Source of file ShopifyProductController.php
Size: 1,482 Bytes - Last Modified: 2021-12-24T06:46:30+00:00
/var/www/docs.ssmods.com/process/src/src/Controller/ShopifyProductController.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 | <?php namespace Dynamic\Shopify\Controller; use Dynamic\Shopify\Page\ShopifyProduct; use SilverStripe\View\Requirements; /** * Class ShopifyProductController * @package Dynamic\Shopify\Controller * * @mixin ShopifyProduct */ class ShopifyProductController extends \PageController { /** * @inheritDoc */ public function init() { $price = number_format($this->getPrice()->getValue(), 2); $name = str_replace('\'', '\\\'', $this->Title); $vendor = str_replace('\'', '\\\'', $this->Vendor); $category = str_replace('\'', '\\\'', $this->Parent()->Title); Requirements::customScript(" (function () { window.dataLayer = window.dataLayer || []; dataLayer.push({ ecommerce: null }); /* Clear the previous ecommerce object. */ dataLayer.push({ 'ecommerce': { 'detail': { 'actionField': {'list': 'Product Detail Page View'}, 'products': [{ 'name': '{$name}', 'id': '{$this->getSKU()}', 'price': '{$price}', 'brand': '{$vendor}', 'category': '{$category}' }] } } }); })(); ", 'shopify-product-detail-enhanced-ecommerce'); return parent::init(); } } |