Helper
{shopGiftcertificatesPluginHelper::generateOneCertificate($params, $validation_types, $return_template)}
creates a certificate once, depending on the validations. Returns either an array of data or a template. If the certificate has already been created, then the data of the previously created certificate will be returned. The structure of parameters is described in the article.
When displaying the helper in different places on the site, you should take into account the features of the verification mechanism.
Specifying $validation_type
checks whether the certificate was ever generated via the helper generateOneCertificate
.
User validation (user)
Checks whether the user is authorized and whether a certificate has ever been generated through this helper.
This validation is performed for contact ID, specifying in params. If the contact is not specified, the email field is checked. If the email address is not found, the ID of the current contact that called the helper is used. If the customer is not authorized, it will not pass the verification.
{shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'state_id' => 19 ], ['user'], true)}
Thus, if the helper is used in the storefront, you don't need to specify the contact ID, because it will be taken from the data of the current user.
If the helper is used in notifications or mailings, specify the contact ID or email address in the $params
parameter to make it clear which user to check.
Session validation (session)
Checks whether the user has a special record in the session that the certificate was generated through this helper.
This type of verification should only be used in the frontend, when the certificate is created when the user views the page, because the value in the session will be saved for it.
{shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'state_id' => 19 ], ['session'], true)}
If you perform this validation in notifications, you may experience incorrect operation.
Cookie validation (cookie)
Checks whether the user has a special record in the cookie that the certificate was generated through this helper.
This type of validation should only be used in the frontend, when the certificate is created when the user views the page, because the value in the cookie will be saved for it.
{shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'state_id' => 19 ], ['cookie'], true)}
If you perform this validation in notifications, you may experience incorrect operation.
IP validation (ip)
Checks whether a certificate was generated for the IP through this helper.
This type of validation should only be used in the frontend, when the certificate is created when the user views the page, because the IP value will be saved for it.
{shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'state_id' => 19 ], ['ip'], true)}
If you perform this validation in notifications, you may experience incorrect operation.
Mild checks
These examples check whether ever a certificate was created through the helper.
What should we do if we need to generate a certificate for the same user first in mailing lists, and then later in a notification or on the main page?.
You can specify in the keys of the $validation_type
parameter a unique code that will be used for checking the generator.
Let's look at some examples.
Generator for mailings
{if !empty($id) && $wa->shop} {shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'contact_id' => $id, 'state_id' => 19 ], ['mailer' => 'user'], true)} {/if}
Generator for notifications
{if !empty($order) && $wa->shop} {shopGiftcertificatesPluginHelper::generateOneCertificate([ 'amount' => '50', 'currency' => 'USD', 'contact_id' => $order.contact_id, 'state_id' => 19 ], ['notification' => 'user'], true)} {/if}
In one case, we used the code mailer
to verify the user , in another code notification
.
So we created 2 different generators with user verification.