/** * Initialize product controller * @see FrontController::init() */ public function init() { parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } else { $this->canonicalRedirection(); } if (!Validate::isLoadedObject($this->product)) { $this->errors[] = Tools::displayError('Product not found'); } else { if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) { $this->product->quantity = 0; } $this->product->description = $this->transformDescriptionWithImg($this->product->description); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) * allow showing the product * In all the others cases => 404 "Product is no longer available" */ if (!$this->product->isAssociatedToShop() || !$this->product->active && (Tools::getValue('adtoken') != Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) || !file_exists(_PS_ROOT_DIR_ . '/' . Tools::getValue('ad') . '/index.php'))) { header('HTTP/1.1 404 page not found'); $this->errors[] = Tools::displayError('Product is no longer available.'); } else { if (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) { $this->errors[] = Tools::displayError('You do not have access to this product.'); } } // Load category if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs)) { // If the previous page was a category and is a parent category of the product use this category as parent category if (isset($regs[2]) && is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) { $this->category = new Category($regs[2], (int) $this->context->cookie->id_lang); } } else { if (isset($regs[5]) && is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) { $this->category = new Category($regs[5], (int) $this->context->cookie->id_lang); } } } } else { // Set default product category $this->category = new Category($this->product->id_category_default, (int) $this->context->cookie->id_lang); } } }
public static function getItemTable($id_product, $id_lang, $full = false) { $price_sql = Product::getProductPriceSql('p.id_product', 'pp'); $sql = "\n\t\t SELECT\n p.*,\n\t\t pl.*,\n\t\t i.`id_image`,\n\t\t il.`legend`,\n\t\t t.`rate`,\n\t\t cl.`name` AS category_default,\n\t\t a.quantity AS pack_quantity\n\t\t FROM\n `PREFIX_pack` a\n\t\t LEFT JOIN `PREFIX_product` p ON\n p.id_product = a.id_product_item\n\t\t LEFT JOIN `PREFIX_product_lang` pl ON\n p.id_product = pl.id_product AND pl.`id_lang` = {$id_lang}\n\t\t LEFT JOIN `PREFIX_image` i ON\n i.`id_product` = p.`id_product` AND i.`cover` = 1\n\t\t LEFT JOIN `PREFIX_image_lang` il ON\n i.`id_image` = il.`id_image` AND il.`id_lang` = {$id_lang}\n\t\t LEFT JOIN `PREFIX_category_lang` cl ON\n p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = {$id_lang}\n {$price_sql}\n\t\t LEFT JOIN `PREFIX_tax` t ON\n t.`id_tax` = pp.`id_tax`\n\t\t WHERE a.`id_product_pack` = {$id_product}"; $sql = str_replace('PREFIX_', _DB_PREFIX_, $sql); $result = Db::getInstance()->ExecuteS($sql); if (!$full) { return $result; } $arrayResult = array(); foreach ($result as $row) { if (!Pack::isPack($row['id_product'])) { $arrayResult[] = Product::getProductProperties($id_lang, $row); } } return $arrayResult; }
public static function getItemTable($id_product, $id_lang, $full = false) { $result = Db::getInstance()->ExecuteS(' SELECT p.*, pl.*, i.`id_image`, il.`legend`, t.`rate`, cl.`name` AS category_default, a.quantity AS pack_quantity FROM `' . _DB_PREFIX_ . 'pack` a LEFT JOIN `' . _DB_PREFIX_ . 'product` p ON p.id_product = a.id_product_item LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.id_product = pl.id_product AND pl.`id_lang` = ' . intval($id_lang) . ') LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1) LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = ' . intval($id_lang) . ') LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (p.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . intval($id_lang) . ') LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = p.`id_tax`) WHERE a.`id_product_pack` = ' . intval($id_product)); if (!$full) { return $result; } $arrayResult = array(); foreach ($result as $row) { if (!Pack::isPack($row['id_product'])) { $arrayResult[] = Product::getProductProperties($id_lang, $row); } } return $arrayResult; }
/** * @param int $id_customization * @return bool * @deprecated */ public function deleteCustomizedDatas($id_customization) { Tools::displayAsDeprecated(); if (Pack::isPack((int) $product['id_product'])) { $products_pack = Pack::getItems((int) $product['id_product'], (int) Configuration::get('PS_LANG_DEFAULT')); foreach ($products_pack as $product_pack) { $tab_product_pack['id_product'] = (int) $product_pack->id; $tab_product_pack['id_product_attribute'] = self::getDefaultAttribute($tab_product_pack['id_product'], 1); $tab_product_pack['cart_quantity'] = (int) ($product_pack->pack_quantity * $product['cart_quantity']); self::updateQuantity($tab_product_pack); } } if (($result = Db::getInstance()->ExecuteS('SELECT `value` FROM `' . _DB_PREFIX_ . 'customized_data` WHERE `id_customization` = ' . (int) $id_customization . ' AND `type` = ' . _CUSTOMIZE_FILE_)) === false) { return false; } foreach ($result as $row) { if (!@unlink(_PS_UPLOAD_DIR_ . $row['value']) or !@unlink(_PS_UPLOAD_DIR_ . $row['value'] . '_small')) { return false; } } return Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'customization` WHERE `id_customization` = ' . (int) $id_customization) and Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'customized_data` WHERE `id_customization` = ' . (int) $id_customization); }
/** * delete all items in pack, then check if type_product value is 2. * if yes, add the pack items from input "inputPackItems" * * @param Product $product * @return boolean */ public function updatePackItems($product) { Pack::deleteItems($product->id); // lines format: QTY x ID-QTY x ID if (Tools::getValue('type_product') == Product::PTYPE_PACK) { $product->setDefaultAttribute(0); //reset cache_default_attribute $items = Tools::getValue('inputPackItems'); $lines = array_unique(explode('-', $items)); // lines is an array of string with format : QTYxID if (count($lines)) { foreach ($lines as $line) { if (!empty($line)) { list($qty, $item_id) = explode('x', $line); if ($qty > 0 && isset($item_id)) { if (Pack::isPack((int) $item_id)) { $this->errors[] = Tools::displayError('You can\'t add product packs into a pack'); } elseif (!Pack::addItem((int) $product->id, (int) $item_id, (int) $qty)) { $this->errors[] = Tools::displayError('An error occurred while attempting to add products to the pack.'); } } } } } } }
private function displayPack(Product $obj) { global $currentIndex, $cookie; $boolPack = ($obj->id and Pack::isPack($obj->id) or Tools::getValue('ppack')) ? true : false; $packItems = $boolPack ? Pack::getItems($obj->id, $cookie->id_lang) : array(); echo ' <tr> <td> <input type="checkbox" name="ppack" id="ppack" value="1"' . ($boolPack ? ' checked="checked"' : '') . ' onchange="openCloseLayer(\'ppackdiv\');" /> <label class="t" for="ppack">' . $this->l('Pack') . '</label> </td> <td> <div id="ppackdiv" ' . ($boolPack ? '' : ' style="display: none;"') . '> <div id="divPackItems">'; foreach ($packItems as $packItem) { echo $packItem->pack_quantity . ' x ' . $packItem->name . '<span onclick="delPackItem(' . $packItem->id . ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />'; } echo ' </div> <input type="hidden" name="inputPackItems" id="inputPackItems" value="'; if (Tools::getValue('inputPackItems')) { echo Tools::getValue('inputPackItems'); } else { foreach ($packItems as $packItem) { echo $packItem->pack_quantity . 'x' . $packItem->id . '-'; } } echo '" /> <input type="hidden" name="namePackItems" id="namePackItems" value="'; if (Tools::getValue('namePackItems')) { echo Tools::getValue('namePackItems'); } else { foreach ($packItems as $packItem) { echo $packItem->pack_quantity . 'x ' . $packItem->name . '¤'; } } echo '" /> <script type="text/javascript"> var formProduct; var packItems = new Array(); ' . $this->fillPackItems($obj) . ' ' . $this->addPackItem() . ' ' . $this->delPackItem() . ' delPackItem(0); </script> <select id="selectPackItems" name="selectPackItems" style="width: 380px;" onfocus="fillPackItems();"> <option value="0" selected="selected">-- ' . $this->l('Choose') . ' --</option> </select> <input type="text" name="quantityPackItems" id="quantityPackItems" value="1" size="1" /> <span onclick="addPackItem();" style="cursor: pointer;"><img src="../img/admin/add.gif" alt="' . $this->l('Add an item to the pack') . '" title="' . $this->l('Add an item to the pack') . '" /></span> <br />' . $this->l('Filter:') . ' <input type="text" size="25" name="filterPack" onkeyup="fillPackItems();" class="space" /> </td> </div> </tr>'; }
protected function initPack(Product $product) { $this->tpl_form_vars['is_pack'] = $product->id && Pack::isPack($product->id) || Tools::getValue('ppack') || Tools::getValue('type_product') == Product::PTYPE_PACK; $product->packItems = Pack::getItems($product->id, $this->context->language->id); $input_pack_items = ''; if (Tools::getValue('inputPackItems')) { $input_pack_items = Tools::getValue('inputPackItems'); } else { foreach ($product->packItems as $pack_item) { $input_pack_items .= $pack_item->pack_quantity . 'x' . $pack_item->id . '-'; } } $this->tpl_form_vars['input_pack_items'] = $input_pack_items; $input_namepack_items = ''; if (Tools::getValue('namePackItems')) { $input_namepack_items = Tools::getValue('namePackItems'); } else { foreach ($product->packItems as $pack_item) { $input_namepack_items .= $pack_item->pack_quantity . ' x ' . $pack_item->name . '¤'; } } $this->tpl_form_vars['input_namepack_items'] = $input_namepack_items; }
protected function reinjectQuantity($order_detail, $qty_cancel_product, $delete = false) { // Reinject product $reinjectable_quantity = (int) $order_detail->product_quantity - (int) $order_detail->product_quantity_reinjected; $quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product; // @since 1.5.0 : Advanced Stock Management $product_to_inject = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop); $product = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop); if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management && $order_detail->id_warehouse != 0) { $manager = StockManagerFactory::getManager(); $movements = StockMvt::getNegativeStockMvts($order_detail->id_order, $order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject); $left_to_reinject = $quantity_to_reinject; foreach ($movements as $movement) { if ($left_to_reinject > $movement['physical_quantity']) { $quantity_to_reinject = $movement['physical_quantity']; } $left_to_reinject -= $quantity_to_reinject; if (Pack::isPack((int) $product->id)) { // Gets items if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0) { $products_pack = Pack::getItems((int) $product->id, (int) Configuration::get('PS_LANG_DEFAULT')); // Foreach item foreach ($products_pack as $product_pack) { if ($product_pack->advanced_stock_management == 1) { $manager->addProduct($product_pack->id, $product_pack->id_pack_product_attribute, new Warehouse($movement['id_warehouse']), $product_pack->pack_quantity * $quantity_to_reinject, null, $movement['price_te'], true); } } } if ($product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)) { $manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true); } } else { $manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true); } } $id_product = $order_detail->product_id; if ($delete) { $order_detail->delete(); } StockAvailable::synchronize($id_product); } elseif ($order_detail->id_warehouse == 0) { StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject, $order_detail->id_shop); if ($delete) { $order_detail->delete(); } } else { $this->errors[] = Tools::displayError('This product cannot be re-stocked.'); } }
public function update_cart_by_site_xml($order_id, $data) { $xml = simplexml_load_string($data); $prefix = _DB_PREFIX_; $tablename = $prefix . 'orders'; $total_amount = 0; $total_principal = 0; $shipping_amount = 0; $total_promo = 0; $ClientRequestId = 0; $WrappingAmount = 0; $gift = 0; $gift_message = ' '; foreach ($xml->ProcessedOrder->ProcessedOrderItems->ProcessedOrderItem as $item) { $SKU = (string) $item->SKU; if ($SKU == 'wrapping_fee') { $WrappingAmount = (double) $item->Price->Amount; $gift = 1; $gift_message = (string) $item->Description; } $Title = (string) $item->Title; $Amount = (double) $item->Price->Amount; $ClientRequestId = (int) $item->ClientRequestId; $other_promo = 0; foreach ($item->ItemCharges->Component as $amount_type) { $item_charge_type = (string) $amount_type->Type; if ($item_charge_type == 'Principal') { $principal = (string) $amount_type->Charge->Amount; } if ($item_charge_type == 'Shipping') { $Shipping = (string) $amount_type->Charge->Amount; } if ($item_charge_type == 'PrincipalPromo') { $principal_promo = (string) $amount_type->Charge->Amount; } if ($item_charge_type == 'ShippingPromo') { $shipping_promo = (string) $amount_type->Charge->Amount; } if ($item_charge_type == 'OtherPromo') { $other_promo = (string) $amount_type->Charge->Amount; } } $CurrencyCode = (string) $item->Price->CurrencyCode; $Quantity = (int) $item->Quantity; /* * Total Item Charge = (Principal - PrincipalPromo) + (Shipping - ShippingPromo) + Tax + ShippingTax */ $total_principal += $principal; $total_amount += $principal - $principal_promo + ($Shipping - $shipping_promo); $shipping_amount += $Shipping; $total_promo += $principal_promo + $shipping_promo + $other_promo; } $total_principal = $total_principal - $WrappingAmount; $ShippingServiceLevel = (string) $xml->ProcessedOrder->ShippingServiceLevel; $sql = 'UPDATE `' . $prefix . 'pwa_orders` set `shipping_service` = "' . $ShippingServiceLevel . '" , `order_type` = "site" where `prestashop_order_id` = "' . $order_id . '" '; Db::getInstance()->Execute($sql); $id_cart = $ClientRequestId; $this->context = Context::getContext(); $this->context->cart = new Cart($id_cart); if ((int) $this->context->cart->id_customer == 0) { $email = (string) $xml->ProcessedOrder->BuyerInfo->BuyerEmailAddress; $sql = 'SELECT * from `' . $prefix . 'customer` where email = "' . $email . '" '; $results = Db::getInstance()->ExecuteS($sql); if (empty($results)) { $name = (string) $xml->ProcessedOrder->BuyerInfo->BuyerName; $name_arr = explode(' ', $name); if (count($name_arr) > 1) { $firstname = ''; for ($i = 0; $i <= count($name_arr) - 2; $i++) { $firstname = $firstname . ' ' . $name_arr[$i]; } $lastname = $name_arr[count($name_arr) - 1]; } else { $firstname = $name; $lastname = '.'; } $password = Tools::passwdGen(); $customer = new Customer(); $customer->firstname = trim($firstname); $customer->lastname = $lastname; $customer->email = (string) $xml->ProcessedOrder->BuyerInfo->BuyerEmailAddress; $customer->passwd = md5($password); $customer->active = 1; if (Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) { $customer->is_guest = 1; } else { $customer->is_guest = 0; } $customer->add(); $customer_id = $customer->id; if (Configuration::get('PS_CUSTOMER_CREATION_EMAIL') && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) { Mail::Send($this->context->language->id, 'account', Mail::l('Welcome!'), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => $password), $customer->email, $customer->firstname . ' ' . $customer->lastname); } } else { $customer_id = $results[0]['id_customer']; } $id_country = Country::getByIso((string) $xml->ProcessedOrder->ShippingAddress->CountryCode); if ($id_country == 0 || $id_country == '') { $id_country = 110; } $name = (string) $xml->ProcessedOrder->ShippingAddress->Name; $name_arr = explode(' ', $name); if (count($name_arr) > 1) { $firstname = ''; for ($i = 0; $i <= count($name_arr) - 2; $i++) { $firstname = $firstname . ' ' . $name_arr[$i]; } $lastname = $name_arr[count($name_arr) - 1]; } else { $firstname = $name; $lastname = '.'; } $address = new Address(); $address->id_country = $id_country; $address->id_state = 0; $address->id_customer = $customer_id; $address->alias = 'My Address'; $address->firstname = trim($firstname); $address->lastname = $lastname; $address->address1 = (string) $xml->ProcessedOrder->ShippingAddress->AddressFieldOne; $address->address2 = (string) $xml->ProcessedOrder->ShippingAddress->AddressFieldTwo; $address->postcode = (string) $xml->ProcessedOrder->ShippingAddress->PostalCode; $address->city = (string) $xml->ProcessedOrder->ShippingAddress->City . ' ' . (string) $xml->ProcessedOrder->ShippingAddress->State; $address->active = 1; $address->add(); $address_id = $address->id; $cart = new Cart($id_cart); $cart->id_customer = $customer_id; $cart->id_address_delivery = $address_id; $cart->id_address_invoice = $address_id; $cart->update(); } $this->context->cart = new Cart($id_cart); $this->context->customer = new Customer($this->context->cart->id_customer); $id_order_state = 99; // The tax cart is loaded before the customer so re-cache the tax calculation method //$this->context->cart->setTaxCalculationMethod(); $this->context->language = new Language($this->context->cart->id_lang); $this->context->shop = $shop ? $shop : new Shop($this->context->cart->id_shop); $id_currency = $currency_special ? (int) $currency_special : (int) $this->context->cart->id_currency; $this->context->currency = new Currency($id_currency, null, $this->context->shop->id); $reference = Order::generateReference(); $cart_rules = $this->context->cart->getCartRules(); $order = new Order(); $order->id = $order_id; $order->id_customer = (int) $this->context->cart->id_customer; $order->id_address_invoice = (int) $this->context->cart->id_address_invoice; $order->id_shop = (int) $this->context->shop->id; $order->id_shop_group = (int) $this->context->shop->id_shop_group; $carrier = null; if ((int) $this->context->cart->id_carrier) { $carrier = 'yes'; $id_carrier = (int) $this->context->cart->id_carrier; } else { $sql = 'SELECT id_carrier from `' . $prefix . 'carrier` where `active` = 1 and `deleted` = 0 limit 0,1'; $result = Db::getInstance()->ExecuteS($sql); $id_carrier = $result[0]['id_carrier']; } $sql = 'UPDATE `' . $tablename . '` set `id_customer` = ' . (int) $this->context->cart->id_customer . ', `id_carrier` = ' . $id_carrier . ', `id_address_invoice` = ' . (int) $this->context->cart->id_address_invoice . ', `id_address_delivery` = ' . (int) $this->context->cart->id_address_delivery . ', `id_currency` = ' . $this->context->currency->id . ', `id_lang` = ' . (int) $this->context->cart->id_lang . ', `id_cart` = ' . (int) $this->context->cart->id . ', `reference` = "' . $reference . '", `id_shop` = ' . (int) $this->context->shop->id . ', `id_shop_group` = ' . (int) $this->context->shop->id_shop_group . ', `secure_key` = "' . $this->context->cart->secure_key . '", `conversion_rate` = ' . $this->context->currency->conversion_rate . ', `total_paid` = ' . $total_amount . ', `total_paid_tax_incl` = ' . $total_amount . ', `total_paid_tax_excl` = ' . $total_amount . ', `total_paid_real` = 0, `total_shipping` = ' . $shipping_amount . ', `total_shipping_tax_incl` = ' . $shipping_amount . ', `total_shipping_tax_excl` = ' . $shipping_amount . ', `total_discounts` = ' . (double) $total_promo . ', `total_discounts_tax_incl` = ' . (double) $total_promo . ', `total_discounts_tax_excl` = ' . (double) $total_promo . ', `total_products` = ' . $total_principal . ', `total_products_wt` = ' . $total_principal . ', `total_wrapping_tax_incl` = ' . $WrappingAmount . ', `total_wrapping_tax_excl` = ' . $WrappingAmount . ', `total_wrapping` = ' . $WrappingAmount . ', `gift` = ' . $gift . ', `gift_message` = "' . $gift_message . '", `invoice_date` = "0000-00-00 00:00:00", `delivery_date` = "0000-00-00 00:00:00" where `id_order` = ' . $order_id . ' '; //`round_mode` = '.Configuration::get('PS_PRICE_ROUND_MODE').', //`carrier_tax_rate` = '.$carrier->getTaxesRate(new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})).' , Db::getInstance()->Execute($sql); $acknowledge_arr = array(); $i = 0; foreach ($xml->ProcessedOrder->ProcessedOrderItems->ProcessedOrderItem as $item) { $SKU = (string) $item->SKU; if ($SKU == 'wrapping_fee') { //Nothing } else { $AmazonOrderItemCode = (string) $item->AmazonOrderItemCode; $Title = (string) $item->Title; $Amount = (double) $item->Price->Amount; $product_id = (int) $item->ItemCustomData->Item_product_id; $product_attribute_id = (int) $item->ItemCustomData->Item_attr_product_id; $Item_price_excl_tax = $item->ItemCustomData->Item_price_excl_tax; $A_Name = ''; foreach ($item->ItemCustomData->Item_attribute as $attribute) { if ($A_Name == '') { $A_Name = $attribute->Attribute_name . ' : ' . $attribute->Attribute_val; } else { $A_Name = $A_Name . ', ' . $attribute->Attribute_name . ' : ' . $attribute->Attribute_val; } } $acknowledge_arr['items'][$i]['AmazonOrderItemCode'] = $AmazonOrderItemCode; $acknowledge_arr['items'][$i]['product_id'] = $product_id; $Title = $Title . ' - ' . $A_Name; $CurrencyCode = (string) $item->Price->CurrencyCode; $Quantity = (int) $item->Quantity; $other_promo = 0; foreach ($item->ItemCharges->Component as $amount_type) { $item_charge_type = (string) $amount_type->Type; if ($item_charge_type == 'Principal') { $principal = (string) $amount_type->Charge->Amount; } if ($item_charge_type == 'Shipping') { $Shipping = (string) $amount_type->Charge->Amount; } if ($item_charge_type == 'PrincipalPromo') { $principal_promo = (string) $amount_type->Charge->Amount; } if ($item_charge_type == 'ShippingPromo') { $shipping_promo = (string) $amount_type->Charge->Amount; } if ($item_charge_type == 'OtherPromo') { $other_promo = (string) $amount_type->Charge->Amount; } } $sql = 'INSERT into `' . $prefix . 'order_detail` set `id_order` = ' . $order_id . ', `product_id` = ' . $product_id . ', `product_attribute_id` = ' . $product_attribute_id . ', `product_name` = "' . $Title . '", `product_quantity` = ' . $Quantity . ', `product_quantity_in_stock` = ' . $Quantity . ', `product_price` = ' . $Amount . ', `product_reference` = "' . $SKU . '", `total_price_tax_incl` = ' . $Amount * $Quantity . ', `total_price_tax_excl` = ' . $Item_price_excl_tax * $Quantity . ', `unit_price_tax_incl` = ' . $Amount . ', `unit_price_tax_excl` = ' . $Item_price_excl_tax . ', `original_product_price` = ' . $Amount . ' '; Db::getInstance()->Execute($sql); if (Pack::isPack($product_id)) { $product = new Product((int) $product_id); if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2) { $products_pack = Pack::getItems($product_id, (int) Configuration::get('PS_LANG_DEFAULT')); foreach ($products_pack as $product_pack) { $sql = 'UPDATE `' . $prefix . 'stock_available` set `quantity` = `quantity` - ' . $product_pack->pack_quantity * $Quantity . ' where `id_product` = ' . $product_pack->id . ' and `id_product_attribute` = 0 '; Db::getInstance()->Execute($sql); $sql = 'UPDATE `' . $prefix . 'stock_available` set `quantity` = `quantity` - ' . $product_pack->pack_quantity * $Quantity . ' where `id_product` = ' . $product_pack->id . ' and `id_product_attribute` = ' . $product_pack->id_pack_product_attribute . ' '; Db::getInstance()->Execute($sql); } } if ($product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)) { $sql = 'UPDATE `' . $prefix . 'stock_available` set `quantity` = `quantity` - ' . $Quantity . ' where `id_product` = ' . $product_id . ' and `id_product_attribute` = 0 '; Db::getInstance()->Execute($sql); if ($product_attribute_id > 0) { $sql = 'UPDATE `' . $prefix . 'stock_available` set `quantity` = `quantity` - ' . $Quantity . ' where `id_product` = ' . $product_id . ' and `id_product_attribute` = ' . $product_attribute_id . ' '; Db::getInstance()->Execute($sql); } $date = date('Y-m-d'); $sql = 'UPDATE `' . $prefix . 'product_sale` set `quantity` = `quantity` + ' . $Quantity . ', `sale_nbr` = `sale_nbr` + ' . $Quantity . ', `date_upd` = ' . $date . ' where `id_product` = ' . $product_id . ' '; Db::getInstance()->Execute($sql); } } else { $sql = 'UPDATE `' . $prefix . 'stock_available` set `quantity` = `quantity` - ' . $Quantity . ' where `id_product` = ' . $product_id . ' and `id_product_attribute` = 0 '; Db::getInstance()->Execute($sql); if ($product_attribute_id > 0) { $sql = 'UPDATE `' . $prefix . 'stock_available` set `quantity` = `quantity` - ' . $Quantity . ' where `id_product` = ' . $product_id . ' and `id_product_attribute` = ' . $product_attribute_id . ' '; Db::getInstance()->Execute($sql); } $date = date('Y-m-d'); $sql = 'UPDATE `' . $prefix . 'product_sale` set `quantity` = `quantity` + ' . $Quantity . ', `sale_nbr` = `sale_nbr` + ' . $Quantity . ', `date_upd` = ' . $date . ' where `id_product` = ' . $product_id . ' '; Db::getInstance()->Execute($sql); } } $i++; } // Adding an entry in order_carrier table if (!is_null($carrier)) { $order_carrier = new OrderCarrier(); $order_carrier->id_order = (int) $order->id; $order_carrier->id_carrier = (int) $id_carrier; $order_carrier->weight = '0'; $order_carrier->shipping_cost_tax_excl = (double) $shipping_amount; $order_carrier->shipping_cost_tax_incl = (double) $shipping_amount; $order_carrier->add(); } else { $order_carrier = new OrderCarrier(); $order_carrier->id_order = (int) $order->id; $order_carrier->id_carrier = (int) $id_carrier; $order_carrier->weight = '0'; $order_carrier->shipping_cost_tax_excl = (double) $shipping_amount; $order_carrier->shipping_cost_tax_incl = (double) $shipping_amount; $order_carrier->add(); } foreach ($cart_rules as $cart_rule) { $values['tax_incl'] = $cart_rule['value_real']; $values['tax_excl'] = $cart_rule['value_tax_exc']; $order->addCartRule($cart_rule['obj']->id, $cart_rule['obj']->name, $values, 0, $cart_rule['obj']->free_shipping); } // Set the order status $history = new OrderHistory(); $history->id_order = (int) $order->id; $history->changeIdOrderState((int) $id_order_state, $order->id, true); $history->addWithemail(true, array(), $this->context); if ($total_amount == 0) { $date = date('Y-m-d H:i:s'); $sql = 'INSERT into `' . $prefix . 'order_payment` set order_reference = "' . $reference . '", `id_currency` = "' . $this->context->currency->id . '", `amount` = "0.0", `payment_method` = "Pay With Amazon", `conversion_rate` = "' . $this->context->currency->conversion_rate . '", `date_add` = "' . $date . '" '; Db::getInstance()->Execute($sql); } $acknowledge_arr['MerchantOrderID'] = (int) $order->id; }
public static function buildXML() { global $country_infos; $context = Context::getContext(); $country_infos = array('id_group' => 0, 'id_tax' => 1); $html = '<products>' . "\n"; /* First line, columns */ $columns = array('id', 'name', 'smallimage', 'bigimage', 'producturl', 'description', 'price', 'retailprice', 'discount', 'recommendable', 'instock'); /* Setting parameters */ $conf = Configuration::getMultiple(array('PS_REWRITING_SETTINGS', 'PS_LANG_DEFAULT', 'PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT', 'PS_COUNTRY_DEFAULT', 'PS_SHOP_NAME', 'PS_CURRENCY_DEFAULT', 'PS_CARRIER_DEFAULT')); /* Searching for products */ $result = Db::getInstance()->executeS(' SELECT DISTINCT p.`id_product`, i.`id_image` FROM `' . _DB_PREFIX_ . 'product` p JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.id_product = p.id_product) LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.id_product = p.id_product) WHERE p.`active` = 1 AND i.id_image IS NOT NULL GROUP BY p.id_product'); foreach ($result as $k => $row) { if (Pack::isPack(intval($row['id_product']))) { continue; } $product = new Product(intval($row['id_product']), true); if (Validate::isLoadedObject($product)) { $imageObj = new Image($row['id_image']); $imageObj->id_product = intval($product->id); $line = array(); $line[] = $product->manufacturer_name . ' - ' . $product->name[intval($conf['PS_LANG_DEFAULT'])]; $line[] = Tools::getProtocol() . $_SERVER['HTTP_HOST'] . _THEME_PROD_DIR_ . $imageObj->getExistingImgPath() . '-small.jpg'; $line[] = Tools::getProtocol() . $_SERVER['HTTP_HOST'] . _THEME_PROD_DIR_ . $imageObj->getExistingImgPath() . '-thickbox.jpg'; $line[] = $context->link->getProductLink(intval($product->id), $product->link_rewrite[intval($conf['PS_LANG_DEFAULT'])], $product->ean13) . '&utm_source=criteo&aff=criteo'; $line[] = str_replace(array("\n", "\r", "\t", '|'), '', strip_tags(html_entity_decode($product->description_short[intval($conf['PS_LANG_DEFAULT'])], ENT_COMPAT, 'UTF-8'))); $price = $product->getPrice(true, intval(Product::getDefaultAttribute($product->id))); $line[] = number_format($price, 2, '.', ''); $line[] = number_format($product->getPrice(true, intval(Product::getDefaultAttribute(intval($product->id))), 6, NULL, false, false), 2, '.', ''); $line[] = $product->getPrice(true, NULL, 2, NULL, true); $line[] = '1'; $line[] = '1'; $cptXML = 1; $html .= "\t" . '<product id="' . $product->id . '">' . "\n"; foreach ($line as $column) { $html .= "\t\t" . '<' . $columns[$cptXML] . '>' . $column . '</' . $columns[$cptXML] . '>' . "\n"; $cptXML++; } $html .= "\t" . '</product>' . "\n"; } } $html .= '</products>' . "\n"; echo $html; }
/** * @see StockManagerInterface::removeProduct() */ public function removeProduct($id_product, $id_product_attribute = null, Warehouse $warehouse, $quantity, $id_stock_mvt_reason, $is_usable = true, $id_order = null) { $return = array(); if (!Validate::isLoadedObject($warehouse) || !$quantity || !$id_product) { return $return; } if (!StockMvtReason::exists($id_stock_mvt_reason)) { $id_stock_mvt_reason = Configuration::get('PS_STOCK_MVT_DEC_REASON_DEFAULT'); } $context = Context::getContext(); // Special case of a pack if (Pack::isPack((int) $id_product)) { // Gets items $products_pack = Pack::getItems((int) $id_product, (int) Configuration::get('PS_LANG_DEFAULT')); // Foreach item foreach ($products_pack as $product_pack) { $pack_id_product_attribute = Product::getDefaultAttribute($product_pack->id, 1); if ($product_pack->advanced_stock_management == 1) { $this->removeProduct($product_pack->id, $pack_id_product_attribute, $warehouse, $product_pack->pack_quantity * $quantity, $id_stock_mvt_reason, $is_usable, $id_order); } } } else { // gets total quantities in stock for the current product $physical_quantity_in_stock = (int) $this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), false); $usable_quantity_in_stock = (int) $this->getProductPhysicalQuantities($id_product, $id_product_attribute, array($warehouse->id), true); // check quantity if we want to decrement unusable quantity if (!$is_usable) { $quantity_in_stock = $physical_quantity_in_stock - $usable_quantity_in_stock; } else { $quantity_in_stock = $usable_quantity_in_stock; } // checks if it's possible to remove the given quantity if ($quantity_in_stock < $quantity) { return $return; } $stock_collection = $this->getStockCollection($id_product, $id_product_attribute, $warehouse->id); $stock_collection->getAll(); // check if the collection is loaded if (count($stock_collection) <= 0) { return $return; } $stock_history_qty_available = array(); $mvt_params = array(); $stock_params = array(); $quantity_to_decrement_by_stock = array(); $global_quantity_to_decrement = $quantity; // switch on MANAGEMENT_TYPE switch ($warehouse->management_type) { // case CUMP mode case 'WA': // There is one and only one stock for a given product in a warehouse in this mode $stock = $stock_collection->current(); $mvt_params = array('id_stock' => $stock->id, 'physical_quantity' => $quantity, 'id_stock_mvt_reason' => $id_stock_mvt_reason, 'id_order' => $id_order, 'price_te' => $stock->price_te, 'last_wa' => $stock->price_te, 'current_wa' => $stock->price_te, 'id_employee' => $context->employee->id, 'employee_firstname' => $context->employee->firstname, 'employee_lastname' => $context->employee->lastname, 'sign' => -1); $stock_params = array('physical_quantity' => $stock->physical_quantity - $quantity, 'usable_quantity' => $is_usable ? $stock->usable_quantity - $quantity : $stock->usable_quantity); // saves stock in warehouse $stock->hydrate($stock_params); $stock->update(); // saves stock mvt $stock_mvt = new StockMvt(); $stock_mvt->hydrate($mvt_params); $stock_mvt->save(); $return[$stock->id]['quantity'] = $quantity; $return[$stock->id]['price_te'] = $stock->price_te; break; case 'LIFO': case 'FIFO': // for each stock, parse its mvts history to calculate the quantities left for each positive mvt, // according to the instant available quantities for this stock foreach ($stock_collection as $stock) { $left_quantity_to_check = $stock->physical_quantity; if ($left_quantity_to_check <= 0) { continue; } $resource = Db::getInstance(_PS_USE_SQL_SLAVE_)->query(' SELECT sm.`id_stock_mvt`, sm.`date_add`, sm.`physical_quantity`, IF ((sm2.`physical_quantity` is null), sm.`physical_quantity`, (sm.`physical_quantity` - SUM(sm2.`physical_quantity`))) as qty FROM `' . _DB_PREFIX_ . 'stock_mvt` sm LEFT JOIN `' . _DB_PREFIX_ . 'stock_mvt` sm2 ON sm2.`referer` = sm.`id_stock_mvt` WHERE sm.`sign` = 1 AND sm.`id_stock` = ' . (int) $stock->id . ' GROUP BY sm.`id_stock_mvt` ORDER BY sm.`date_add` DESC'); while ($row = Db::getInstance()->nextRow($resource)) { // break - in FIFO mode, we have to retreive the oldest positive mvts for which there are left quantities if ($warehouse->management_type == 'FIFO') { if ($row['qty'] == 0) { break; } } // converts date to timestamp $date = new DateTime($row['date_add']); $timestamp = $date->format('U'); // history of the mvt $stock_history_qty_available[$timestamp] = array('id_stock' => $stock->id, 'id_stock_mvt' => (int) $row['id_stock_mvt'], 'qty' => (int) $row['qty']); // break - in LIFO mode, checks only the necessary history to handle the global quantity for the current stock if ($warehouse->management_type == 'LIFO') { $left_quantity_to_check -= (int) $row['physical_quantity']; if ($left_quantity_to_check <= 0) { break; } } } } if ($warehouse->management_type == 'LIFO') { // orders stock history by timestamp to get newest history first krsort($stock_history_qty_available); } else { // orders stock history by timestamp to get oldest history first ksort($stock_history_qty_available); } // checks each stock to manage the real quantity to decrement for each of them foreach ($stock_history_qty_available as $entry) { if ($entry['qty'] >= $global_quantity_to_decrement) { $quantity_to_decrement_by_stock[$entry['id_stock']][$entry['id_stock_mvt']] = $global_quantity_to_decrement; $global_quantity_to_decrement = 0; } else { $quantity_to_decrement_by_stock[$entry['id_stock']][$entry['id_stock_mvt']] = $entry['qty']; $global_quantity_to_decrement -= $entry['qty']; } if ($global_quantity_to_decrement <= 0) { break; } } // for each stock, decrements it and logs the mvts foreach ($stock_collection as $stock) { if (array_key_exists($stock->id, $quantity_to_decrement_by_stock) && is_array($quantity_to_decrement_by_stock[$stock->id])) { $total_quantity_for_current_stock = 0; foreach ($quantity_to_decrement_by_stock[$stock->id] as $id_mvt_referrer => $qte) { $mvt_params = array('id_stock' => $stock->id, 'physical_quantity' => $qte, 'id_stock_mvt_reason' => $id_stock_mvt_reason, 'id_order' => $id_order, 'price_te' => $stock->price_te, 'sign' => -1, 'referer' => $id_mvt_referrer, 'id_employee' => $context->employee->id); // saves stock mvt $stock_mvt = new StockMvt(); $stock_mvt->hydrate($mvt_params); $stock_mvt->save(); $total_quantity_for_current_stock += $qte; } $stock_params = array('physical_quantity' => $stock->physical_quantity - $total_quantity_for_current_stock, 'usable_quantity' => $is_usable ? $stock->usable_quantity - $total_quantity_for_current_stock : $stock->usable_quantity); $return[$stock->id]['quantity'] = $total_quantity_for_current_stock; $return[$stock->id]['price_te'] = $stock->price_te; // saves stock in warehouse $stock->hydrate($stock_params); $stock->update(); } } break; } } // if we remove a usable quantity, exec hook if ($is_usable) { Hook::exec('actionProductCoverage', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'warehouse' => $warehouse)); } return $return; }
public function setWsType($type_str) { $reverse_type_information = array('simple' => Product::PTYPE_SIMPLE, 'pack' => Product::PTYPE_PACK, 'virtual' => Product::PTYPE_VIRTUAL); if (!isset($reverse_type_information[$type_str])) { return false; } $type = $reverse_type_information[$type_str]; if (Pack::isPack((int) $this->id) && $type != Product::PTYPE_PACK) { Pack::deleteItems($this->id); } $this->cache_is_pack = $type == Product::PTYPE_PACK; $this->is_virtual = $type == Product::PTYPE_VIRTUAL; return true; }
private function displayPack(Product $obj) { global $currentIndex, $cookie; $boolPack = ($obj->id and Pack::isPack($obj->id) or Tools::getValue('ppack')) ? true : false; $packItems = $boolPack ? Pack::getItems($obj->id, $cookie->id_lang) : array(); echo ' <tr> <td> <input type="checkbox" name="ppack" id="ppack" value="1"' . ($boolPack ? ' checked="checked"' : '') . ' onclick="$(\'#ppackdiv\').slideToggle();" /> <label class="t" for="ppack">' . $this->l('Pack') . '</label> </td> <td> <div id="ppackdiv" ' . ($boolPack ? '' : ' style="display: none;"') . '> <div id="divPackItems">'; foreach ($packItems as $packItem) { echo $packItem->pack_quantity . ' x ' . $packItem->name . '<span onclick="delPackItem(' . $packItem->id . ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />'; } echo ' </div> <input type="hidden" name="inputPackItems" id="inputPackItems" value="'; if (Tools::getValue('inputPackItems')) { echo Tools::getValue('inputPackItems'); } else { foreach ($packItems as $packItem) { echo $packItem->pack_quantity . 'x' . $packItem->id . '-'; } } echo '" /> <input type="hidden" name="namePackItems" id="namePackItems" value="'; if (Tools::getValue('namePackItems')) { echo Tools::getValue('namePackItems'); } else { foreach ($packItems as $packItem) { echo $packItem->pack_quantity . ' x ' . $packItem->name . '¤'; } } echo '" /> <input type="hidden" size="2" id="curPackItemId" /> <p class="clear">' . $this->l('Begin typing the first letters of the product name, then select the product from the drop-down list:') . ' <br />' . $this->l('You cannot add downloadable products to a pack.') . '</p> <input type="text" size="25" id="curPackItemName" /> <input type="text" name="curPackItemQty" id="curPackItemQty" value="1" size="1" /> <script language="javascript"> ' . $this->addPackItem() . ' ' . $this->delPackItem() . ' </script> <span onclick="addPackItem();" style="cursor: pointer;"><img src="../img/admin/add.gif" alt="' . $this->l('Add an item to the pack') . '" title="' . $this->l('Add an item to the pack') . '" /></span> </td> </div> </tr>'; // param multipleSeparator:'||' ajouté à cause de bug dans lib autocomplete echo '<script type="text/javascript"> urlToCall = null; /* function autocomplete */ $(function() { $(\'#curPackItemName\') .autocomplete(\'ajax_products_list.php\', { delay: 100, minChars: 1, autoFill: true, max:20, matchContains: true, mustMatch:true, scroll:false, cacheLength:0, multipleSeparator:\'||\', formatItem: function(item) { return item[1]+\' - \'+item[0]; } }).result(function(event, item){ $(\'#curPackItemId\').val(item[1]); }); $(\'#curPackItemName\').setOptions({ extraParams: {excludeIds : getSelectedIds(), excludeVirtuals : 1} }); }); function getSelectedIds() { // input lines QTY x ID- var ids = ' . $obj->id . '+\',\'; ids += $(\'#inputPackItems\').val().replace(/\\d+x/g, \'\').replace(/\\-/g,\',\'); ids = ids.replace(/\\,$/,\'\'); return ids; } function getAccessorieIds() { var ids = ' . $obj->id . '+\',\'; ids += $(\'#inputAccessories\').val().replace(/\\-/g,\',\').replace(/\\,$/,\'\'); ids = ids.replace(/\\,$/,\'\'); return ids; } </script>'; }
public function process() { global $cart, $currency; parent::process(); if (!Validate::isLoadedObject($this->product)) { $this->errors[] = Tools::displayError('Product not found'); } else { if (!$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) { header('HTTP/1.1 404 page not found'); $this->errors[] = Tools::displayError('Product is no longer available.'); } elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) { $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id)); if (!$this->product->active) { self::$smarty->assign('adminActionDisplay', true); } /* Product pictures management */ require_once 'images.inc.php'; if ($this->product->customizable) { self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { $this->pictureUpload($this->product, $cart); $this->textRecord($this->product, $cart); $this->formTargetFormat(); } elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) { $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture'); } $files = self::$cookie->getFamily('pictures_' . (int) $this->product->id); $textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id); foreach ($textFields as $key => $textField) { $textFields[$key] = str_replace('<br />', "\n", $textField); } self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields)); } /* Features / Values */ $features = $this->product->getFrontFeatures((int) self::$cookie->id_lang); $attachments = $this->product->cache_has_attachments ? $this->product->getAttachments((int) self::$cookie->id_lang) : array(); /* Category */ $category = false; if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) and is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) { $category = new Category((int) $regs[2], (int) self::$cookie->id_lang); } } elseif (isset($regs[5]) and is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) { $category = new Category((int) $regs[5], (int) self::$cookie->id_lang); } } } if (!$category) { $category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang); } if (isset($category) and Validate::isLoadedObject($category)) { self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name))); } else { self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name)); } self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();'); if (Pack::isPack((int) $this->product->id) and !Pack::isInStock((int) $this->product->id)) { $this->product->quantity = 0; } $group_reduction = (100 - Group::getReduction((int) self::$cookie->id_customer)) / 100; $id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0; $id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_; $id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT')); // Tax $tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); self::$smarty->assign('tax_rate', $tax); $productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6); if (Product::$_taxCalculationMethod == PS_TAX_INC) { $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2); } $productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax); $ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2); if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) { $ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2); } self::$smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int) $this->product->id, (int) Shop::getCurrentShop(), (int) self::$cookie->id_currency, $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (double) $tax), 'product' => $this->product, 'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'homeSize' => Image::getSize('home'), 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, self::$cookie->id_lang), 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => (double) $productPriceWithoutEcoTax, 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'group_reduction' => $group_reduction, 'col_img_dir' => _PS_COL_IMG_DIR_)); self::$smarty->assign(array('HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($this->product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent'))); $images = $this->product->getImages((int) self::$cookie->id_lang); $productImages = array(); foreach ($images as $k => $image) { if ($image['cover']) { self::$smarty->assign('mainImage', $images[0]); $cover = $image; $cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image']; $cover['id_image_only'] = (int) $image['id_image']; } $productImages[(int) $image['id_image']] = $image; } if (!isset($cover)) { $cover = array('id_image' => Language::getIsoById(self::$cookie->id_lang) . '-default', 'legend' => 'No picture', 'title' => 'No picture'); } $size = Image::getSize('large'); self::$smarty->assign(array('cover' => $cover, 'imgWidth' => (int) $size['width'], 'mediumSize' => Image::getSize('medium'), 'largeSize' => Image::getSize('large'), 'accessories' => $this->product->getAccessories((int) self::$cookie->id_lang))); if (count($productImages)) { self::$smarty->assign('images', $productImages); } /* Attributes / Groups & colors */ $colors = array(); $attributesGroups = $this->product->getAttributesGroups((int) self::$cookie->id_lang); // @todo (RM) should only get groups and not all declination ? if (is_array($attributesGroups) and $attributesGroups) { $groups = array(); $combinationImages = $this->product->getCombinationImages((int) self::$cookie->id_lang); foreach ($attributesGroups as $k => $row) { /* Color management */ if ((isset($row['attribute_color']) and $row['attribute_color'] or file_exists(_PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg')) and $row['id_attribute_group'] == $this->product->id_color_default) { $colors[$row['id_attribute']]['value'] = $row['attribute_color']; $colors[$row['id_attribute']]['name'] = $row['attribute_name']; if (!isset($colors[$row['id_attribute']]['attributes_quantity'])) { $colors[$row['id_attribute']]['attributes_quantity'] = 0; } $colors[$row['id_attribute']]['attributes_quantity'] += (int) $row['quantity']; } if (!isset($groups[$row['id_attribute_group']])) { $groups[$row['id_attribute_group']] = array('name' => $row['public_group_name'], 'is_color_group' => $row['is_color_group'], 'default' => -1); } $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name']; if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) { $groups[$row['id_attribute_group']]['default'] = (int) $row['id_attribute']; } if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) { $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0; } $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int) $row['quantity']; $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes'][] = (int) $row['id_attribute']; $combinations[$row['id_product_attribute']]['price'] = (double) $row['price']; $combinations[$row['id_product_attribute']]['ecotax'] = (double) $row['ecotax']; $combinations[$row['id_product_attribute']]['weight'] = (double) $row['weight']; $combinations[$row['id_product_attribute']]['quantity'] = (int) $row['quantity']; $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact']; $combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity']; $combinations[$row['id_product_attribute']]['id_image'] = isset($combinationImages[$row['id_product_attribute']][0]['id_image']) ? $combinationImages[$row['id_product_attribute']][0]['id_image'] : -1; } //wash attributes list (if some attributes are unavailables and if allowed to wash it) if (!Product::isAvailableWhenOutOfStock($this->product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) { foreach ($groups as &$group) { foreach ($group['attributes_quantity'] as $key => &$quantity) { if (!$quantity) { unset($group['attributes'][$key]); } } } foreach ($colors as $key => $color) { if (!$color['attributes_quantity']) { unset($colors[$key]); } } } foreach ($groups as &$group) { natcasesort($group['attributes']); } foreach ($combinations as $id_product_attribute => $comb) { $attributeList = ''; foreach ($comb['attributes'] as $id_attribute) { $attributeList .= '\'' . (int) $id_attribute . '\','; } $attributeList = rtrim($attributeList, ','); $combinations[$id_product_attribute]['list'] = $attributeList; } self::$smarty->assign(array('groups' => $groups, 'combinaisons' => $combinations, 'combinations' => $combinations, 'colors' => (sizeof($colors) and $this->product->id_color_default) ? $colors : false, 'combinationImages' => $combinationImages)); } self::$smarty->assign(array('no_tax' => Tax::excludeTaxeOption() or !Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), 'customizationFields' => $this->product->customizable ? $this->product->getCustomizationFields((int) self::$cookie->id_lang) : false)); // Pack management self::$smarty->assign('packItems', $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, (int) self::$cookie->id_lang, true) : array()); self::$smarty->assign('packs', Pack::getPacksTable($this->product->id, (int) self::$cookie->id_lang, true, 1)); } } self::$smarty->assign(array('ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'categories' => Category::getHomeCategories((int) self::$cookie->id_lang), 'have_image' => isset($cover) ? (int) $cover['id_image'] : false, 'tax_enabled' => Configuration::get('PS_TAX'), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'ecotax' => !sizeof($this->errors) and $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'currencySign' => $currency->sign, 'currencyRate' => $currency->conversion_rate, 'currencyFormat' => $currency->format, 'currencyBlank' => $currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'))); }
/** * @see StockManagerInterface::getProductRealQuantities() */ public function getProductRealQuantities($id_product, $id_product_attribute, $ids_warehouse = null, $usable = false) { if (!is_null($ids_warehouse)) { // in case $ids_warehouse is not an array if (!is_array($ids_warehouse)) { $ids_warehouse = array($ids_warehouse); } // casts for security reason $ids_warehouse = array_map('intval', $ids_warehouse); } $client_orders_qty = 0; // check if product is present in a pack if (!Pack::isPack($id_product) && ($in_pack = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('SELECT id_product_pack, quantity FROM ' . _DB_PREFIX_ . 'pack WHERE id_product_item = ' . (int) $id_product . ' AND id_product_attribute_item = ' . ($id_product_attribute ? (int) $id_product_attribute : '0')))) { foreach ($in_pack as $value) { if (Validate::isLoadedObject($product = new Product((int) $value['id_product_pack'])) && ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0)) { $query = new DbQuery(); $query->select('od.product_quantity, od.product_quantity_refunded, pk.quantity'); $query->from('order_detail', 'od'); $query->leftjoin('orders', 'o', 'o.id_order = od.id_order'); $query->where('od.product_id = ' . (int) $value['id_product_pack']); $query->leftJoin('order_history', 'oh', 'oh.id_order = o.id_order AND oh.id_order_state = o.current_state'); $query->leftJoin('order_state', 'os', 'os.id_order_state = oh.id_order_state'); $query->leftJoin('pack', 'pk', 'pk.id_product_item = ' . (int) $id_product . ' AND pk.id_product_attribute_item = ' . ($id_product_attribute ? (int) $id_product_attribute : '0') . ' AND id_product_pack = od.product_id'); $query->where('os.shipped != 1'); $query->where('o.valid = 1 OR (os.id_order_state != ' . (int) Configuration::get('PS_OS_ERROR') . ' AND os.id_order_state != ' . (int) Configuration::get('PS_OS_CANCELED') . ')'); $query->groupBy('od.id_order_detail'); if (count($ids_warehouse)) { $query->where('od.id_warehouse IN(' . implode(', ', $ids_warehouse) . ')'); } $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); if (count($res)) { foreach ($res as $row) { $client_orders_qty += ($row['product_quantity'] - $row['product_quantity_refunded']) * $row['quantity']; } } } } } // skip if product is a pack without if (!Pack::isPack($id_product) || (Pack::isPack($id_product) && Validate::isLoadedObject($product = new Product((int) $id_product)) && $product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2))) { // Gets client_orders_qty $query = new DbQuery(); $query->select('od.product_quantity, od.product_quantity_refunded'); $query->from('order_detail', 'od'); $query->leftjoin('orders', 'o', 'o.id_order = od.id_order'); $query->where('od.product_id = ' . (int) $id_product); if (0 != $id_product_attribute) { $query->where('od.product_attribute_id = ' . (int) $id_product_attribute); } $query->leftJoin('order_history', 'oh', 'oh.id_order = o.id_order AND oh.id_order_state = o.current_state'); $query->leftJoin('order_state', 'os', 'os.id_order_state = oh.id_order_state'); $query->where('os.shipped != 1'); $query->where('o.valid = 1 OR (os.id_order_state != ' . (int) Configuration::get('PS_OS_ERROR') . ' AND os.id_order_state != ' . (int) Configuration::get('PS_OS_CANCELED') . ')'); $query->groupBy('od.id_order_detail'); if (count($ids_warehouse)) { $query->where('od.id_warehouse IN(' . implode(', ', $ids_warehouse) . ')'); } $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); if (count($res)) { foreach ($res as $row) { $client_orders_qty += $row['product_quantity'] - $row['product_quantity_refunded']; } } } // Gets supply_orders_qty $query = new DbQuery(); $query->select('sod.quantity_expected, sod.quantity_received'); $query->from('supply_order', 'so'); $query->leftjoin('supply_order_detail', 'sod', 'sod.id_supply_order = so.id_supply_order'); $query->leftjoin('supply_order_state', 'sos', 'sos.id_supply_order_state = so.id_supply_order_state'); $query->where('sos.pending_receipt = 1'); $query->where('sod.id_product = ' . (int) $id_product . ' AND sod.id_product_attribute = ' . (int) $id_product_attribute); if (!is_null($ids_warehouse) && count($ids_warehouse)) { $query->where('so.id_warehouse IN(' . implode(', ', $ids_warehouse) . ')'); } $supply_orders_qties = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); $supply_orders_qty = 0; foreach ($supply_orders_qties as $qty) { if ($qty['quantity_expected'] > $qty['quantity_received']) { $supply_orders_qty += $qty['quantity_expected'] - $qty['quantity_received']; } } // Gets {physical OR usable}_qty $qty = $this->getProductPhysicalQuantities($id_product, $id_product_attribute, $ids_warehouse, $usable); //real qty = actual qty in stock - current client orders + current supply orders return $qty - $client_orders_qty + $supply_orders_qty; }
public function ajaxProcessProductQuantity() { if (!Tools::getValue('actionQty')) { return Tools::jsonEncode(array('error' => $this->l('Undefined action'))); } $product = new Product((int) Tools::getValue('id_product'), true); switch (Tools::getValue('actionQty')) { case 'depends_on_stock': if (Tools::getValue('value') === false) { die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); } if ((int) Tools::getValue('value') != 0 && (int) Tools::getValue('value') != 1) { die(Tools::jsonEncode(array('error' => $this->l('Incorrect value')))); } if (!$product->advanced_stock_management && (int) Tools::getValue('value') == 1) { die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. ')))); } if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) Tools::getValue('value') == 1 && (Pack::isPack($product->id) && !Pack::allUsesAdvancedStockManagement($product->id) && ($product->pack_stock_type == 2 || $product->pack_stock_type == 1 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)))) { die(Tools::jsonEncode(array('error' => $this->l('You cannot use advanced stock management for this pack because') . '</br>' . $this->l('- advanced stock management is not enabled for these products') . '</br>' . $this->l('- you have chosen to decrement products quantities.')))); } StockAvailable::setProductDependsOnStock($product->id, (int) Tools::getValue('value')); break; case 'pack_stock_type': $value = Tools::getValue('value'); if ($value === false) { die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); } if ((int) $value != 0 && (int) $value != 1 && (int) $value != 2 && (int) $value != 3) { die(Tools::jsonEncode(array('error' => $this->l('Incorrect value')))); } if ($product->depends_on_stock && !Pack::allUsesAdvancedStockManagement($product->id) && ((int) $value == 1 || (int) $value == 2 || (int) $value == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2))) { die(Tools::jsonEncode(array('error' => $this->l('You cannot use this stock management option because:') . '</br>' . $this->l('- advanced stock management is not enabled for these products') . '</br>' . $this->l('- advanced stock management is enabled for the pack')))); } Product::setPackStockType($product->id, $value); break; case 'out_of_stock': if (Tools::getValue('value') === false) { die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); } if (!in_array((int) Tools::getValue('value'), array(0, 1, 2))) { die(Tools::jsonEncode(array('error' => $this->l('Incorrect value')))); } StockAvailable::setProductOutOfStock($product->id, (int) Tools::getValue('value')); break; case 'set_qty': $value = Tools::getValue('value'); if ($value !== false) { $value = $product->normalizeQty(trim($value)); } if ($value === false || !is_numeric($value)) { die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); } if (Tools::getValue('id_product_attribute') === false) { die(Tools::jsonEncode(array('error' => $this->l('Undefined id product attribute')))); } StockAvailable::setQuantity($product->id, (int) Tools::getValue('id_product_attribute'), $value); Hook::exec('actionProductUpdate', array('id_product' => (int) $product->id, 'product' => $product)); // Catch potential echo from modules $error = ob_get_contents(); if (!empty($error)) { ob_end_clean(); die(Tools::jsonEncode(array('error' => $error))); } break; case 'advanced_stock_management': if (Tools::getValue('value') === false) { die(Tools::jsonEncode(array('error' => $this->l('Undefined value')))); } if ((int) Tools::getValue('value') != 1 && (int) Tools::getValue('value') != 0) { die(Tools::jsonEncode(array('error' => $this->l('Incorrect value')))); } if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) Tools::getValue('value') == 1) { die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. ')))); } $product->setAdvancedStockManagement((int) Tools::getValue('value')); if (StockAvailable::dependsOnStock($product->id) == 1 && (int) Tools::getValue('value') == 0) { StockAvailable::setProductDependsOnStock($product->id, 0); } break; } die(Tools::jsonEncode(array('error' => false))); }
/** * Is this product a pack? * * @param Product $product * @return boolean */ public function isPack($product) { return Pack::isPack($product->id); }
/** * Get the product type (simple, virtual, pack) * @since in 1.5.0 * * @return int */ public function getType() { if (!$this->id) { return Product::PTYPE_SIMPLE; } if (Pack::isPack($this->id)) { return Product::PTYPE_PACK; } if ($this->is_virtual) { return Product::PTYPE_VIRTUAL; } return Product::PTYPE_SIMPLE; }
public function process() { global $cart, $currency; parent::process(); if (!($id_product = (int) Tools::getValue('id_product')) or !Validate::isUnsignedId($id_product)) { $this->errors[] = Tools::displayError('Product not found'); } else { if (!Validate::isLoadedObject($this->product) or !$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) { header('HTTP/1.1 404 page not found'); $this->errors[] = Tools::displayError('Product is no longer available.'); } elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) { $this->errors[] = Tools::displayError('You do not have access to this product.'); } else { self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id)); if (!$this->product->active) { self::$smarty->assign('adminActionDisplay', true); } /* rewrited url set */ $rewrited_url = self::$link->getProductLink($this->product->id, $this->product->link_rewrite); /* Product pictures management */ require_once 'images.inc.php'; self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { $this->pictureUpload($this->product, $cart); $this->textRecord($this->product, $cart); $this->formTargetFormat(); } elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) { $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture'); } $files = self::$cookie->getFamily('pictures_' . (int) $this->product->id); $textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id); foreach ($textFields as $key => $textField) { $textFields[$key] = str_replace('<br />', "\n", $textField); } self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields)); if ((int) Tools::getValue('pp') == 1) { echo 'here1'; } $productPriceWithTax = Product::getPriceStatic($id_product, true, NULL, 6); if (Product::$_taxCalculationMethod == PS_TAX_INC) { $productPriceWithTax = Tools::ps_round($productPriceWithTax, 2); } if ((int) Tools::getValue('pp') == 1) { $time2 = time(); echo 'time2: ' . $time2; } $productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax); $configs = Configuration::getMultiple(array('PS_ORDER_OUT_OF_STOCK', 'PS_LAST_QTIES')); /* Features / Values */ $features = $this->product->getFrontFeatures((int) self::$cookie->id_lang); $attachments = $this->product->getAttachments((int) self::$cookie->id_lang); /* Category */ $category = false; if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) { if (isset($regs[2]) and is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) { $category = new Category((int) $regs[2], (int) self::$cookie->id_lang); } } elseif (isset($regs[5]) and is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) { $category = new Category((int) $regs[5], (int) self::$cookie->id_lang); } } } if (!$category) { $category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang); } if (isset($category) and Validate::isLoadedObject($category)) { self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name))); } else { self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name)); } self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();'); $lang = Configuration::get('PS_LANG_DEFAULT'); if (Pack::isPack((int) $this->product->id, (int) $lang) and !Pack::isInStock((int) $this->product->id, (int) $lang)) { $this->product->quantity = 0; } $group_reduction = (100 - Group::getReduction((int) self::$cookie->id_customer)) / 100; $id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0; $id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_; $id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT')); if ((int) Tools::getValue('pp') == 1) { $time3 = time(); echo 'time3: ' . $time3; } // Tax $tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); self::$smarty->assign('tax_rate', $tax); $ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2); if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) { $ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2); } $manufacturer = new Manufacturer((int) $this->product->id_manufacturer, 1); $sizechart = new Sizechart((int) $this->product->id_sizechart, 1); //see if the product is already in the wishlist if ($id_customer) { $sql = "select id from ps_wishlist where id_customer = " . $id_customer . " and id_product = " . $this->product->id; $res = Db::getInstance()->ExecuteS($sql); if ($res) { self::$smarty->assign("in_wishlist", true); } else { self::$smarty->assign("in_wishlist", false); } } else { self::$smarty->assign("in_wishlist", false); } self::$smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int) $this->product->id, (int) Shop::getCurrentShop(), (int) self::$cookie->id_currency, $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (double) $tax), 'product' => $this->product, 'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'homeSize' => Image::getSize('home'), 'product_manufacturer' => $manufacturer, 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => (double) $productPriceWithoutEcoTax, 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) $configs['PS_LAST_QTIES'], 'group_reduction' => $group_reduction, 'col_img_dir' => _PS_COL_IMG_DIR_, 'sizechart' => $sizechart->sizechart, 'sizechart_data' => $sizechart->sizechart_data)); self::$smarty->assign(array('HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($this->product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent'))); if ((int) Tools::getValue('pp') == 1) { $time4 = time(); echo 'time4: ' . $time4; } $images = $this->product->getImages((int) self::$cookie->id_lang); $productImages = array(); foreach ($images as $k => $image) { if ($image['cover']) { self::$smarty->assign('mainImage', $images[0]); $cover = $image; $cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image']; $cover['id_image_only'] = (int) $image['id_image']; } $productImages[(int) $image['id_image']] = $image; } if (!isset($cover)) { $cover = array('id_image' => Language::getIsoById(self::$cookie->id_lang) . '-default', 'legend' => 'No picture', 'title' => 'No picture'); } $size = Image::getSize('large'); self::$smarty->assign(array('cover' => $cover, 'imgWidth' => (int) $size['width'], 'mediumSize' => Image::getSize('medium'), 'largeSize' => Image::getSize('large'), 'accessories' => $this->product->getAccessories((int) self::$cookie->id_lang))); if (sizeof($productImages)) { self::$smarty->assign('images', $productImages); } if ((int) Tools::getValue('pp') == 1) { $time5 = time(); echo 'time5: ' . $time5; } /* Attributes / Groups & colors */ $colors = array(); //see if the product has shades if ($this->product->id_group && $this->product->id_group > 0) { global $link; $related_productIds = $this->product->getRelatedProducts(); $related_products = array(); foreach ($related_productIds as &$productId) { $relProduct = new Product((int) $productId['id_product'], true, self::$cookie->id_lang); $idImage = $relProduct->getCoverWs(); if ($idImage) { $idImage = $relProduct->id . '-' . $idImage; } else { $idImage = Language::getIsoById(1) . '-default'; } $relProduct->image_link = $link->getImageLink($relProduct->link_rewrite, $idImage, 'small'); $relProduct->link = $relProduct->getLink(); $related_products[] = $relProduct; } self::$smarty->assign('relatedProducts', $related_products); } if ((int) Tools::getValue('pp') == 1) { $time6 = time(); echo 'time6: ' . $time6; } $attributesGroups = $this->product->getAttributesGroups((int) self::$cookie->id_lang); // @todo (RM) should only get groups and not all declination ? if (is_array($attributesGroups) and $attributesGroups) { $groups = array(); $combinationImages = $this->product->getCombinationImages((int) self::$cookie->id_lang); foreach ($attributesGroups as $k => $row) { /* Color management */ if ((isset($row['attribute_color']) and $row['attribute_color'] or file_exists(_PS_COL_IMG_DIR_ . $row['id_attribute'] . '.jpg')) and $row['id_attribute_group'] == $this->product->id_color_default) { $colors[$row['id_attribute']]['value'] = $row['attribute_color']; $colors[$row['id_attribute']]['name'] = $row['attribute_name']; if (!isset($colors[$row['id_attribute']]['attributes_quantity'])) { $colors[$row['id_attribute']]['attributes_quantity'] = 0; } $colors[$row['id_attribute']]['attributes_quantity'] += (int) $row['quantity']; } if (!isset($groups[$row['id_attribute_group']])) { $groups[$row['id_attribute_group']] = array('name' => $row['public_group_name'], 'is_color_group' => $row['is_color_group'], 'default' => -1); } $groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = $row['attribute_name']; if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) { $groups[$row['id_attribute_group']]['default'] = (int) $row['id_attribute']; } if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) { $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0; } $groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int) $row['quantity']; $combinations[$row['id_product_attribute']]['attributes_values'][$row['id_attribute_group']] = $row['attribute_name']; $combinations[$row['id_product_attribute']]['attributes'][] = (int) $row['id_attribute']; $combinations[$row['id_product_attribute']]['price'] = (double) $row['price']; $combinations[$row['id_product_attribute']]['ecotax'] = (double) $row['ecotax']; $combinations[$row['id_product_attribute']]['weight'] = (double) $row['weight']; $combinations[$row['id_product_attribute']]['quantity'] = (int) $row['quantity']; $combinations[$row['id_product_attribute']]['reference'] = $row['reference']; $combinations[$row['id_product_attribute']]['unit_impact'] = $row['unit_price_impact']; $combinations[$row['id_product_attribute']]['minimal_quantity'] = $row['minimal_quantity']; $combinations[$row['id_product_attribute']]['id_image'] = isset($combinationImages[$row['id_product_attribute']][0]['id_image']) ? $combinationImages[$row['id_product_attribute']][0]['id_image'] : -1; } if ((int) Tools::getValue('pp') == 1) { $time7 = time(); echo 'time7: ' . $time7; } //wash attributes list (if some attributes are unavailables and if allowed to wash it) if (!Product::isAvailableWhenOutOfStock($this->product->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) { foreach ($groups as &$group) { foreach ($group['attributes_quantity'] as $key => &$quantity) { if (!$quantity) { unset($group['attributes'][$key]); } } } foreach ($colors as $key => $color) { if (!$color['attributes_quantity']) { unset($colors[$key]); } } } if ((int) Tools::getValue('pp') == 1) { $time71 = time(); echo 'time71: ' . $time71; } foreach ($groups as &$group) { natcasesort($group['attributes']); } foreach ($combinations as $id_product_attribute => $comb) { $attributeList = ''; foreach ($comb['attributes'] as $id_attribute) { $attributeList .= '\'' . (int) $id_attribute . '\','; } $attributeList = rtrim($attributeList, ','); $combinations[$id_product_attribute]['list'] = $attributeList; } self::$smarty->assign(array('groups' => $groups, 'combinaisons' => $combinations, 'combinations' => $combinations, 'colors' => (sizeof($colors) and $this->product->id_color_default) ? $colors : false, 'combinationImages' => $combinationImages)); } if ((int) Tools::getValue('pp') == 1) { $time72 = time(); echo 'time72: ' . $time72; } //$newProducts = Product::getNewProducts((int)(self::$cookie->id_lang), 0, 10, false, 'date_add', 'desc'); /*$categoryProducts = $this->getRandomCatProducts(); self::$smarty->assign('cat_products', $categoryProducts);*/ //$brandProducts = $this->getRandomBrandProducts(); //self::$smarty->assign('brand_products', $brandProducts); if ((int) Tools::getValue('pp') == 1) { $time73 = time(); echo ' time73: ' . $time73; } self::$smarty->assign(array('no_tax' => Tax::excludeTaxeOption() or !Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), 'customizationFields' => $this->product->getCustomizationFields((int) self::$cookie->id_lang))); if ((int) Tools::getValue('pp') == 1) { $time74 = time(); echo 'time74: ' . $time74; } // Pack management self::$smarty->assign('packItems', $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, (int) self::$cookie->id_lang, true) : array()); self::$smarty->assign('packs', Pack::getPacksTable($this->product->id, (int) self::$cookie->id_lang, true, 1)); if ((int) Tools::getValue('pp') == 1) { print_r('pack done'); } } } if ((int) Tools::getValue('pp') == 1) { $time8 = time(); echo 'time8: ' . $time8; } if ($this->is_saree || $this->is_lehenga) { if ($this->is_lehenga) { self::$smarty->assign('is_lehenga', $this->is_lehenga); } self::$smarty->assign('as_shown', (bool) $this->product->as_shown); /*if($blouse_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 1)) self::$smarty->assign('measurement_info', $blouse_measurements); if($skirt_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 2)) self::$smarty->assign('skirt_measurement_info', $skirt_measurements);*/ if ((int) Tools::getValue('pp') == 1) { $time81 = time(); echo 'time81: ' . $time81; } if ($this->is_saree) { //count of all styles mapped to this product $res = Db::getInstance()->getRow("select count(s.id_style) as style_count from ps_styles s inner join ps_product_style ps on ps.id_style = s.id_style and ps.id_product = {$id_product} and s.style_type = 1"); $style_count = (int) $res['style_count']; if ($style_count === 0) { // show the default style for sarees $style = array('id_style' => 1, 'style_image_small' => '1-small.png', 'style_name' => 'Round'); } else { $res = Db::getInstance()->getRow("select s.id_style, s.style_name, s.style_image_small from ps_styles s inner join ps_product_style ps on ps.id_style = s.id_style and ps.id_product = {$id_product} and s.style_type = 1 and ps.is_default = 1"); if (!empty($res)) { //show the default style for this product $style = array('id_style' => $res['id_style'], 'style_image_small' => $res['style_image_small'], 'style_name' => $res['style_name']); } } if ((int) Tools::getValue('pp') == 1) { $time82 = time(); echo 'time82: ' . $time82; } self::$smarty->assign('blouse_style_count', $style_count); self::$smarty->assign('blouse_style', $style); } } else { if ($this->is_skd || $this->is_skd_rts) { self::$smarty->assign('is_anarkali', $this->is_anarkali); if ($this->is_anarkali) { if ($kurta_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 5)) { self::$smarty->assign('kurta_measurement_info', $kurta_measurements); } } else { if ($kurta_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 3)) { self::$smarty->assign('kurta_measurement_info', $kurta_measurements); } } if ($salwar_measurements = $this->getCustomerMeasurements(self::$cookie->id_customer, 4)) { self::$smarty->assign('salwar_measurement_info', $salwar_measurements); } //get default styles for this product (RTS) if ($this->is_skd_rts) { $res = Db::getInstance()->ExecuteS("select count(s.id_style) as style_count, s.style_type, ps.id_product from ps_styles s inner join ps_product_style ps on ps.id_style = s.id_style and ps.id_product = {$id_product} group by ps.id_product,s.style_type"); foreach ($res as $s) { $style_count = (int) $s['style_count']; if ((int) $s['style_type'] === 4) { self::$smarty->assign('kurta_style_count', $style_count); } else { if ((int) $s['style_type'] === 5) { self::$smarty->assign('salwar_style_count', $style_count); } } } $res = Db::getInstance()->ExecuteS("select s.id_style, s.style_type, s.style_image_small, s.style_name from ps_styles s inner join ps_product_style ps on ps.id_style = s.id_style and ps.id_product = {$id_product} and ps.is_default = 1"); foreach ($res as $s) { $style = array('id_style' => $s['id_style'], 'style_image_small' => $s['style_image_small'], 'style_name' => $s['style_name']); if ((int) $s['style_type'] === 4) { self::$smarty->assign('kurta_style', $style); } else { if ((int) $s['style_type'] === 5) { self::$smarty->assign('salwar_style', $style); } } } } } } self::$smarty->assign('is_bottoms', $this->is_bottoms); self::$smarty->assign('is_abaya', $this->is_abaya); self::$smarty->assign('is_wristwear', $this->is_wristwear); self::$smarty->assign('is_pakistani_rts', $this->is_pakistani_rts); if ((int) Tools::getValue('pp') == 1) { $time85 = time(); echo 'time85: ' . $time85; } self::$smarty->assign(array('ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'categories' => Category::getHomeCategories((int) self::$cookie->id_lang), 'have_image' => Product::getCover((int) Tools::getValue('id_product')), 'tax_enabled' => Configuration::get('PS_TAX'), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'ecotax' => !sizeof($this->errors) and $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'currencySign' => $currency->sign, 'currencyRate' => $currency->conversion_rate, 'currencyFormat' => $currency->format, 'currencyBlank' => $currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'))); if ((int) Tools::getValue('pp') == 1) { $time9 = time(); echo 'time9: ' . $time9; } //add this to product stats //Tools::captureActivity(PSTAT_VIEWS,$id_product); if ((int) Tools::getValue('pp') == 1) { $time1 = time(); echo 'process end: ' . $time1; } }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); if (!$this->errors) { $webservice_exi = new SoapClient('http://www2.promoshop.com.mx/ws_store/service.asmx?WSDL'); $parameter = array("ItemNumber" => $this->product->item_number, "key" => EXIMAGEN_KEY); $inventory = $webservice_exi->GetInventory($parameter); if (isset($inventory->GetInventoryResult->InventoryData->SKU)) { $inventory = $inventory->GetInventoryResult; } else { $inventory = $inventory->GetInventoryResult->InventoryData; } $quote_table = ""; $decoration_list = ''; $decoration = json_decode($this->product->decoration_details); if (!isset($decoration->areasimp->ItemNumber)) { $decoration = $decoration->areasimp; } foreach ($decoration as $deco) { $decoration_list .= $deco->TecnicaFull . ', '; } $decoration_list = substr($decoration_list, 0, -2); if ($this->product->quick_quote != '') { $quote = json_decode($this->product->quick_quote); //var_dump($this->product->quick_quote); foreach ($quote->PricesArray->Prices as $price) { $quote_table .= "<tr><td>" . $price->Piezas; $precio = explode('.', $price->Precio); $precio_imp = explode('.', $price->PrecioImp); if (intval($price->Piezas) < 10) { $quote_table .= " Muestra"; } else { $quote_table .= " Piezas"; } $quote_table .= "</td>"; $quote_table .= "<td>\$" . $precio[0] . "." . substr($precio[1], 0, 2) . "</td>"; $quote_table .= "<td>\$" . $precio_imp[0] . "." . substr($precio_imp[1], 0, 2) . "</td></tr>"; } } $link = new Link(); $productUrl = $link->getProductLink($this->product); $margin = Configuration::get('PROFIT_MARGIN'); $price_type = Configuration::get('PRODUCT_DYNAMIC_PRICE'); if (isset($margin) && $price_type == 1) { $margin = floatval($margin) / 100; $margin = 1 - $margin; $this->product->base_price = $this->product->base_price / $margin; } if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) { $this->product->quantity = 0; } $this->product->description = $this->transformDescriptionWithImg($this->product->description); // Assign to the template the id of the virtual product. "0" if the product is not downloadable. $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id)); $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { // If cart has not been saved, we need to do it so that customization fields can have an id_cart // We check that the cookie exists first to avoid ghost carts if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) { $this->context->cart->add(); $this->context->cookie->id_cart = (int) $this->context->cart->id; } $this->pictureUpload(); $this->textRecord(); $this->formTargetFormat(); } else { if (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) { $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.'); } } $pictures = array(); $text_fields = array(); if ($this->product->customizable) { $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true); foreach ($files as $file) { $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value']; } $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true); foreach ($texts as $text_field) { $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']); } } $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields)); $this->product->customization_required = false; $customizationFields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false; if (is_array($customizationFields)) { foreach ($customizationFields as $customizationField) { if ($this->product->customization_required = $customizationField['required']) { break; } } } // Assign template vars related to the category + execute hooks related to the category $this->assignCategory(); // Assign template vars related to the price and tax $this->assignPriceAndTax(); // Assign template vars related to the images $this->assignImages(); // Assign attribute groups to the template $this->assignAttributesGroups(); // Assign attributes combinations to the template $this->assignAttributesCombinations(); // Pack management $pack_items = $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array(); $this->context->smarty->assign('packItems', $pack_items); $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1)); if (isset($this->category->id) && $this->category->id) { $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category)); } else { $return_link = 'javascript: history.back();'; } $this->context->smarty->assign(array('stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $customizationFields, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'HOOK_PRODUCT_FILE_CONTENT' => Hook::exec('productFileContent', array('product' => $this->product)), 'HOOK_PRODUCT_FILE' => Hook::exec('productFile', array('product' => $this->product)), 'HOOK_CUSTOM_QUOTE' => Hook::exec('displayProductcustomquote', array('product' => $this->product, 'customizationFields' => $customizationFields)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'quote_table_detail' => $quote_table, 'inventory' => $inventory, 'decoration_list' => $decoration_list, 'product_url' => $productUrl, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'))); } $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl'); }
/** * Assign template vars related to page content * @see FrontController::initContent() */ public function initContent() { parent::initContent(); if (!$this->errors) { if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) { $this->product->quantity = 0; } $this->product->description = $this->transformDescriptionWithImg($this->product->description); // Assign to the template the id of the virtual product. "0" if the product is not downloadable. $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id)); $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { // If cart has not been saved, we need to do it so that customization fields can have an id_cart // We check that the cookie exists first to avoid ghost carts if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) { $this->context->cart->add(); $this->context->cookie->id_cart = (int) $this->context->cart->id; } $this->pictureUpload(); $this->textRecord(); $this->formTargetFormat(); } elseif (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) { $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.'); } $pictures = array(); $text_fields = array(); if ($this->product->customizable) { $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true); foreach ($files as $file) { $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value']; } $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true); foreach ($texts as $text_field) { $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']); } } $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields)); $this->product->customization_required = false; $customization_fields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false; if (is_array($customization_fields)) { foreach ($customization_fields as $customization_field) { if ($this->product->customization_required = $customization_field['required']) { break; } } } // Assign template vars related to the category + execute hooks related to the category $this->assignCategory(); // Assign template vars related to the price and tax $this->assignPriceAndTax(); // Assign template vars related to the images $this->assignImages(); // Assign attribute groups to the template $this->assignAttributesGroups(); // Assign attributes combinations to the template $this->assignAttributesCombinations(); // Pack management $pack_items = Pack::isPack($this->product->id) ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array(); $this->context->smarty->assign('packItems', $pack_items); $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1)); if (isset($this->category->id) && $this->category->id) { $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category)); } else { $return_link = 'javascript: history.back();'; } $accessories = $this->product->getAccessories($this->context->language->id); if ($this->product->cache_is_pack || count($accessories)) { $this->context->controller->addCSS(_THEME_CSS_DIR_ . 'product_list.css'); } $this->context->smarty->assign(array('stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $customization_fields, 'accessories' => $accessories, 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE'))); } $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl'); }
} } elseif (isset($regs[5]) and is_numeric($regs[5])) { if (Product::idIsOnCategoryId(intval($product->id), array('0' => array('id_category' => intval($regs[5]))))) { $category = new Category(intval($regs[5]), intval($cookie->id_lang)); } } } if (!$category) { $category = new Category($product->id_category_default, intval($cookie->id_lang)); } if (isset($category) and Validate::isLoadedObject($category)) { $smarty->assign(array('category' => $category, 'subCategories' => $category->getSubCategories(intval($cookie->id_lang), true), 'id_category_current' => intval($category->id), 'id_category_parent' => intval($category->id_parent), 'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name)))); } $smarty->assign(array('return_link' => (isset($category->id) and $category->id) ? Tools::safeOutput($link->getCategoryLink($category)) : 'javascript: history.back();', 'path' => (isset($category->id) and $category->id) ? Tools::getFullPath(intval($category->id), $product->name) : Tools::getFullPath(intval($product->id_category_default), $product->name))); $lang = Configuration::get('PS_LANG_DEFAULT'); if (Pack::isPack(intval($product->id), intval($lang)) and !Pack::isInStock(intval($product->id), intval($lang))) { $product->quantity = 0; } /* /Quantity discount management */ $smarty->assign(array('quantity_discounts' => QuantityDiscount::getQuantityDiscounts(intval($product->id), $product->getPriceWithoutReduct()), 'product' => $product, 'homeSize' => Image::getSize('home'), 'jqZoomEnabled' => $jqZoomEnabled, 'product_manufacturer' => new Manufacturer(intval($product->id_manufacturer)), 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => floatval($productPriceWithoutEcoTax), 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $product->isAvailableWhenOutOfStock(intval($product->out_of_stock)), 'last_qties' => intval($configs['PS_LAST_QTIES']), 'group_reduction' => (100 - Group::getReduction(intval($cookie->id_customer))) / 100, 'col_img_dir' => _PS_COL_IMG_DIR_, 'HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent'))); $images = $product->getImages(intval($cookie->id_lang)); $productImages = array(); foreach ($images as $k => $image) { if ($image['cover']) { $smarty->assign('mainImage', $images[0]); $cover = $image; $cover['id_image'] = intval($product->id) . '-' . $cover['id_image']; $cover['id_image_only'] = intval($image['id_image']); } $productImages[intval($image['id_image'])] = $image; }
/** * Get products grouped by package and by addresses to be sent individualy (one package = one shipping cost). * * @return array array( * 0 => array( // First address * 0 => array( // First package * 'product_list' => array(...), * 'carrier_list' => array(...), * 'id_warehouse' => array(...), * ), * ), * ); * @todo Add avaibility check */ public function getPackageList($flush = false) { static $cache = array(); if (isset($cache[(int) $this->id . '_' . (int) $this->id_address_delivery]) && $cache[(int) $this->id . '_' . (int) $this->id_address_delivery] !== false && !$flush) { return $cache[(int) $this->id . '_' . (int) $this->id_address_delivery]; } $product_list = $this->getProducts(); // Step 1 : Get product informations (warehouse_list and carrier_list), count warehouse // Determine the best warehouse to determine the packages // For that we count the number of time we can use a warehouse for a specific delivery address $warehouse_count_by_address = array(); $warehouse_carrier_list = array(); $stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'); foreach ($product_list as &$product) { if ((int) $product['id_address_delivery'] == 0) { $product['id_address_delivery'] = (int) $this->id_address_delivery; } if (!isset($warehouse_count_by_address[$product['id_address_delivery']])) { $warehouse_count_by_address[$product['id_address_delivery']] = array(); } $product['warehouse_list'] = array(); if ($stock_management_active && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement((int) $product['id_product']))) { $warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute'], $this->id_shop); if (count($warehouse_list) == 0) { $warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']); } // Does the product is in stock ? // If yes, get only warehouse where the product is in stock $warehouse_in_stock = array(); $manager = StockManagerFactory::getManager(); foreach ($warehouse_list as $key => $warehouse) { $product_real_quantities = $manager->getProductRealQuantities($product['id_product'], $product['id_product_attribute'], array($warehouse['id_warehouse']), true); if ($product_real_quantities > 0 || Pack::isPack((int) $product['id_product'])) { $warehouse_in_stock[] = $warehouse; } } if (!empty($warehouse_in_stock)) { $warehouse_list = $warehouse_in_stock; $product['in_stock'] = true; } else { $product['in_stock'] = false; } } else { //simulate default warehouse $warehouse_list = array(0); $product['in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']) > 0; } foreach ($warehouse_list as $warehouse) { if (!isset($warehouse_carrier_list[$warehouse['id_warehouse']])) { $warehouse_object = new Warehouse($warehouse['id_warehouse']); $warehouse_carrier_list[$warehouse['id_warehouse']] = $warehouse_object->getCarriers(); } $product['warehouse_list'][] = $warehouse['id_warehouse']; if (!isset($warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']])) { $warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']] = 0; } $warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]++; } } unset($product); arsort($warehouse_count_by_address); // Step 2 : Group product by warehouse $grouped_by_warehouse = array(); foreach ($product_list as &$product) { if (!isset($grouped_by_warehouse[$product['id_address_delivery']])) { $grouped_by_warehouse[$product['id_address_delivery']] = array('in_stock' => array(), 'out_of_stock' => array()); } $product['carrier_list'] = array(); $id_warehouse = 0; foreach ($warehouse_count_by_address[$product['id_address_delivery']] as $id_war => $val) { if (in_array((int) $id_war, $product['warehouse_list'])) { $product['carrier_list'] = array_merge($product['carrier_list'], Carrier::getAvailableCarrierList(new Product($product['id_product']), $id_war, $product['id_address_delivery'], null, $this)); if (!$id_warehouse) { $id_warehouse = (int) $id_war; } } } if (!isset($grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse])) { $grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse] = array(); $grouped_by_warehouse[$product['id_address_delivery']]['out_of_stock'][$id_warehouse] = array(); } if (!$this->allow_seperated_package) { $key = 'in_stock'; } else { $key = $product['in_stock'] ? 'in_stock' : 'out_of_stock'; } if (empty($product['carrier_list'])) { $product['carrier_list'] = array(0); } $grouped_by_warehouse[$product['id_address_delivery']][$key][$id_warehouse][] = $product; } unset($product); // Step 3 : grouped product from grouped_by_warehouse by available carriers $grouped_by_carriers = array(); foreach ($grouped_by_warehouse as $id_address_delivery => $products_in_stock_list) { if (!isset($grouped_by_carriers[$id_address_delivery])) { $grouped_by_carriers[$id_address_delivery] = array('in_stock' => array(), 'out_of_stock' => array()); } foreach ($products_in_stock_list as $key => $warehouse_list) { if (!isset($grouped_by_carriers[$id_address_delivery][$key])) { $grouped_by_carriers[$id_address_delivery][$key] = array(); } foreach ($warehouse_list as $id_warehouse => $product_list) { if (!isset($grouped_by_carriers[$id_address_delivery][$key][$id_warehouse])) { $grouped_by_carriers[$id_address_delivery][$key][$id_warehouse] = array(); } foreach ($product_list as $product) { $package_carriers_key = implode(',', $product['carrier_list']); if (!isset($grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key])) { $grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key] = array('product_list' => array(), 'carrier_list' => $product['carrier_list'], 'warehouse_list' => $product['warehouse_list']); } $grouped_by_carriers[$id_address_delivery][$key][$id_warehouse][$package_carriers_key]['product_list'][] = $product; } } } } $package_list = array(); // Step 4 : merge product from grouped_by_carriers into $package to minimize the number of package foreach ($grouped_by_carriers as $id_address_delivery => $products_in_stock_list) { if (!isset($package_list[$id_address_delivery])) { $package_list[$id_address_delivery] = array('in_stock' => array(), 'out_of_stock' => array()); } foreach ($products_in_stock_list as $key => $warehouse_list) { if (!isset($package_list[$id_address_delivery][$key])) { $package_list[$id_address_delivery][$key] = array(); } // Count occurance of each carriers to minimize the number of packages $carrier_count = array(); foreach ($warehouse_list as $id_warehouse => $products_grouped_by_carriers) { foreach ($products_grouped_by_carriers as $data) { foreach ($data['carrier_list'] as $id_carrier) { if (!isset($carrier_count[$id_carrier])) { $carrier_count[$id_carrier] = 0; } $carrier_count[$id_carrier]++; } } } arsort($carrier_count); foreach ($warehouse_list as $id_warehouse => $products_grouped_by_carriers) { if (!isset($package_list[$id_address_delivery][$key][$id_warehouse])) { $package_list[$id_address_delivery][$key][$id_warehouse] = array(); } foreach ($products_grouped_by_carriers as $data) { foreach ($carrier_count as $id_carrier => $rate) { if (in_array($id_carrier, $data['carrier_list'])) { if (!isset($package_list[$id_address_delivery][$key][$id_warehouse][$id_carrier])) { $package_list[$id_address_delivery][$key][$id_warehouse][$id_carrier] = array('carrier_list' => $data['carrier_list'], 'warehouse_list' => $data['warehouse_list'], 'product_list' => array()); } $package_list[$id_address_delivery][$key][$id_warehouse][$id_carrier]['carrier_list'] = array_intersect($package_list[$id_address_delivery][$key][$id_warehouse][$id_carrier]['carrier_list'], $data['carrier_list']); $package_list[$id_address_delivery][$key][$id_warehouse][$id_carrier]['product_list'] = array_merge($package_list[$id_address_delivery][$key][$id_warehouse][$id_carrier]['product_list'], $data['product_list']); break; } } } } } } // Step 5 : Reduce depth of $package_list $final_package_list = array(); foreach ($package_list as $id_address_delivery => $products_in_stock_list) { if (!isset($final_package_list[$id_address_delivery])) { $final_package_list[$id_address_delivery] = array(); } foreach ($products_in_stock_list as $key => $warehouse_list) { foreach ($warehouse_list as $id_warehouse => $products_grouped_by_carriers) { foreach ($products_grouped_by_carriers as $data) { $final_package_list[$id_address_delivery][] = array('product_list' => $data['product_list'], 'carrier_list' => $data['carrier_list'], 'warehouse_list' => $data['warehouse_list'], 'id_warehouse' => $id_warehouse); } } } } $cache[(int) $this->id] = $final_package_list; return $final_package_list; }
/** * Initialize product controller * @see FrontController::init() */ public function init() { parent::init(); if ($id_product = (int) Tools::getValue('id_product')) { $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id); } if (!Validate::isLoadedObject($this->product)) { header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); } else { $this->canonicalRedirection(); } if (!Validate::isLoadedObject($this->product)) { $this->errors[] = Tools::displayError('Product not found'); } else { if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) { $this->product->quantity = 0; } $this->product->description = $this->transformDescriptionWithImg($this->product->description); /* * If the product is associated to the shop * and is active or not active but preview mode (need token + file_exists) * allow showing the product * In all the others cases => 404 "Product is no longer available" */ if (!$this->product->isAssociatedToShop() || !$this->product->active) { if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee'))) { // If the product is not active, it's the admin preview mode $this->context->smarty->assign('adminActionDisplay', true); } else { $this->context->smarty->assign('adminActionDisplay', false); if ($this->product->id_product_redirected == $this->product->id) { $this->product->redirect_type = '404'; } switch ($this->product->redirect_type) { case '301': header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '302': header('HTTP/1.1 302 Moved Temporarily'); header('Cache-Control: no-cache'); header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected)); break; case '404': header('HTTP/1.1 404 Not Found'); header('Status: 404 Not Found'); $this->errors[] = Tools::displayError('Product is no longer available.'); break; } } } else { if (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) { header('HTTP/1.1 403 Forbidden'); header('Status: 403 Forbidden'); $this->errors[] = Tools::displayError('You do not have access to this product.'); } } // Load category if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs)) { // If the previous page was a category and is a parent category of the product use this category as parent category if (isset($regs[2]) && is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) { $this->category = new Category($regs[2], (int) $this->context->cookie->id_lang); } } else { if (isset($regs[5]) && is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) { $this->category = new Category($regs[5], (int) $this->context->cookie->id_lang); } } } } else { // Set default product category $this->category = new Category($this->product->id_category_default, (int) $this->context->cookie->id_lang); } } }
/** * For a given pack, returns the warehouse it can be shipped from * * @param int $id_product * @return int|bool id_warehouse or false */ public static function getPackWarehouses($id_product, $id_shop = null) { if (!Pack::isPack($id_product)) { return false; } if (is_null($id_shop)) { $id_shop = Context::getContext()->shop->id; } // warehouses of the pack $pack_warehouses = WarehouseProductLocation::getCollection((int) $id_product); // products in the pack $products = Pack::getItems((int) $id_product, Configuration::get('PS_LANG_DEFAULT')); // array with all warehouses id to check $list = array(); // fills $list foreach ($pack_warehouses as $pack_warehouse) { $list['pack_warehouses'][] = (int) $pack_warehouse->id_warehouse; } // for each products in the pack foreach ($products as $product) { if ($product->advanced_stock_management) { // gets the warehouses of one product $product_warehouses = Warehouse::getProductWarehouseList((int) $product->id, 0, (int) $id_shop); $list[(int) $product->id] = array(); // fills array with warehouses for this product foreach ($product_warehouses as $product_warehouse) { $list[(int) $product->id][] = $product_warehouse['id_warehouse']; } } } $res = false; // returns final list if (count($list) > 1) { $res = call_user_func_array('array_intersect', $list); } return $res; }
private function initiContentForInformation() { $vhafmkgxjva = "category_nbr"; $mvcrgvbvcb = "language"; $myqwjjy = "category_nbr"; $dutlbmuk = "categories"; ${$mvcrgvbvcb} = new Language($this->id_language); ${${"GLOBALS"}["jhyxxhuo"]} = file_exists(_PS_ROOT_DIR_ . "/js/tiny_mce/langs/" . $language->iso_code . ".js") ? $language->iso_code : "en"; ${"GLOBALS"}["gfbjkeb"] = "ad"; ${${"GLOBALS"}["kuvwml"]} = str_replace("\\", "\\\\", dirname($_SERVER["PHP_SELF"])); $crebbb = "categories"; $this->sellerinfo = new SellerInfo(SellerInfo::getIdByCustomerId(self::$cookie->id_customer), self::$cookie->id_lang); ${$dutlbmuk} = array(); ${$myqwjjy} = (int) Db::getInstance()->getValue("SELECT COUNT(*) AS cnt FROM " . _DB_PREFIX_ . "category"); if (${$vhafmkgxjva} <= 1000) { $kmgfuo = "specialcids"; ${"GLOBALS"}["uvadbayndxqr"] = "specialcids"; $uxpwiboxxa = "sql"; ${${"GLOBALS"}["vvskebgpewm"]} = "SELECT c.id_category, c.id_parent, cl.name \n\t\t\tFROM " . _DB_PREFIX_ . "category c \n\t\t\t\tINNER JOIN " . _DB_PREFIX_ . "category_owner co ON (c.id_category=co.id_category AND (IFNULL(co.id_owner,0)=0 OR IFNULL(co.id_owner,0)=" . intval($this->sellerinfo->id_seller) . "))\n\t\t\t\tLEFT JOIN " . _DB_PREFIX_ . "category_lang cl ON (c.id_category=cl.id_category AND cl.id_lang=" . $this->context->language->id . " AND cl.id_shop=" . $this->context->shop->id . ")\n\t\t\t\tWHERE c.id_category > 1\n\t\t\t\t"; $einijh = "specialcids"; ${"GLOBALS"}["wzpgiddtedw"] = "caterows"; ${$kmgfuo} = AgileMultipleSeller::getSpecialCatrgoryIds(); if (!empty(${${"GLOBALS"}["uvadbayndxqr"]})) { ${$uxpwiboxxa} .= " AND c.id_category NOT IN (" . ${$einijh} . ")"; } ${${"GLOBALS"}["gmagdrofuuu"]} = Db::getInstance()->ExecuteS(${${"GLOBALS"}["vvskebgpewm"]}); ${${"GLOBALS"}["kkajzqyo"]} = AgileHelper::getSortedFullnameCategory(${${"GLOBALS"}["wzpgiddtedw"]}); } $ohvjrmga = "HOOK_PRODYCT_LIST_OPTIONS"; ${$ohvjrmga} = ""; if (Module::isInstalled("agilesellerlistoptions")) { include_once _PS_ROOT_DIR_ . "/modules/agilesellerlistoptions/agilesellerlistoptions.php"; ${${"GLOBALS"}["nbpjcibnley"]} = new AgileSellerListOptions(); ${${"GLOBALS"}["kenogesux"]} = $aslo_module->hookAgileAdminProductsFormTop(array("for_front" => 1, "id_product" => $this->object->id), true); } $newCatFormat = $this->getNewCategoryFormat(); self::$smarty->assign(array("ad" => ${${"GLOBALS"}["gfbjkeb"]}, "isoTinyMCE" => ${${"GLOBALS"}["jhyxxhuo"]}, "theme_css_dir" => _THEME_CSS_DIR_, "ajaxurl" => _MODULE_DIR_, "suppliers" => Supplier::getSuppliers(), "manufacturers" => Manufacturer::getManufacturers(), "currency" => new Currency((int) Configuration::get("PS_CURRENCY_DEFAULT")), "ps_ssl_enabled" => Configuration::get("PS_SSL_ENABLED"), "is_pack" => $this->object->id && Pack::isPack($this->object->id) || Tools::getValue("ppack") || Tools::getValue("type_product") == Product::PTYPE_PACK, "categories" => ${$crebbb}, "new_categories" => $newCatFormat, "order_out_of_stock" => Configuration::get("PS_ORDER_OUT_OF_STOCK"), "bullet_common_field" => "", "is_agilesellerlistoptions_installed" => Module::isInstalled("agilesellerlistoptions"), "HOOK_PRODYCT_LIST_OPTIONS" => ${${"GLOBALS"}["kenogesux"]})); }
/** * For a given id_product and id_product_attribute updates the quantity available * * @param int $id_product * @param int $id_product_attribute Optional * @param int $delta_quantity The delta quantity to update * @param int $id_shop Optional */ public static function updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_shop = null) { if (!Validate::isUnsignedId($id_product)) { return false; } $id_stock_available = StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop); if (!$id_stock_available) { return false; } // Update quantity of the pack products if (Pack::isPack($id_product)) { $products_pack = Pack::getItems($id_product, (int) Configuration::get('PS_LANG_DEFAULT')); foreach ($products_pack as $product_pack) { $pack_id_product_attribute = Product::getDefaultAttribute($product_pack->id, 1); StockAvailable::updateQuantity($product_pack->id, $pack_id_product_attribute, $product_pack->pack_quantity * $delta_quantity, $id_shop); } } $stock_available = new StockAvailable($id_stock_available); $stock_available->quantity = $stock_available->quantity + $delta_quantity; $stock_available->update(); Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $stock_available->quantity)); }
/** * Sets the new state of the given order * * @param int $new_order_state * @param int $id_order * @param bool $use_existing_payment */ public function changeIdOrderState($new_order_state, &$id_order, $use_existing_payment = false) { if (!$new_order_state || !$id_order) { return; } if (!is_object($id_order) && is_numeric($id_order)) { $order = new Order((int) $id_order); } elseif (is_object($id_order)) { $order = $id_order; } else { return; } $new_os = new OrderState((int) $new_order_state, $order->id_lang); $old_os = $order->getCurrentOrderState(); $is_validated = $this->isValidated(); // executes hook if ($new_os->id == Configuration::get('PS_OS_PAYMENT')) { Hook::exec('actionPaymentConfirmation', array('id_order' => (int) $order->id)); } // executes hook Hook::exec('actionOrderStatusUpdate', array('newOrderStatus' => $new_os, 'id_order' => (int) $order->id)); if (Validate::isLoadedObject($order) && $old_os instanceof OrderState && $new_os instanceof OrderState) { // @since 1.5.0 : gets the stock manager $manager = null; if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $manager = StockManagerFactory::getManager(); } // foreach products of the order foreach ($order->getProductsDetail() as $product) { // if becoming logable => adds sale if ($new_os->logable && !$old_os->logable) { ProductSale::addProductSale($product['product_id'], $product['product_quantity']); // @since 1.5.0 - Stock Management if (!Pack::isPack($product['product_id']) && ($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')) && !StockAvailable::dependsOnStock($product['id_product'], (int) $order->id_shop)) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int) $product['product_quantity'], $order->id_shop); } } elseif (!$new_os->logable && $old_os->logable) { ProductSale::removeProductSale($product['product_id'], $product['product_quantity']); // @since 1.5.0 - Stock Management if (!Pack::isPack($product['product_id']) && ($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) && !StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int) $product['product_quantity'], $order->id_shop); } } elseif (!$new_os->logable && !$old_os->logable && ($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) && !StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int) $product['product_quantity'], $order->id_shop); } // @since 1.5.0 : if the order is being shipped and this products uses the advanced stock management : // decrements the physical stock using $id_warehouse if ($new_os->shipped == 1 && $old_os->shipped == 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && Warehouse::exists($product['id_warehouse']) && $manager != null && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id']))) { // gets the warehouse $warehouse = new Warehouse($product['id_warehouse']); // decrements the stock (if it's a pack, the StockManager does what is needed) $manager->removeProduct($product['product_id'], $product['product_attribute_id'], $warehouse, $product['product_quantity'], Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'), true, (int) $order->id); } elseif ($new_os->shipped == 0 && $old_os->shipped == 1 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && Warehouse::exists($product['id_warehouse']) && $manager != null && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id']))) { // if the product is a pack, we restock every products in the pack using the last negative stock mvts if (Pack::isPack($product['product_id'])) { $pack_products = Pack::getItems($product['product_id'], Configuration::get('PS_LANG_DEFAULT')); foreach ($pack_products as $pack_product) { if ($pack_product->advanced_stock_management == 1) { $mvts = StockMvt::getNegativeStockMvts($order->id, $pack_product->id, 0, $pack_product->pack_quantity * $product['product_quantity']); foreach ($mvts as $mvt) { $manager->addProduct($pack_product->id, 0, new Warehouse($mvt['id_warehouse']), $mvt['physical_quantity'], null, $mvt['price_te'], true); } if (!StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($pack_product->id, 0, (int) $pack_product->pack_quantity * $product['product_quantity'], $order->id_shop); } } } } else { $mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['product_quantity']); foreach ($mvts as $mvt) { $manager->addProduct($product['product_id'], $product['product_attribute_id'], new Warehouse($mvt['id_warehouse']), $mvt['physical_quantity'], null, $mvt['price_te'], true); } } } } } $this->id_order_state = (int) $new_order_state; // changes invoice number of order ? if (!Validate::isLoadedObject($new_os) || !Validate::isLoadedObject($order)) { die(Tools::displayError('Invalid new order state')); } // the order is valid if and only if the invoice is available and the order is not cancelled $order->current_state = $this->id_order_state; $order->valid = $new_os->logable; $order->update(); if ($new_os->invoice && !$order->invoice_number) { $order->setInvoice($use_existing_payment); } // set orders as paid if ($new_os->paid == 1) { $invoices = $order->getInvoicesCollection(); if ($order->total_paid != 0) { $payment_method = Module::getInstanceByName($order->module); } foreach ($invoices as $invoice) { $rest_paid = $invoice->getRestPaid(); if ($rest_paid > 0) { $payment = new OrderPayment(); $payment->order_reference = $order->reference; $payment->id_currency = $order->id_currency; $payment->amount = $rest_paid; if ($order->total_paid != 0) { $payment->payment_method = $payment_method->displayName; } else { $payment->payment_method = null; } // Update total_paid_real value for backward compatibility reasons if ($payment->id_currency == $order->id_currency) { $order->total_paid_real += $payment->amount; } else { $order->total_paid_real += Tools::ps_round(Tools::convertPrice($payment->amount, $payment->id_currency, false), 2); } $order->save(); $payment->conversion_rate = 1; $payment->save(); Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'order_invoice_payment` VALUES(' . (int) $invoice->id . ', ' . (int) $payment->id . ', ' . (int) $order->id . ')'); } } } // updates delivery date even if it was already set by another state change if ($new_os->delivery) { $order->setDelivery(); } // executes hook Hook::exec('actionOrderStatusPostUpdate', array('newOrderStatus' => $new_os, 'id_order' => (int) $order->id)); }
/** * For a given pack, tells if all products using the advanced stock management * * @param int $id_product id_pack * @return bool */ public static function allUsesAdvancedStockManagement($id_product) { if (!Pack::isPack($id_product)) { return false; } $products = Pack::getItems($id_product, Configuration::get('PS_LANG_DEFAULT')); foreach ($products as $product) { // if one product uses the advanced stock management if ($product->advanced_stock_management == 0) { return false; } } // not used return true; }
/** * Sets the new state of the given order * * @param int $new_order_state * @param int/object $id_order * @param bool $use_existing_payment */ public function changeIdOrderState($new_order_state, $id_order, $use_existing_payment = false) { if (!$new_order_state || !$id_order) { return; } if (!is_object($id_order) && is_numeric($id_order)) { $order = new Order((int) $id_order); } elseif (is_object($id_order)) { $order = $id_order; } else { return; } ShopUrl::cacheMainDomainForShop($order->id_shop); $new_os = new OrderState((int) $new_order_state, $order->id_lang); $old_os = $order->getCurrentOrderState(); $is_validated = $this->isValidated(); // executes hook if (in_array($new_os->id, array(Configuration::get('PS_OS_PAYMENT'), Configuration::get('PS_OS_WS_PAYMENT')))) { Hook::exec('actionPaymentConfirmation', array('id_order' => (int) $order->id), null, false, true, false, $order->id_shop); } // executes hook Hook::exec('actionOrderStatusUpdate', array('newOrderStatus' => $new_os, 'id_order' => (int) $order->id), null, false, true, false, $order->id_shop); if (Validate::isLoadedObject($order) && $new_os instanceof OrderState) { // An email is sent the first time a virtual item is validated $virtual_products = $order->getVirtualProducts(); if ($virtual_products && (!$old_os || !$old_os->logable) && $new_os && $new_os->logable) { $context = Context::getContext(); $assign = array(); foreach ($virtual_products as $key => $virtual_product) { $id_product_download = ProductDownload::getIdFromIdProduct($virtual_product['product_id']); $product_download = new ProductDownload($id_product_download); // If this virtual item has an associated file, we'll provide the link to download the file in the email if ($product_download->display_filename != '') { $assign[$key]['name'] = $product_download->display_filename; $dl_link = $product_download->getTextLink(false, $virtual_product['download_hash']) . '&id_order=' . (int) $order->id . '&secure_key=' . $order->secure_key; $assign[$key]['link'] = $dl_link; if (isset($virtual_product['download_deadline']) && $virtual_product['download_deadline'] != '0000-00-00 00:00:00') { $assign[$key]['deadline'] = Tools::displayDate($virtual_product['download_deadline']); } if ($product_download->nb_downloadable != 0) { $assign[$key]['downloadable'] = (int) $product_download->nb_downloadable; } } } $customer = new Customer((int) $order->id_customer); $links = '<ul>'; foreach ($assign as $product) { $links .= '<li>'; $links .= '<a href="' . $product['link'] . '">' . Tools::htmlentitiesUTF8($product['name']) . '</a>'; if (isset($product['deadline'])) { $links .= ' ' . Tools::htmlentitiesUTF8(Tools::displayError('expires on', false)) . ' ' . $product['deadline']; } if (isset($product['downloadable'])) { $links .= ' ' . Tools::htmlentitiesUTF8(sprintf(Tools::displayError('downloadable %d time(s)', false), (int) $product['downloadable'])); } $links .= '</li>'; } $links .= '</ul>'; $data = array('{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{id_order}' => (int) $order->id, '{order_name}' => $order->getUniqReference(), '{nbProducts}' => count($virtual_products), '{virtualProducts}' => $links); // If there's at least one downloadable file if (!empty($assign)) { Mail::Send((int) $order->id_lang, 'download_product', Mail::l('Virtual product to download', $order->id_lang), $data, $customer->email, $customer->firstname . ' ' . $customer->lastname, null, null, null, null, _PS_MAIL_DIR_, false, (int) $order->id_shop); } } // @since 1.5.0 : gets the stock manager $manager = null; if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $manager = StockManagerFactory::getManager(); } $errorOrCanceledStatuses = array(Configuration::get('PS_OS_ERROR'), Configuration::get('PS_OS_CANCELED')); // foreach products of the order if (Validate::isLoadedObject($old_os)) { foreach ($order->getProductsDetail() as $product) { // if becoming logable => adds sale if ($new_os->logable && !$old_os->logable) { ProductSale::addProductSale($product['product_id'], $product['product_quantity']); // @since 1.5.0 - Stock Management if (!Pack::isPack($product['product_id']) && in_array($old_os->id, $errorOrCanceledStatuses) && !StockAvailable::dependsOnStock($product['id_product'], (int) $order->id_shop)) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int) $product['product_quantity'], $order->id_shop); } } elseif (!$new_os->logable && $old_os->logable) { ProductSale::removeProductSale($product['product_id'], $product['product_quantity']); // @since 1.5.0 - Stock Management if (!Pack::isPack($product['product_id']) && in_array($new_os->id, $errorOrCanceledStatuses) && !StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int) $product['product_quantity'], $order->id_shop); } } elseif (!$new_os->logable && !$old_os->logable && in_array($new_os->id, $errorOrCanceledStatuses) && !in_array($old_os->id, $errorOrCanceledStatuses) && !StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int) $product['product_quantity'], $order->id_shop); } // @since 1.5.0 : if the order is being shipped and this products uses the advanced stock management : // decrements the physical stock using $id_warehouse if ($new_os->shipped == 1 && $old_os->shipped == 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && Warehouse::exists($product['id_warehouse']) && $manager != null && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id']))) { // gets the warehouse $warehouse = new Warehouse($product['id_warehouse']); // decrements the stock (if it's a pack, the StockManager does what is needed) $manager->removeProduct($product['product_id'], $product['product_attribute_id'], $warehouse, $product['product_quantity'], Configuration::get('PS_STOCK_CUSTOMER_ORDER_REASON'), true, (int) $order->id); } elseif ($new_os->shipped == 0 && $old_os->shipped == 1 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && Warehouse::exists($product['id_warehouse']) && $manager != null && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement($product['product_id']))) { // if the product is a pack, we restock every products in the pack using the last negative stock mvts if (Pack::isPack($product['product_id'])) { $pack_products = Pack::getItems($product['product_id'], Configuration::get('PS_LANG_DEFAULT', null, null, $order->id_shop)); foreach ($pack_products as $pack_product) { if ($pack_product->advanced_stock_management == 1) { $mvts = StockMvt::getNegativeStockMvts($order->id, $pack_product->id, 0, $pack_product->pack_quantity * $product['product_quantity']); foreach ($mvts as $mvt) { $manager->addProduct($pack_product->id, 0, new Warehouse($mvt['id_warehouse']), $mvt['physical_quantity'], null, $mvt['price_te'], true); } if (!StockAvailable::dependsOnStock($product['id_product'])) { StockAvailable::updateQuantity($pack_product->id, 0, (int) $pack_product->pack_quantity * $product['product_quantity'], $order->id_shop); } } } } else { $mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['product_quantity']); foreach ($mvts as $mvt) { $manager->addProduct($product['product_id'], $product['product_attribute_id'], new Warehouse($mvt['id_warehouse']), $mvt['physical_quantity'], null, $mvt['price_te'], true); } } } } } } $this->id_order_state = (int) $new_order_state; // changes invoice number of order ? if (!Validate::isLoadedObject($new_os) || !Validate::isLoadedObject($order)) { die(Tools::displayError('Invalid new order state')); } // the order is valid if and only if the invoice is available and the order is not cancelled $order->current_state = $this->id_order_state; $order->valid = $new_os->logable; $order->update(); if ($new_os->invoice && !$order->invoice_number) { $order->setInvoice($use_existing_payment); } // set orders as paid if ($new_os->paid == 1) { $invoices = $order->getInvoicesCollection(); if ($order->total_paid != 0) { $payment_method = Module::getInstanceByName($order->module); } foreach ($invoices as $invoice) { $rest_paid = $invoice->getRestPaid(); if ($rest_paid > 0) { $payment = new OrderPayment(); $payment->order_reference = $order->reference; $payment->id_currency = $order->id_currency; $payment->amount = $rest_paid; if ($order->total_paid != 0) { $payment->payment_method = $payment_method->displayName; } else { $payment->payment_method = null; } // Update total_paid_real value for backward compatibility reasons if ($payment->id_currency == $order->id_currency) { $order->total_paid_real += $payment->amount; } else { $order->total_paid_real += Tools::ps_round(Tools::convertPrice($payment->amount, $payment->id_currency, false), 2); } $order->save(); $payment->conversion_rate = 1; $payment->save(); Db::getInstance()->execute(' INSERT INTO `' . _DB_PREFIX_ . 'order_invoice_payment` VALUES(' . (int) $invoice->id . ', ' . (int) $payment->id . ', ' . (int) $order->id . ')'); } } } // updates delivery date even if it was already set by another state change if ($new_os->delivery) { $order->setDelivery(); } // executes hook Hook::exec('actionOrderStatusPostUpdate', array('newOrderStatus' => $new_os, 'id_order' => (int) $order->id), null, false, true, false, $order->id_shop); ShopUrl::resetMainDomainCache(); }