public function getProductInfoForFacebookPixel()

in 2.0.x-2.2.x/upload/catalog/controller/module/facebook_business.php [632:685]


    public function getProductInfoForFacebookPixel() {
        $event_name = (isset($this->request->get['event_name']))
          ? $this->request->get['event_name']
          : '';

        /**
         * Creating a default facebook_pixel_params with just the event_name
         * and empty parameters. This is to guard against cases where the
         * product is not found or the product_id is not available.
         */
        $facebook_pixel_event_params = array('event_name' => $event_name);

        if (isset($this->request->get['product_id']) && $this->request->get['product_id']) {
            $this->load->model('catalog/product');
            $this->load->model('module/facebook_business');

            $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);

            if ($product_info) {
                $quantity = isset($this->request->get['quantity']) ? $this->request->get['quantity'] : 1;

                $contents = array(
                    'id'        => $product_info['product_id'],
                    'quantity'  => $quantity
                );

                if ((float)$product_info['special'] && $this->config->get('facebook_business_sync_specials_status')) {
                    $price = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'], '', false);
                } else {
                    $price = $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency'], '', false);
                }

                $event_id = $this->model_module_facebook_business->generateEventId();

                $facebook_pixel_event_params = array(
                    'event_name'    => $event_name,
                    'content_ids'   => array((string)$product_info['product_id']),
                    'content_name'  => $this->model_module_facebook_business->formatString($product_info['name']),
                    'content_type'  => 'product',
                    'contents'      => array($contents),
                    'currency'      => strtoupper($this->session->data['currency']),
                    'value'         => $price,
                    'event_id'      => $event_id
                );

                $this->model_module_facebook_business->trackPixel($facebook_pixel_event_params, $event_name, $event_id);
            }
        }

        $json = array('facebook_pixel_event_params' => $facebook_pixel_event_params);

        $this->response->addHeader('Content-Type: application/json');
        $this->response->setOutput(json_encode($json));
    }