Hello guys
I need to output a comma separated array of the IDs of the products in the placed order, on the Order Confirmation Page, for Facebook Remarketing.
My current code in OrderConfirmationController.php is:
public function initContent() { parent::initContent(); $order = new Order((int)($this->id_order)); $products = $order->getProducts(); $product_ids = array(); foreach ($products as $product) $product_ids[] = (int)$product['id_product']; $this->context->smarty->assign(array( '$products' => $products, 'id_order' => $this->id_order, 'is_guest' => $this->context->customer->is_guest, 'HOOK_ORDER_CONFIRMATION' => $this->displayOrderConfirmation(), 'HOOK_PAYMENT_RETURN' => $this->displayPaymentReturn() )); if ($this->context->customer->is_guest) { $this->context->smarty->assign(array( 'id_order' => $this->id_order, '$products' => $products, 'reference_order' => $this->reference, 'id_order_formatted' => sprintf('#%06d', $this->id_order), 'email' => $this->context->customer->email )); /* If guest we clear the cookie for security reason */ $this->context->customer->mylogout(); }
and on the order-confirmation.tpl I got this:
{literal} <script> fbq('track', 'Purchase', // {/literal} // {foreach from=$products item=product name=item} // {literal} { content_ids: ['{/literal}{$product_ids}{literal}'], content_type: 'product', value: '{/literal}{$_value}{literal}', currency: 'RON' }); // {/literal} // {/foreach} // {literal} </script> <!-- End Facebook Pixel Code --> {/literal}
As you can see, I commented a {foreach} because I tried A LOT of suggestions here on the forum without good results and on the current setup I have the array generated in the PHP file.
The current output is none. Previous attempts have output either all the IDs united into one, without separation (which actually lead me to this endeavor) or just one product ID.
I am getting errors across all sites using this setup and it impacts my clients.
Please help? Thank you!