How to add a list of Shop-Script products to an email message

Problem

Add an arbitrary list of Shop-Script products with links, images, names, and prices to an email message.

Solution

Use this code as a template. Fill in desired values for variables listed at the beginning.

{if $wa->shop}
    {$products = $wa->shop->productSet("bestsellers")} {* method to obtain a product list *}
    {$domain = 'mydomain.com'} {* your domain name *}
    {$route = '*'} {* your storefront address from Site app's "Structure" section *}
    {$image_size = '200'} {* product image size *}
    {$currency = 'USD'} {* currency to display product prices *}

    {foreach $products as $product}
        {$route_params = [
            'product_url' => $product['url'],
            'domain'      => $domain,
            'route'       => $route
        ]}
        {if (isset($product['category_url']))}
            {$route_params['category_url'] = $product['category_url']}
        {else}
            {$route_params['category_url'] = ''}
        {/if}
        
        <p>
            {strip}
                <a href="{$wa->getUrl('shop/frontend/product', $route_params, true)}">
                    {if !empty($product.image_id)}
                        <img src="{$wa->shop->imgUrl([&#10;                            'id'         => $product['image_id'],&#10;                            'product_id' => $product['id'],&#10;                            'filename'   => $product['image_filename'],&#10;                            'ext'        => $product['ext']&#10;                        ], $image_size, true)}"><br>
                    {/if}
                    {$product.name}
                </a><br>
                {shop_currency_html($product.price, $currency)}
            {/strip}
        </p>
    {/foreach}
{/if}

0 comments

    Add comment

    To add a comment please sign up or login