php数据层中的多个产品列表
我想得到一个很好的数据层跟踪我的网站的营销像素在“订单确认页”(谢谢你购买页面)。 该网站使用OXID Shop作为电子商务平台 我想进行以下设置:php数据层中的多个产品列表,php,smarty,google-tag-manager,google-datalayer,oxid,Php,Smarty,Google Tag Manager,Google Datalayer,Oxid,我想得到一个很好的数据层跟踪我的网站的营销像素在“订单确认页”(谢谢你购买页面)。 该网站使用OXID Shop作为电子商务平台 我想进行以下设置: IF currentPage == 'thankyou': products_info = '[{id: 'product_id_1', price: 'price_1', quantity: 'quantity_1'}, {id: 'product_id_2', price: 'price_2', quant
IF currentPage == 'thankyou':
products_info = '[{id: 'product_id_1', price: 'price_1', quantity: 'quantity_1'},
{id: 'product_id_2', price: 'price_2', quantity: 'quantity_2'}]'
如果我的页面变量“CurrentController”=“thankyou”,我将尝试使用以下代码直接从后端获取值,对于只包含一篇文章的值的变量,我可以很容易地做到这一点
示例:
[{if $currentControllerName == "thankyou"}]
var dataLayer = [];
[{assign var="order" value=$oView->getOrder()}]
dataLayer.push(
{email: [{$order->oxorder__oxbillemail->value}]}
);
[{/if}]
问题是当我需要为多篇文章获取值时,就像我在开头提到的products_info变量一样
我正在尝试以下代码,但我不确定如何使迭代器“append”或将每个产品的值发送到单个变量:
[{if $currentControllerName == "thankyou"}]
var dataLayer = [];
[{assign var="order" value=$oView->getOrder()}]
(
[{foreach from=$orderArticles item="currOrderArticle"}]
[{assign var="currArticle" value=$currOrderArticle->getArticle()}]
[{assign var="currBasePrice" value=$currOrderArticle->getBasePrice()}]
product_info: [{id: [{$currOrderArticle->oxorderarticles__oxartnum->value}],
price: [{$currBasePrice->getBruttoPrice()}],
quantity: [{$currOrderArticle->oxorderarticles__oxamount->value}]}]
[{/foreach}]
)
[{/if}]
每次调用时,您正在调用的Javascript函数.push()都会将一个项附加到数据层数组中。(见附件) 那么,为什么不让smarty为篮子中的每个产品提供对该函数的调用呢
[{if $oView->getClassName() == "thankyou"}]
<script>
var dataLayer = [];
[{assign var="basket" value=$oView->getBasket()}]
[{foreach from=$basket->getContents() item=basketitem}]
[{assign var=itemarticle value=$basketitem->getArticle()}]
[{assign var="basketitemprice" value=$basketitem->getPrice()}]
dataLayer.push({ id: [{$itemarticle->oxarticles__oxartnum->value}], price: [{$basketitemprice->getBruttoPrice()}], quantity: [{$basketitem->getAmount()}] });
[{/foreach}]
</script>
[{/if}]
最后,您要做的是创建一个Javascript数组(可以由Google标记管理器读取)。这是Thankyou页面上的最终输出(也是完全有效的Javascript):
<script>
var dataLayer = [];
dataLayer.push({ id: 3788, price: 24.95, quantity: 1 });
dataLayer.push({ id: 1401, price: 129, quantity: 1 });
dataLayer.push({ id: 10101, price: 0, quantity: 1 });
</script>
var数据层=[];
推送({id:3788,价格:24.95,数量:1});
推送({id:1401,价格:129,数量:1});
push({id:10101,价格:0,数量:1});
请注意,您没有使用PHP将数据附加到dataLayer变量。您正在创建Javascript代码(使用Smarty/PHP),然后将创建数据层数组(然后可由Google Tag Manager Javascript使用)我不确定您要归档什么,但OXID使用Smarty作为模板语言,您可以使用Smarty的捕获将输出附加到单个变量。
<script>
var dataLayer = [];
dataLayer.push({ id: 3788, price: 24.95, quantity: 1 });
dataLayer.push({ id: 1401, price: 129, quantity: 1 });
dataLayer.push({ id: 10101, price: 0, quantity: 1 });
</script>