/** * Formatage des informations produit pour NetEven. * @param $t_product * @param bool $display * @return array */ private function getPropertiesForNetEven($products, $display = false) { if (!sizeof($products)) { return false; } global $cookie, $link; if (!$link) { $link = new Link(); } $products_temp = array(); $compteur_product_no_ean13 = 0; $compteur_product_no_ref = 0; foreach ($products as $product) { $product_reference = 'P' . $product['id_product']; if (!empty($product['id_product_attribute'])) { $product_reference = 'D' . $product['id_product_attribute']; } if (self::$type_sku == 'reference') { $product_reference = $product['product_reference']; if (!empty($product['id_product_attribute'])) { $product_reference = $product['product_attribute_reference']; } } $ean_ps = !empty($product['ean13_declinaison']) ? $product['ean13_declinaison'] : $product['ean13']; $codeEan = ""; if (!empty($ean_ps)) { $codeEan = sprintf('%013s', $ean_ps); } $id_product_attribute = NULL; if (!empty($product['id_product_attribute'])) { $id_product_attribute = (int) $product['id_product_attribute']; } $product_price = Product::getPriceStatic((int) $product['id_product'], true, (int) $id_product_attribute, 2, NULL, false, true); $product_price_without_reduction = Product::getPriceStatic((int) $product['id_product'], true, (int) $id_product_attribute, 2, NULL, false, false); $categories = $this->getProductCategories($product); $categories = array_reverse($categories); $classification = str_replace('//', '', implode('/', $categories)); $quantity = Product::getQuantity((int) $product['id_product'], !empty($product['id_product_attribute']) ? (int) $product['id_product_attribute'] : NULL); $indice = count($products_temp); $weight = $product['weight']; if (!empty($id_product_attribute)) { $weight += $product['weight_product_attribute']; } $products_temp[$indice] = array('Title' => $product['name'], 'SKU' => $product_reference, 'Description' => strip_tags($product['description']), 'EAN' => $codeEan, 'Quantity' => $quantity, 'PriceFixed' => $product_price_without_reduction, 'PriceRetail' => $product_price, 'Etat' => 11, 'SKUFamily' => self::$type_sku == 'reference' ? $product['declinaison_default_ref'] : $product['declinaison_default'], 'Classification' => str_replace('Accueil/', '', $classification), 'shipping_delay' => $this->getValue('shipping_delay'), 'Comment' => $this->getValue('comment'), 'Height' => $product['height'], 'Width' => $product['width'], 'Depth' => $product['depth'], 'Weight' => $weight, 'Brand' => !empty($product['name_manufacturer']) ? $product['name_manufacturer'] : $this->getValue('default_brand')); $id_lang = isset($cookie->id_lang) ? (int) $cookie->id_lang : (int) Configuration::get('PS_LANG_DEFAULT'); $sql = 'SELECT t.name FROM ' . _DB_PREFIX_ . 'product_tag pt INNER JOIN ' . _DB_PREFIX_ . 'tag t ON (pt.id_tag = t.id_tag AND t.id_lang = ' . intval($id_lang) . ') WHERE pt.id_product = ' . intval($product['id_product']); $t_tags_bdd = Db::getInstance()->ExecuteS($sql); if ($t_tags_bdd && count($t_tags_bdd) > 0) { $t_tags_final = array(); foreach ($t_tags_bdd as $t_tag_bdd) { $t_tags_final[] = $t_tag_bdd['name']; } $products_temp[$indice]["Keywords"] = implode(',', $t_tags_final); } //shipping part $shipping_price_local = $this->getValue('shipping_price_local'); if (self::$shipping_by_product && !empty(self::$shipping_by_product_fieldname)) { $shipping_price_local = $product[self::$shipping_by_product_fieldname]; } $carrier_france = $this->getConfig('SHIPPING_CARRIER_FRANCE'); $carrier_zone_france = $this->getConfig('SHIPPING_ZONE_FRANCE'); if (!empty($carrier_france) && !empty($carrier_zone_france)) { $products_temp[$indice]['PriceShippingLocal1'] = $this->getShippingPrice($product['id_product'], $id_product_attribute, $carrier_france, $carrier_zone_france); } elseif (!empty($shipping_price_local)) { $products_temp[$indice]['PriceShippingLocal1'] = $shipping_price_local; } $shipping_price_inter = $this->getValue('shipping_price_international'); $carrier_inter = $this->getConfig('SHIPPING_CARRIER_INTERNATIONAL'); $carrier_zone_inter = $this->getConfig('SHIPPING_ZONE_INTERNATIONAL'); if (!empty($carrier_france) && !empty($carrier_zone_france)) { $products_temp[$indice]['PriceShippingInt1'] = $this->getShippingPrice($product['id_product'], $id_product_attribute, $carrier_inter, $carrier_zone_inter); } elseif (!empty($shipping_price_inter)) { $products_temp[$indice]['PriceShippingInt1'] = $shipping_price_inter; } if (!empty($carrier_france) && !empty($carrier_zone_france)) { $products_temp[$indice]['PriceShippingInt1'] = $this->getShippingPrice($product['id_product'], $id_product_attribute, $carrier_inter, $carrier_zone_inter); } $images = $this->getProductImages($product); foreach ($images as $key => $image) { if (is_object($link)) { $img_url = $link->getImageLink($product['link_rewrite'], (int) $product['id_product'] . '-' . (int) $image['id_image'], Gateway::getConfig('IMAGE_TYPE_NAME')); $products_temp[$indice]['Image' . ($key + 1)] = 'http://' . str_replace('http://', '', $img_url); } } // Attributes and fetures of product $category_default = new Category((int) $product['id_category_default'], (int) $cookie->id_lang); $products_temp[$indice]['ArrayOfSpecificFields'] = array(); $products_temp[$indice]['ArrayOfSpecificFields'][] = array('Name' => 'categorie', 'Value' => $category_default->name); $sql = ' SELECT GROUP_CONCAT(DISTINCT CONCAT(fl.`name`," {##} ",fvl.`value`) SEPARATOR "' . pSQL($this->getValue('separator')) . ' ") as feature_name FROM `' . _DB_PREFIX_ . 'feature_product` fp LEFT JOIN `' . _DB_PREFIX_ . 'feature_value_lang` fvl ON (fp.`id_feature_value` = fvl.`id_feature_value` AND fvl.id_lang=' . (int) $cookie->id_lang . ') LEFT JOIN `' . _DB_PREFIX_ . 'feature_value` fv ON (fv.`id_feature_value` = fvl.`id_feature_value`) LEFT JOIN `' . _DB_PREFIX_ . 'feature_lang` fl ON (fl.`id_feature` = fv.`id_feature` AND fl.`id_lang`=' . (int) $cookie->id_lang . ') WHERE fp.`id_product` = ' . (int) $product['id_product'] . ' '; $product['feature_name'] = Db::getInstance()->getValue($sql); if (empty($product['attribute_name']) && empty($product['feature_name'])) { continue; } $features_attributes = array(); if (!empty($product['attribute_name'])) { $features_attributes = explode($this->getValue('separator'), $product['attribute_name']); } if (!empty($product['feature_name'])) { $features_attributes = array_merge($features_attributes, explode($this->getValue('separator'), $product['feature_name'])); } $feature_links = $this->getValue('feature_links'); foreach ($features_attributes as $value) { $infos = explode(' {##} ', $value); if (count($infos) == 2 && !empty($infos[0]) && !empty($infos[1]) && !empty($feature_links[trim($infos[0])])) { $specific_name = $feature_links[trim($infos[0])]; $products_temp[$indice]['ArrayOfSpecificFields'][] = array('Name' => $specific_name, 'Value' => $infos[1]); } } if (count(self::$customizable_field) > 0) { foreach (self::$customizable_field as $key => $value) { $products_temp[$indice]['ArrayOfSpecificFields'][] = array('Name' => $key, 'Value' => $value); } } } return $products_temp; }
public function displayForm($order_states, $features, $attribute_groups, $neteven_feature_categories) { $customizable_fields = array(); if (Gateway::getConfig('CUSTOMIZABLE_FIELDS')) { foreach (explode('¤', Gateway::getConfig('CUSTOMIZABLE_FIELDS')) as $customizable_field) { $customizable_fields[] = explode('|', $customizable_field); } } $carriers = Carrier::getCarriers((int) $this->context->cookie->id_lang); $this->context->smarty->assign(array('SHIPPING_CARRIER_FRANCE' => Tools::safeOutput(Tools::getValue('SHIPPING_CARRIER_FRANCE', Gateway::getConfig('SHIPPING_CARRIER_FRANCE'))), 'SHIPPING_ZONE_FRANCE' => Tools::safeOutput(Tools::getValue('SHIPPING_ZONE_FRANCE', Gateway::getConfig('SHIPPING_ZONE_FRANCE'))), 'SHIPPING_CARRIER_INTERNATIONAL' => Tools::safeOutput(Tools::getValue('SHIPPING_CARRIER_INTERNATIONAL', Gateway::getConfig('SHIPPING_CARRIER_INTERNATIONAL'))), 'SHIPPING_ZONE_INTERNATIONAL' => Tools::safeOutput(Tools::getValue('SHIPPING_ZONE_INTERNATIONAL', Gateway::getConfig('SHIPPING_ZONE_INTERNATIONAL'))), 'carriers' => $carriers, 'order_states' => $order_states, 'features' => $features, 'module_path' => $this->_path, 'module_display_name' => $this->displayName, 'attribute_groups' => $attribute_groups, 'neteven_feature_categories' => $neteven_feature_categories, 'default_currency' => new Currency((int) Configuration::get('PS_CURRENCY_DEFAULT')), 'format_images' => ImageType::getImagesTypes('products'), 'cron_feature_url' => Tools::getProtocol(Tools::usingSecureMode()) . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . $this->feature_url, 'cron_order_url' => Tools::getProtocol(Tools::usingSecureMode()) . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . $this->order_url, 'cron_product_url' => Tools::getProtocol(Tools::usingSecureMode()) . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . $this->product_url, 'customizable_fields' => $customizable_fields, 'neteven_token' => Tools::encrypt(Configuration::get('PS_SHOP_NAME')), 'NETEVEN_LOGIN' => Tools::safeOutput(Tools::getValue('NETEVEN_LOGIN', Gateway::getConfig('NETEVEN_LOGIN'))), 'NETEVEN_PASSWORD' => Tools::safeOutput(Tools::getValue('NETEVEN_PASSWORD', Gateway::getConfig('NETEVEN_PASSWORD'))), 'SYNCHRONISATION_ORDER' => (int) Gateway::getConfig('SYNCHRONISATION_ORDER'), 'SYNCHRONISATION_PRODUCT' => (int) Gateway::getConfig('SYNCHRONISATION_PRODUCT'), 'DEFAULT_BRAND' => Tools::safeOutput(Tools::getValue('DEFAULT_BRAND', Gateway::getConfig('DEFAULT_BRAND'))), 'SHIPPING_DELAY' => Tools::safeOutput(Tools::getValue('SHIPPING_DELAY', Gateway::getConfig('SHIPPING_DELAY'))), 'IMAGE_TYPE_NAME' => Gateway::getConfig('IMAGE_TYPE_NAME'), 'COMMENT' => Tools::safeOutput(Tools::getValue('COMMENT', Gateway::getConfig('COMMENT'))), 'SHIPPING_PRICE_LOCAL' => Tools::safeOutput(Tools::getValue('SHIPPING_PRICE_LOCAL', Gateway::getConfig('SHIPPING_PRICE_LOCAL'))), 'SHIPPING_PRICE_INTERNATIONAL' => Tools::safeOutput(Tools::getValue('SHIPPING_PRICE_INTERNATIONAL', Gateway::getConfig('SHIPPING_PRICE_INTERNATIONAL'))), 'SHIPPING_BY_PRODUCT' => (int) Gateway::getConfig('SHIPPING_BY_PRODUCT'), 'SHIPPING_BY_PRODUCT_FIELDNAME' => Tools::safeOutput(Tools::getValue('SHIPPING_BY_PRODUCT_FIELDNAME', Gateway::getConfig('SHIPPING_BY_PRODUCT_FIELDNAME'))), 'ID_ORDER_STATE_NETEVEN' => (int) Gateway::getConfig('ID_ORDER_STATE_NETEVEN'), 'NETEVEN_URL' => Tools::safeOutput(Tools::getValue('NETEVEN_URL', Gateway::getConfig('NETEVEN_URL'))), 'NETEVEN_NS' => Tools::safeOutput(Tools::getValue('NETEVEN_NS', Gateway::getConfig('NETEVEN_NS'))), 'MAIL_LIST_ALERT' => Tools::safeOutput(Tools::getValue('MAIL_LIST_ALERT', Gateway::getConfig('MAIL_LIST_ALERT'))), 'DEBUG' => (int) Gateway::getConfig('DEBUG'), 'SEND_REQUEST_BY_EMAIL' => (int) Gateway::getConfig('SEND_REQUEST_BY_EMAIL'), 'TYPE_SKU' => (int) (Gateway::getConfig('TYPE_SKU') !== false) ? Gateway::getConfig('TYPE_SKU') : 'reference')); return $this->display(__FILE__, 'views/templates/admin/nqgatewayneteven.tpl'); }
* * @author PrestaShop SA <*****@*****.**> * @copyright 2007-2014 PrestaShop SA * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * International Registered Trademark & Property of PrestaShop SA */ include dirname(__FILE__) . '/../../../config/config.inc.php'; include dirname(__FILE__) . '/../../../init.php'; include dirname(__FILE__) . '/../classes/Gateway.php'; if (Tools::getValue('token') != Tools::encrypt(Configuration::get('PS_SHOP_NAME'))) { die(Tools::displayError()); } $action = Tools::getValue('action'); $field = Tools::getValue('field'); $id = Tools::getValue('id'); $order_states = explode(':', Gateway::getConfig($field)); if (empty($order_states[0])) { $order_states = array(); } if ($action != 'display') { $position = 0; if ($action == 'add') { array_push($order_states, $id); } elseif ($action == 'up') { foreach ($order_states as $key => $id_order_state) { if ($id_order_state == $id) { $position = (int) $key; break; } } if ($position != 0) {
/** * Creating of the PrestaShop order * @param $neteven_order * @param $neteven_orders * @return int */ private function createOrder($neteven_order, $neteven_orders) { if (constant('_PS_VERSION_') >= 1.5) { include_once dirname(__FILE__) . '/OrderInvoiceOverride.php'; } /* Treatment of customer */ $id_customer = $this->addCustomerInBDD($neteven_order); if ($this->time_analyse) { $this->current_time_2 = time(); Toolbox::displayDebugMessage(self::getL('Customer') . ' : ' . ((int) $this->current_time_2 - (int) $this->current_time_0) . 's'); } /* Treatment of addresses of the customer */ $id_address_billing = $this->addAddresseInBDD($neteven_order->OrderID, $neteven_order->BillingAddress, 'facturation', $id_customer); $id_address_shipping = $this->addAddresseInBDD($neteven_order->OrderID, $neteven_order->ShippingAddress, 'livraison', $id_customer); if ($this->time_analyse) { $this->current_time_0 = time(); Toolbox::displayDebugMessage(self::getL('Address') . ' : ' . ((int) $this->current_time_0 - (int) $this->current_time_2) . 's'); } /* Get secure key of customer */ $secure_key_default = md5(uniqid(rand(), true)); if ($secure_key = Db::getInstance()->getValue('SELECT `secure_key` FROM `' . _DB_PREFIX_ . 'customer` WHERE `id_customer` = ' . (int) $id_customer)) { $secure_key_default = $secure_key; } else { Toolbox::addLogLine(self::getL('Problem with a secure key recovery for the customer / NetEven Order Id') . ' ' . $neteven_order->OrderID); } /* Treatment of order informations */ $total_wt = 0; $total_product = 0; $total_product_wt = 0; $total_taxe = 0; foreach ($neteven_orders as $neteven_order_temp) { if ($neteven_order_temp->OrderID == $neteven_order->OrderID) { if (in_array($neteven_order_temp->Status, $this->getValue('t_list_order_status'))) { continue; } $total_product += (double) $neteven_order_temp->Price->_ - (double) $neteven_order_temp->VAT->_; $total_product_wt += (double) $neteven_order_temp->Price->_; $total_taxe += $neteven_order_temp->VAT->_; } } $total_wt = $total_product_wt + $neteven_order->OrderShippingCost->_; $date_now = date('Y-m-d H:i:s'); if ($this->time_analyse) { $this->current_time_2 = time(); Toolbox::displayDebugMessage(self::getL('Order total') . ' : ' . ((int) $this->current_time_2 - (int) $this->current_time_0) . 's'); } /* Creating and add order in PrestaShop */ if (!($res = Db::getInstance()->getRow('SELECT * FROM `' . _DB_PREFIX_ . 'orders_gateway` WHERE `id_order_neteven` = ' . (int) $neteven_order->OrderID . ' AND `id_order_detail_neteven` = 0'))) { /* Creating cart */ $cart = new Cart(); $cart->id_address_delivery = (int) $id_address_shipping; $cart->id_address_invoice = (int) $id_address_billing; $cart->id_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT'); $cart->id_customer = (int) $id_customer; $cart->id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); $cart->id_carrier = Gateway::getConfig('CARRIER_NETEVEN'); $cart->recyclable = 1; $cart->gift = 0; $cart->gift_message = ''; $cart->date_add = $date_now; $cart->secure_key = $secure_key_default; $cart->date_upd = $date_now; if (!$cart->add()) { Toolbox::addLogLine(self::getL('Failed for cart creation / NetEven Order Id') . ' ' . (int) $neteven_order->OrderID); } if ($this->time_analyse) { $this->current_time_0 = time(); Toolbox::displayDebugMessage(self::getL('Cart') . ' : ' . ((int) $this->current_time_0 - (int) $this->current_time_2) . 's'); } /* Creating order */ $id_order_temp = 0; $order = new Order(); $order->id_carrier = Gateway::getConfig('CARRIER_NETEVEN'); $order->id_lang = Configuration::get('PS_LANG_DEFAULT'); $order->id_customer = $id_customer; $order->id_cart = $cart->id; $order->id_currency = Configuration::get('PS_CURRENCY_DEFAULT'); $order->id_address_delivery = $id_address_shipping; $order->id_address_invoice = $id_address_billing; $order->secure_key = $secure_key_default; $order->payment = $neteven_order->PaymentMethod; $order->conversion_rate = 1; $order->module = 'nqgatewayneteven'; $order->recyclable = 0; $order->gift = 0; $order->gift_message = ' '; $order->shipping_number = ''; /* generate reference order */ $nbr_order_neteven = Configuration::get('NUMBER_ORDER_NETEVEN'); if (false === $nbr_order_neteven) { $nbr_order_neteven = 1; } else { $nbr_order_neteven = (int) str_replace('N', '', $nbr_order_neteven); $nbr_order_neteven++; } $next_ref_gen_order_neteven = 'N' . sprintf('%07s', $nbr_order_neteven); Configuration::updateValue('NUMBER_ORDER_NETEVEN', $next_ref_gen_order_neteven); $order->reference = $next_ref_gen_order_neteven; /* ----- */ $carrier = new Carrier((int) $order->id_carrier); if (method_exists($carrier, 'getTaxesRate')) { $carrier_tax_rate = $carrier->getTaxesRate(new Address($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); } elseif (method_exists('Tax', 'getCarrierTaxRate')) { $carrier_tax_rate = (double) Tax::getCarrierTaxRate($order->id_carrier, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } else { $carrier_tax_rate = 100; } $total_shipping_tax_excl = $carrier_tax_rate ? $neteven_order->OrderShippingCost->_ / ($carrier_tax_rate / 100) : $neteven_order->OrderShippingCost->_; $total_wt = $total_product_wt + $neteven_order->OrderShippingCost->_; $total = $total_product + $total_shipping_tax_excl; $order->total_discounts_tax_excl = 0; $order->total_discounts_tax_incl = 0; $order->total_discounts = 0; $order->total_wrapping_tax_excl = 0; $order->total_wrapping_tax_incl = 0; $order->total_wrapping = 0; $order->total_products = (double) number_format($total_product, 2, '.', ''); $order->total_products_wt = (double) number_format($total_product_wt, 2, '.', ''); $order->total_shipping_tax_excl = (double) number_format($total_shipping_tax_excl, 2, '.', ''); $order->total_shipping_tax_incl = (double) number_format($neteven_order->OrderShippingCost->_, 2, '.', ''); $order->total_shipping = (double) number_format($neteven_order->OrderShippingCost->_, 2, '.', ''); $order->total_paid_tax_excl = (double) number_format($total_wt - $total_taxe, 2, '.', ''); $order->total_paid_tax_incl = (double) number_format($total_wt, 2, '.', ''); $order->total_paid_real = (double) number_format($total_wt, 2, '.', ''); $order->total_paid = (double) number_format($total_wt, 2, '.', ''); $order->carrier_tax_rate = 0; $order->total_wrapping = 0; $order->invoice_number = 0; $order->delivery_number = 0; $order->invoice_date = $date_now; $order->delivery_date = $date_now; $order->valid = 1; $order->date_add = $date_now; $order->date_upd = $date_now; if (Configuration::get('PS_SHOP_ENABLE')) { $order->id_shop = (int) Configuration::get('PS_SHOP_DEFAULT'); } if (!$order->add()) { Toolbox::addLogLine(self::getL('Failed for order creation / NetEven Order Id') . ' ' . (int) $neteven_order->OrderID); } else { $id_order_temp = $order->id; Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'order_carrier` (`id_order`, `id_carrier`, `id_order_invoice`, `weight`, `shipping_cost_tax_excl`, `shipping_cost_tax_incl`, `tracking_number`, `date_add`) VALUES (' . (int) $id_order_temp . ', ' . (int) Gateway::getConfig('CARRIER_NETEVEN') . ', 0, 0, 0, 0, 0,"' . pSQL(date('Y-m-d H:i:s')) . '")'); Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'message` (`id_order`, `message`, `date_add`) VALUES (' . (int) $id_order_temp . ', "Place de marché ' . $neteven_order->MarketPlaceName . '", "' . pSQL(date('Y-m-d H:i:s')) . '")'); Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'message` (`id_order`, `message`, `date_add`) VALUES (' . (int) $id_order_temp . ', "ID order NetEven ' . $neteven_order->MarketPlaceOrderId . '", "' . pSQL(date('Y-m-d H:i:s')) . '")'); if ($this->time_analyse) { $this->current_time_2 = time(); Toolbox::displayDebugMessage(self::getL('Order') . ' : ' . ((int) $this->current_time_2 - (int) $this->current_time_0) . 's'); } Toolbox::addLogLine(self::getL('Add order Id') . ' ' . (int) $id_order_temp . ' ' . self::getL('NetEven Order Id') . ' ' . (int) $neteven_order->OrderID); if ($this->time_analyse) { $this->current_time_0 = time(); Toolbox::displayDebugMessage(self::getL('History') . ' : ' . ((int) $this->current_time_0 - (int) $this->current_time_2) . 's'); } /* Insert order in orders_gateway table */ if (!Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'orders_gateway` (`id_order_neteven`, `id_order`, `id_order_detail_neteven`, `date_add`, `date_upd`) VALUES (' . (int) $neteven_order->OrderID . ', ' . (int) $id_order_temp . ', 0, "' . pSQL($date_now) . '", "' . pSQL($date_now) . '")')) { Toolbox::addLogLine(self::getL('Failed for save export NetEven order Id') . ' ' . (int) $neteven_order->OrderID); } else { Toolbox::addLogLine(self::getL('Save export NetEven order Id') . ' ' . (int) $neteven_order->OrderID); } } } else { $id_order_temp = $res['id_order']; Toolbox::addLogLine(self::getL('Get already exported order Id') . ' ' . $res['id_order'] . ' ' . self::getL('NetEven Order Id') . ' ' . (int) $neteven_order->OrderID); } return $id_order_temp; }
public function affectProperties() { global $cookie; // Get the configuration $this->shipping_delay = Gateway::getConfig('SHIPPING_DELAY'); $this->comment = Gateway::getConfig('COMMENT'); $this->default_brand = Gateway::getConfig('DEFAULT_BRAND'); $this->id_country_default = Configuration::get('PS_COUNTRY_DEFAULT'); $this->default_passwd = Gateway::getConfig('PASSWORD_DEFAULT'); $this->id_employee_neteven = (int) Gateway::getConfig('ID_EMPLOYEE_NETEVEN'); $this->id_customer_neteven = (int) Gateway::getConfig('ID_CUSTOMER_NETEVEN'); $this->id_order_state_neteven = (int) Gateway::getConfig('ID_ORDER_STATE_NETEVEN'); $this->shipping_price_local = Gateway::getConfig('SHIPPING_PRICE_LOCAL'); $this->shipping_price_international = Gateway::getConfig('SHIPPING_PRICE_INTERNATIONAL'); $this->id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); // Get feature links NetEven/PrestaShop $feature_links = Db::getInstance()->ExecuteS(' SELECT ogfl.*, agl.`name` as attribute_name, fl.`name` as feature_name, ogf.`value` FROM `' . _DB_PREFIX_ . 'orders_gateway_feature_link` ogfl LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (agl.`id_attribute_group` = ogfl.`id_attribute_group` AND agl.`id_lang` = ' . (int) $cookie->id_lang . ') LEFT JOIN `' . _DB_PREFIX_ . 'feature_lang` fl ON (fl.`id_feature` = ogfl.`id_feature` AND fl.`id_lang` = ' . (int) $cookie->id_lang . ') LEFT JOIN `' . _DB_PREFIX_ . 'orders_gateway_feature` ogf ON (ogf.`id_order_gateway_feature` = ogfl.`id_order_gateway_feature`) '); $temp = array(); foreach ($feature_links as $feature_link) { if (!empty($feature_link['id_attribute_group'])) { $temp[$feature_link['attribute_name']] = $feature_link['value']; } else { $temp[$feature_link['feature_name']] = $feature_link['value']; } } $this->feature_links = $temp; // Get order states if (Gateway::getConfig('ORDER_STATE_BEFORE')) { $this->order_state_before = explode(':', Gateway::getConfig('ORDER_STATE_BEFORE')); } if (Gateway::getConfig('ORDER_STATE_AFTER')) { $this->order_state_after = explode(':', Gateway::getConfig('ORDER_STATE_AFTER')); } $this->mail_list_alert = explode(':', Gateway::getConfig('MAIL_LIST_ALERT')); $this->debug = Gateway::getConfig('DEBUG') == 1 ? true : false; $this->send_request_to_mail = Gateway::getConfig('SEND_REQUEST_BY_EMAIL') == 1 ? true : false; $this->mail_active = Gateway::getConfig('MAIL_ACTIVE') == 1 ? true : false; if ($this->debug == true) { ini_set('display_errors', 1); error_reporting(E_ALL); } }
/** * Formatage des informations produit pour NetEven. * @param $t_product * @param bool $display * @return array */ private function getPropertiesForNetEven($products, $display = false) { if (!sizeof($products)) { return false; } global $cookie, $link; if (!$link) { $link = new Link(); } $products_temp = array(); $compteur_product_no_ean13 = 0; $compteur_product_no_ref = 0; foreach ($products as $product) { $product_reference = 'P' . $product['id_product']; if (!empty($product['id_product_attribute'])) { $product_reference = 'D' . $product['id_product_attribute']; } if (self::$type_sku == 'reference') { $product_reference = $product['product_reference']; if (!empty($product['id_product_attribute'])) { $product_reference = $product['product_attribute_reference']; } } $codeEan = sprintf('%013s', !empty($product['ean13_declinaison']) ? $product['ean13_declinaison'] : $product['ean13']); $id_product_attribute = NULL; if (!empty($product['id_product_attribute'])) { $id_product_attribute = (int) $product['id_product_attribute']; } $product_price = Product::getPriceStatic((int) $product['id_product'], true, (int) $id_product_attribute, 2, NULL, false, true); $product_price_without_reduction = Product::getPriceStatic((int) $product['id_product'], true, (int) $id_product_attribute, 2, NULL, false, false); $categories = $this->getProductCategories($product); $classification = str_replace('//', '', implode('/', $categories)); $quantity = Product::getQuantity((int) $product['id_product'], !empty($product['id_product_attribute']) ? (int) $product['id_product_attribute'] : NULL); $indice = count($products_temp); $shipping_price_local = $this->getValue('shipping_price_local'); if (self::$shipping_by_product && !empty(self::$shipping_by_product_fieldname)) { $shipping_price_local = $product[self::$shipping_by_product_fieldname]; } $products_temp[$indice] = array('Title' => $product['name'], 'SKU' => $product_reference, 'Description' => strip_tags($product['description']), 'EAN' => $codeEan, 'Quantity' => $quantity, 'PriceFixed' => $product_price_without_reduction, 'PriceRetail' => $product_price, 'Etat' => 11, 'SKUFamily' => self::$type_sku == 'reference' ? $product['declinaison_default_ref'] : $product['declinaison_default'], 'Classification' => str_replace('Accueil/', '', $classification), 'shipping_delay' => $this->getValue('shipping_delay'), 'Comment' => $this->getValue('comment'), 'Brand' => !empty($product['name_manufacturer']) ? $product['name_manufacturer'] : $this->getValue('default_brand')); if ($shipping_price_local == '-') { unset($products_temp[$indice]['shipping_price_local']); } if (empty($products_temp[$indice]['shipping_price_international'])) { unset($products_temp[$indice]['shipping_price_international']); } $images = $this->getProductImages($product); foreach ($images as $key => $image) { if (is_object($link)) { $img_url = $link->getImageLink($product['link_rewrite'], (int) $product['id_product'] . '-' . (int) $image['id_image'], Gateway::getConfig('IMAGE_TYPE_NAME')); $products_temp[$indice]['Image' . ($key + 1)] = 'http://' . str_replace('http://', '', $img_url); } } // Attributes and fetures of product $products_temp[$indice]['ArrayOfSpecificFields'] = array(); $products_temp[$indice]['ArrayOfSpecificFields'][] = array('Name' => 'categorie', 'Value' => $category_default->name); $sql = ' SELECT GROUP_CONCAT(DISTINCT CONCAT(fl.`name`," {##} ",fvl.`value`) SEPARATOR "' . pSQL($this->getValue('separator')) . ' ") as feature_name FROM `' . _DB_PREFIX_ . 'feature_product` fp LEFT JOIN `' . _DB_PREFIX_ . 'feature_value_lang` fvl ON (fp.`id_feature_value` = fvl.`id_feature_value` AND fvl.id_lang=' . (int) $cookie->id_lang . ') LEFT JOIN `' . _DB_PREFIX_ . 'feature_value` fv ON (fv.`id_feature_value` = fvl.`id_feature_value`) LEFT JOIN `' . _DB_PREFIX_ . 'feature_lang` fl ON (fl.`id_feature` = fv.`id_feature` AND fl.`id_lang`=' . (int) $cookie->id_lang . ') WHERE fp.`id_product` = ' . (int) $product['id_product'] . ' '; $product['feature_name'] = Db::getInstance()->getValue($sql); if (empty($product['attribute_name']) && empty($product['feature_name'])) { continue; } $features_attributes = array(); if (!empty($product['attribute_name'])) { $features_attributes = explode($this->getValue('separator'), $product['attribute_name']); } if (!empty($product['feature_name'])) { $features_attributes = array_merge($t_carac_attr, explode($this->getValue('separator'), $product['feature_name'])); } $feature_links = $this->getValue('feature_links'); foreach ($features_attributes as $value) { $infos = explode(' {##} ', $value); if (count($infos) == 2 && !empty($infos[0]) && !empty($infos[1]) && !empty($feature_links[trim($infos[0])])) { $specific_name = $feature_links[trim($infos[0])]; $products_temp[$indice]['ArrayOfSpecificFields'][] = array('Name' => $specific_name, 'Value' => $infos[1]); } } if (count(self::$customizable_field) > 0) { foreach (self::$customizable_field as $key => $value) { $products_temp[$indice]['ArrayOfSpecificFields'][] = array('Name' => $key, 'Value' => $value); } } } return $products_temp; }