To understand the parameters and helper methods, read the articles certificate generating and features of the helper generateOneCertificate.
Automatic certificate creation can be organized in various places on the site. This will help you encourage people to make purchases in your store.
Let's look at examples of certificate generation:
- Certificates in Notifications.
- Certificates in Mailer.
- Certificates on the page of the successful purchase.
- Certificates on home page.
- Certificates on product page.
Certificates in Notifications
We are going to give a certificate every time when order get state Completed
.
Open page Shop - Settings - Notifications - Order was marked as completed (Customer)
.
Find block with code:
Thank you for shopping at...
Below insert generatore code.
{$certificate = shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'contact_id' => $order.contact_id, 'state_id' => 19 ], ['notification' => 'user'])} {if $certificate} <p>We present you a gift certificate for {shop_currency($certificate.amount, $certificate.currency, $order.currency)}!</p> <p>Enter the code at the checkout to redeem <b>{$certificate.code}</b></p> {/if}
The result should be similar to
If you want certificates to be created for an order amount of 500 or more (in the primary currency), you should add the appropriate condition:
{if shop_currency($order.total, $order.currency, $wa->shop->primaryCurrency(), false) > 500} {$certificate = shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'contact_id' => $order.contact_id, 'state_id' => 19 ], ['notification' => 'user'])} {if $certificate} <p>We present you a gift certificate for {shop_currency($certificate.amount, $certificate.currency, $order.currency)}!</p> <p>Enter the code at the checkout to redeem <b>{$certificate.code}</b></p> {/if} {/if}
When using generators in notifications, we recommend using user
validation if you are working through the helper generateOneCertificate
.
Certificates in Mailer
You can use certificate in application Mailer.
1) Create block with any ID. For example, open page Site - Blocks
and create block giftcertificates.mailer
.
Insert one of the following constuctions to generate the certificate.
Private user certificate:
{if !empty($id) && $wa->shop} {shopGiftcertificatesPluginHelper::generateCertificateTemplate([ 'amount' => '50', 'currency' => 'USD', 'state_id' => 19, 'send' => 'user', 'contact_id' => $id ])} {/if}
Certificate attached by email:
{if !empty($email) && $wa->shop} {shopGiftcertificatesPluginHelper::generateCertificateTemplate([ 'amount' => '50', 'currency' => 'USD', 'state_id' => 19, 'send' => 'email', 'email' => $email ])} {/if}
Certificate with user validation:
{if !empty($id) && $wa->shop} {shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'contact_id' => $id, 'state_id' => 19 ], ['mailer' => 'user'], true)} {/if}
2) Copy only block ID. Following the example, it should be giftcertificates.mailer
.
3) Paste into the mail content:
{$wa->block("giftcertificates.mailer", ["id" => ifempty($id, 0), "email" => ifempty($email, "")])}
You need to replace only giftcertificates.mailer
. Don't change other code.
When using generators in Mailer, we recommend using user
validation if you are working through the helper generateOneCertificate
.
Certificates on the page of the successful purchase
We are going to give the certificate with free product to all customers, who placed an order for the amount of $700 (primary currency). Also add limitations to certificate: minimal order sum and lifetime.
Open template checkout.success.html
on the page Shop - Storefront - Templates
.
Paste the code in any place that is convenient for you:
{if !empty($order.id) && shop_currency($order.total, $order.currency, $wa->shop->primaryCurrency(), false) > 700} {shopGiftcertificatesPluginHelper::generateCertificateTemplate([ 'state_id' => 19, 'use_limitations' => 1, 'limitations' => [ 'lifetime' => 10, 'min' => [ 'value' => 350, 'currency' => 'USD' ] ], 'free_products' => [ 'skus' => [30] ] ])} {/if}
Certificates on home page
We are going to give certificate for all customers from the group VIP
1) Fing ID of VIP group. To do this, open application Contacts
and group VIP. The contact category ID will be displayed in the browser's address bar.
At this example this is 4.
2) Open the template home.html
on the page Shop - Storefront - Templates
.
3) Paste the code in any place that is convenient for you:
{if shopGiftcertificatesPluginHelper::contactInCategory($wa->user()->getId(), 4)} {shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'contact_id' => $wa->user()->getId(), 'state_id' => 19 ], ['home' => 'user'], true)} {/if}
Read more about the method contactInCategory
in the article available helpers.
Certificates on product page
We are going to create certificate on the product page. Certificate will be generated only once per user.
Ope the template product.html
(or product.cart.html
) on the page Shop - Storefront - Templates
.
Let's pretend that ID of desired product 25.
Paste the code in any place that is convenient for you:
{if $product.id == '25'} {$certificate = shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'state_id' => 19 ], ['product' => 'user'])} {if $certificate} <p>We present you a gift certificate for {shop_currency($certificate.amount, $certificate.currency)}!</p> <p>Enter the code at the checkout to redeem <b>{$certificate.code}</b></p> {/if} {/if}
If you can't find the appropriate output place, consult the developer of the design theme.