The plugin has additional helpers that can be useful to you when working with templates.
Let's look at all available helper plugins and examples of their use.
Checking whether a contact exists in the user's categories
Contact categories can be created in the application Contacts
/** * @param int $contact_id - contact ID * @param int|array $category_id - contact categories ID * @return bool **/ {shopGiftcertificatesPluginHelper::contactInCategory($contact_id, $category_id)}
Let's assume that you want to check whether a customer belongs to the following user groups: Wholesalers and VIPs.
To do this, you need to find out the ID of the categories (let's say it's 4 and 9) and use the helper:
{if shopGiftcertificatesPluginHelper::contactInCategory($wa->user()->getId(), [4, 9])} {shopGiftcertificatesPluginHelper::generateCertificateTemplate([ 'amount' => '50', 'currency' => 'USD', 'state_id' => 19, 'send' => 'user', 'contact_id' => $wa->user()->getId() ])} {/if}
Output the template of the certificate
The helper has a built-in certificate availability check
/** * @param int|string $certificate_id - certificate ID or code * @param bool $skip_validations - should we skip validations ro not * @return string **/ {shopGiftcertificatesPluginHelper::showCertificateTemplate($certificate_id, $skip_validations = false)}
Let's say you need to display a certificate knowing its ID (let's say it's 5).
{shopGiftcertificatesPluginHelper::showCertificateTemplate(5)}
If the certificate has limitations or its status does not allow using the certificate, nothing will be displayed.
Cancel the availability check if you want to always display the certificate:
{shopGiftcertificatesPluginHelper::showCertificateTemplate(5, true)}
Output the template of the certificate with dummy data
Use the helper if you want to see what your certificate template will look like
/** * @param string $template_id - template ID * @return string **/ {shopGiftcertificatesPluginHelper::showTemplate($template_id)}
Template IDs and specified construction available on the page Shop - Plugins - Gift certificates - Templates
.
Output the template with ID template2
.
{shopGiftcertificatesPluginHelper::showTemplate('template2')}
Creating a certificate and getting it's data
Read more about the helper in the article about generating.
/** * @param array $params - Certificate params * @return array **/ {shopGiftcertificatesPluginHelper::generateCertificate($params = [])}
Creating a certificate and output it's template
Read more about the helper in the article about generating.
/** * @param array $params - Certificate params * @return string **/ {shopGiftcertificatesPluginHelper::generateCertificateTemplate($params = [])}
Creating a certificate based on validations
Read more about the helper in the article about generating and about the helper generateOneCertificate.
/** * @param array $params - Certificate params * @param string[] $validation_types - Types of checks to determine whether to create a certificate or not * @param bool $return_template - Return array data or HTML-template * @return string|array **/ {shopGiftcertificatesPluginHelper::generateOneCertificate($params = [], $validation_types = ['user'], $return_template = false)}
Output of the certificate order form
Read more about the helper in the article selling of the certificates.
Helper allows you to sell the certificates on the storefront.
/** * @return string **/ {shopGiftcertificatesPluginHelper::form()}
Output of the form for entering the certificate in the shopping cart
Read more about the helper in the article.
The helper allows you to change the location of the form output in the shopping cart.
/** * @return string **/ {shopGiftcertificatesPluginHelper::getCartForm()}
Additional information about the certificate in the shopping cart
Read more about the helper in the article.
/** * @param array $item - Item data from the cart page * @return string **/ {shopGiftcertificatesPluginHelper::getCartItemCertificateBlock($item)}