/** * Function DO HOOK */ public function doHook($params) { if ($this->_allowToWork == false) { return; } $customer = new Customer($params['cart']->id_customer); $currency = new Currency($params['cart']->id_currency); $address = $customer->getAddresses($params['cart']->id_lang); $address = $address[0]; // for 1.3 compatibility $type_both = 3; $type_only_shipping = 5; $tva = $params['cart']->getOrderTotal(true, $type_both) - $params['cart']->getOrderTotal(false, $type_both); $tax = $tva * 100 / $params['cart']->getOrderTotal(true, $type_both); $params_to_twenga = array(); $params_to_twenga['total_ht'] = $params['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); $params_to_twenga['basket_id'] = $params['cart']->id; $params_to_twenga['currency'] = $currency->iso_code; $params_to_twenga['total_ttc'] = $params['cart']->getOrderTotal(true, Twenga::BOTH); $params_to_twenga['shipping'] = $params['cart']->getOrderTotal(true, Twenga::ONLY_SHIPPING); $params_to_twenga['tax'] = Tools::ps_round($tax, 2); $params_to_twenga['tva'] = $tva; $params_to_twenga['cli_firstname'] = $customer->firstname; $params_to_twenga['cli_lastname'] = $customer->lastname; $params_to_twenga['cli_city'] = $address['city']; $params_to_twenga['cli_state'] = $address['state']; $params_to_twenga['cli_country'] = $address['country']; $params_to_twenga['items'] = array(); foreach ($params['cart']->getProducts() as $product) { $arr_item = array(); if ($product['total'] != '') { $arr_item['total_ht'] = (double) $product['total']; } if ($product['cart_quantity'] != '') { $arr_item['quantity'] = (int) $product['cart_quantity']; } if ($product['reference'] != '') { $arr_item['sku'] = (string) $product['reference']; } if ($product['name'] != '') { $arr_item['name'] = (string) $product['name']; } if ($product['category']) { $arr_item['category_name'] = (string) $product['category']; } $params_to_twenga['items'][] = $arr_item; } $params_to_twenga = array_filter($params_to_twenga); try { // twenga don't saved double orders with the same id, // so don't need to use TwengaObj::orderExist() method. $tracking_code = self::$obj_twenga->getTrackingScript($params_to_twenga); return $tracking_code; } catch (TwengaFieldsException $e) { return $this->l('Error occurred when params passed in Twenga API') . ' : <br />' . $e->getMessage(); } catch (Exception $e) { return $e->getMessage(); } }
public function hookPayment($params) { if ($this->_allowToWork == false) { return; } // One page Checkout cause problem with event and document.write use by twenga script // (page completely deleted if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { return; } $customer = new Customer($params['cart']->id_customer); $currency = new Currency($params['cart']->id_currency); $address = $customer->getAddresses($params['cart']->id_lang); $address = $address[0]; // for 1.3 compatibility $type_both = 3; $type_only_shipping = 5; /* const ONLY_PRODUCTS = 1; const ONLY_DISCOUNTS = 2; const BOTH = 3; const BOTH_WITHOUT_SHIPPING = 4; const ONLY_SHIPPING = 5; const ONLY_WRAPPING = 6; const ONLY_PRODUCTS_WITHOUT_SHIPPING = 7; */ $tva = $params['cart']->getOrderTotal(true, $type_both) - $params['cart']->getOrderTotal(false, $type_both); $tax = $tva * 100 / $params['cart']->getOrderTotal(true, $type_both); $params_to_twenga = array(); // @todo delete or not ?? // $params_to_twenga['user_id'] = $customer->id; // $params_to_twenga['cli_email'] = $customer->email; $params_to_twenga['total_ht'] = $params['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); $params_to_twenga['basket_id'] = $params['cart']->id; $params_to_twenga['currency'] = $currency->iso_code; $params_to_twenga['total_ttc'] = $params['cart']->getOrderTotal(true, Twenga::BOTH); $params_to_twenga['shipping'] = $params['cart']->getOrderTotal(true, Twenga::ONLY_SHIPPING); $params_to_twenga['tax'] = Tools::ps_round($tax, 2); $params_to_twenga['tva'] = $tva; $params_to_twenga['cli_firstname'] = $customer->firstname; $params_to_twenga['cli_lastname'] = $customer->lastname; $params_to_twenga['cli_city'] = $address['city']; $params_to_twenga['cli_state'] = $address['state']; $params_to_twenga['cli_country'] = $address['country']; $params_to_twenga['items'] = array(); foreach ($params['cart']->getProducts() as $product) { $arr_item = array(); if ($product['total'] != '') { $arr_item['total_ht'] = (double) $product['total']; } if ($product['cart_quantity'] != '') { $arr_item['quantity'] = (int) $product['cart_quantity']; } if ($product['reference'] != '') { $arr_item['sku'] = (string) $product['reference']; } if ($product['name'] != '') { $arr_item['name'] = (string) $product['name']; } if ($product['category']) { $arr_item['category_name'] = (string) $product['category']; } $params_to_twenga['items'][] = $arr_item; } $params_to_twenga = array_filter($params_to_twenga); try { // twenga don't saved double orders with the same id, // so don't need to use TwengaObj::orderExist() method. $tracking_code = self::$obj_twenga->getTrackingScript($params_to_twenga); return $tracking_code; } catch (TwengaFieldsException $e) { return $this->l('Error occurred when params passed in Twenga API') . ' : <br />' . $e->getMessage(); } catch (Exception $e) { return $e->getMessage(); } }
/** * Function DO HOOK */ public function doHook($aParams, $sEvent = '') { if ($this->_allowToWork == false) { return; } $oCustomer = new Customer($aParams['cart']->id_customer); $oCurrency = new Currency($aParams['cart']->id_currency); $aAddress = $oCustomer->getAddresses($aParams['cart']->id_lang); $aAddress = $aAddress[0]; $sUserCountry = ''; if (isset($aAddress['id_country']) && !empty($aAddress['id_country'])) { $sUserCountry = Country::getIsoById($aAddress['id_country']); } // for 1.3 compatibility $tva = false; if (isset($aParams['objOrder']) && !empty($aParams['objOrder'])) { $tax = $aParams['objOrder']->total_paid_tax_incl - $aParams['objOrder']->total_shipping_tax_incl - ($aParams['objOrder']->total_paid_tax_excl - $aParams['objOrder']->total_shipping_tax_excl); $tva = $aParams['objOrder']->carrier_tax_rate; } else { $tax = $aParams['cart']->getOrderTotal(true, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING) - $aParams['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); if ($aParams['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING) > 0) { $tva = $tax * 100 / $aParams['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); } } $aParamsToTwenga = array(); $aParamsToTwenga['event'] = $sEvent; $aParamsToTwenga['user_id'] = $aParams['cart']->id_customer; $aParamsToTwenga['user_global_id'] = md5($oCustomer->email); $aParamsToTwenga['user_email'] = $oCustomer->email; $aParamsToTwenga['user_firstname'] = $oCustomer->firstname; $aParamsToTwenga['user_city'] = $aParams['cart']->id_customer ? $aAddress['city'] : ''; $aParamsToTwenga['user_state'] = $aParams['cart']->id_customer ? $aAddress['state'] : ''; $aParamsToTwenga['user_country'] = $aParams['cart']->id_customer ? $sUserCountry : ''; $aParamsToTwenga['user_segment'] = ''; $aParamsToTwenga['user_is_customer'] = 1; $aParamsToTwenga['ecommerce_platform'] = 'Prestashop'; $aParamsToTwenga['tag_platform'] = ''; $aParamsToTwenga['basket_id'] = $aParams['cart']->id; $aParamsToTwenga['currency'] = $oCurrency->iso_code; $aParamsToTwenga['total_ht'] = isset($aParams['objOrder']) ? $aParams['objOrder']->total_paid_tax_excl - $aParams['objOrder']->total_shipping_tax_excl : $aParams['cart']->getOrderTotal(false, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); $aParamsToTwenga['tva'] = $tva !== false ? Tools::ps_round($tva, 2) : ''; $aParamsToTwenga['total_ttc'] = isset($aParams['objOrder']) ? $aParams['objOrder']->total_paid_tax_incl - $aParams['objOrder']->total_shipping_tax_incl : $aParams['cart']->getOrderTotal(true, Twenga::ONLY_PRODUCTS_WITHOUT_SHIPPING); $aParamsToTwenga['shipping'] = isset($aParams['objOrder']) ? $aParams['objOrder']->total_shipping_tax_incl : $aParams['cart']->getOrderTotal(true, Twenga::ONLY_SHIPPING); $aParamsToTwenga['tax'] = $tax; if (isset($aParams['objOrder']) && !empty($aParams['objOrder'])) { $aParamsToTwenga['order_id'] = $aParams['objOrder']->id; } $aParamsToTwenga['items'] = array(); if ($sEvent == 'product' && isset($_POST['id_product']) || isset($_GET['id_product'])) { $iIdProduct = isset($_POST['id_product']) ? $_POST['id_product'] : $_GET['id_product']; $oProduct = new Product($iIdProduct); if ($oProduct) { $oCategory = new Category($oProduct->id_category_default); if ($oCategory) { $arr_item = array(); $arr_item['price'] = $oProduct->price; $arr_item['quantity'] = ''; $arr_item['ref_id'] = $oProduct->reference; $arr_item['item_id'] = $iIdProduct; $arr_item['name'] = $oProduct->name[1]; $arr_item['category_name'] = $oCategory->name; $aParamsToTwenga['items'][] = $arr_item; } } } elseif (isset($aParams['objOrder']) && !empty($aParams['objOrder'])) { foreach ($aParams['objOrder']->getProducts() as $product) { $oCategory = new Category($product['id_category_default']); $arr_item = array(); if ($product['unit_price_tax_excl'] != '') { $arr_item['price'] = (double) $product['unit_price_tax_excl']; } if ($product['product_quantity'] != '') { $arr_item['quantity'] = (int) $product['product_quantity']; } if ($product['reference'] != '') { $arr_item['ref_id'] = (string) $product['reference']; } if ($product['id_product'] != '') { $arr_item['item_id'] = (string) $product['id_product']; } if ($product['product_name'] != '') { $arr_item['name'] = (string) $product['product_name']; } if (isset($oCategory) && !empty($oCategory)) { $arr_item['category_name'] = $oCategory->name; } $aParamsToTwenga['items'][] = $arr_item; } } else { foreach ($aParams['cart']->getProducts() as $product) { $arr_item = array(); if ($product['price'] != '') { $arr_item['price'] = (double) $product['price']; } if ($product['cart_quantity'] != '') { $arr_item['quantity'] = (int) $product['cart_quantity']; } if ($product['reference'] != '') { $arr_item['ref_id'] = (string) $product['reference']; } if ($product['id_product'] != '') { $arr_item['item_id'] = (string) $product['id_product']; } if ($product['name'] != '') { $arr_item['name'] = (string) $product['name']; } if ($product['category']) { $arr_item['category_name'] = (string) $product['category']; } $aParamsToTwenga['items'][] = $arr_item; } } $aParamsToTwenga = array_filter($aParamsToTwenga); try { $tracking_code = self::$obj_twenga->getTrackingScript($aParamsToTwenga); return $tracking_code; } catch (TwengaFieldsException $e) { return $this->l('Error occurred when params passed in Twenga API') . ' : <br />' . $e->getMessage(); } catch (Exception $e) { return $e->getMessage(); } }