protected function generateProductsData() { $delimiter = ';'; $titles = array(); $id_lang = $this->use_lang; $new_path = new Sampledatainstall(); $f = fopen($new_path->sendPath() . 'output/products.vsc', 'w'); foreach ($this->product_fields as $field => $array) { $titles[] = $array['label']; } fputcsv($f, $titles, $delimiter, '"'); $products = Product::getProducts($id_lang, 0, 0, 'id_product', 'ASC', false, true); foreach ($products as $product) { $line = array(); $p = new Product($product['id_product'], true, $id_lang, 1); foreach ($this->product_fields as $field => $array) { $line[$field] = property_exists('Product', $field) && !is_array($p->{$field}) && !Tools::isEmpty($p->{$field}) ? $p->{$field} : ''; } $cats = $p->getProductCategoriesFull($p->id, 1); $cat_array = array(); foreach ($cats as $cat) { $cat_array[] = $cat['id_category']; } $line['categories'] = implode(',', $cat_array); $line['price_tex'] = $p->getPrice(false); $line['price_tin'] = $p->getPrice(true); $line['upc'] = $p->upc ? $p->upc : ''; $line['features'] = ''; $features = $p->getFrontFeatures($id_lang); $position = 1; $devider = ''; foreach ($features as $feature) { $sql = 'SELECT `id_feature` FROM ' . _DB_PREFIX_ . 'feature_lang WHERE `name` = "' . pSql($feature['name']) . '"'; $sql1 = 'SELECT `id_feature_value` FROM ' . _DB_PREFIX_ . 'feature_value_lang WHERE `value` = "' . pSql($feature['value']) . '"'; $id_feature = Db::getInstance()->getValue($sql); $id_feature_value = Db::getInstance()->getValue($sql1); $line['features'] .= $devider . $id_feature . ':' . $id_feature_value . ':' . $position; $devider = ','; $position++; } $specificPrice = SpecificPrice::getSpecificPrice($p->id, 1, 0, 0, 0, 0); $line['reduction_price'] = ''; $line['reduction_percent'] = ''; $line['reduction_from'] = ''; $line['reduction_to'] = ''; if ($specificPrice) { if ($specificPrice['reduction_type'] == 'amount') { $line['reduction_price'] = $specificPrice['reduction']; } elseif ($specificPrice['reduction_type'] == 'percent') { $line['reduction_percent'] = $specificPrice['reduction']; } if ($line['reduction_price'] !== '' || $line['reduction_percent'] !== '') { $line['reduction_from'] = $specificPrice['from']; $line['reduction_to'] = $specificPrice['to']; } } $tags = $p->getTags($id_lang); $line['tags'] = $tags; $link = new Link(); $imagelinks = array(); $images = $p->getImages($id_lang); foreach ($images as $image) { $imagelink = Tools::getShopProtocol() . $link->getImageLink($p->link_rewrite, $p->id . '-' . $image['id_image']); $this->copyConverFileName($imagelink); $imagelinks[] = $imagelink; } $line['image'] = implode(',', $imagelinks); $line['delete_existing_images'] = 0; $line['shop'] = 1; $warehouses = Warehouse::getWarehousesByProductId($p->id); $line['warehouse'] = ''; if (!empty($warehouses)) { $line['warehouse'] = implode(',', array_map("{$this->getWarehouses}", $warehouses)); } $values = array(); $accesories = $p->getAccessories($id_lang); if (isset($accesories) && $accesories && count($accesories)) { foreach ($accesories as $accesorie) { $values[] = $accesorie['id_product']; } } $line['accessories'] = $values ? implode(',', $values) : ''; $values = array(); $carriers = $p->getCarriers(); if (isset($carriers) && $carriers && count($carriers)) { foreach ($carriers as $carrier) { $values[] = $carrier['id_carrier']; } } $line['carriers'] = $values ? implode(',', $values) : ''; $values = array(); $customization_fields_ids = $p->getCustomizationFieldIds(); if (class_exists('CustomizationField') && isset($customization_fields_ids) && $customization_fields_ids && count($customization_fields_ids)) { foreach ($customization_fields_ids as $customization_field_id) { $cf = new CustomizationField($customization_field_id['id_customization_field'], $this->use_lang); $values[] = $cf->id . ':' . $cf->type . ':' . $cf->required . ':' . $cf->name; } } $line['customization_fields_ids'] = $values ? implode(',', $values) : ''; $values = array(); $attachments = $p->getAttachments($this->use_lang); if (isset($attachments) && $attachments && count($attachments)) { foreach ($attachments as $attachment) { $values[] = $attachment['id_attachment']; } } $line['attachments'] = $values ? implode(',', $values) : ''; if (!property_exists('Product', 'base_price')) { // for versions < 1.6.0.13 $line['base_price'] = !is_array($p->base_price) && !Tools::isEmpty($p->base_price) ? $p->base_price : ''; } if (!$line[$field]) { $line[$field] = ''; } fputcsv($f, $line, $delimiter, '"'); } fclose($f); }
public function delete() { if (!parent::delete()) { return false; } // Removes the product from StockAvailable, for the current shop StockAvailable::removeProductFromStockAvailable((int) $this->id_product, (int) $this->id); if ($specific_prices = SpecificPrice::getByProductId((int) $this->id_product, (int) $this->id)) { foreach ($specific_prices as $specific_price) { $price = new SpecificPrice((int) $specific_price['id_specific_price']); $price->delete(); } } if (!$this->hasMultishopEntries() && !$this->deleteAssociations()) { return false; } return true; }
public function add($autodate = true, $null_values = true) { $cart = new Cart($this->id_cart); Hook::exec('actionBeforeAddOrder', array('order' => $this, 'cart' => $cart)); if (ObjectModel::add($autodate, $null_values)) { return SpecificPrice::deleteByIdCart($this->id_cart); } return false; }
public function delete() { if (!parent::delete()) { return false; } // Removes the product from StockAvailable, for the current shop StockAvailable::removeProductFromStockAvailable((int) $this->id_product, (int) $this->id); if ($specific_prices = SpecificPrice::getByProductId((int) $this->id_product, (int) $this->id)) { foreach ($specific_prices as $specific_price) { $price = new SpecificPrice((int) $specific_price['id_specific_price']); $price->delete(); } } if (!$this->hasMultishopEntries() && !$this->deleteAssociations()) { return false; } $this->deleteFromSupplier($this->id_product); Product::updateDefaultAttribute($this->id_product); Tools::clearColorListCache((int) $this->id_product); return true; }
function updateSellingPrice(&$price) { if ($specificprice = SpecificPrice::filter($this->owner->SpecificPrices()->filter("Price:LessThan", $price), Member::currentUser())->first()) { if ($specificprice->Price > 0) { $price = $specificprice->Price; } elseif ($specificprice->DiscountPercent > 0) { $price *= 1.0 - $specificprice->DiscountPercent; } else { // this would mean both discount and price were 0 $price = 0; } } }
/** * Assign price and tax to the template */ protected function assignPriceAndTax() { die('coucou'); $id_customer = isset($this->context->customer) ? (int) $this->context->customer->id : 0; $id_group = (int) Group::getCurrent()->id; $id_country = $id_customer ? (int) Customer::getCurrentCountry($id_customer) : (int) Tools::getCountry(); $group_reduction = GroupReduction::getValueForProduct($this->product->id, $id_group); if ($group_reduction === false) { $group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100; } // Tax $tax = (double) $this->product->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $this->context->smarty->assign('tax_rate', $tax); $product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6) * 10; if (Product::$_taxCalculationMethod == PS_TAX_INC) { $product_price_with_tax = Tools::ps_round($product_price_with_tax, 2); } $product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax; $ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ecotax_tax_amount = Tools::ps_round($this->product->ecotax, 2); if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) { $ecotax_tax_amount = Tools::ps_round($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2); } $id_currency = (int) $this->context->cookie->id_currency; $id_product = (int) $this->product->id; $id_shop = $this->context->shop->id; $quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true, (int) $this->context->customer->id); foreach ($quantity_discounts as &$quantity_discount) { if ($quantity_discount['id_product_attribute']) { $combination = new Combination((int) $quantity_discount['id_product_attribute']); $attributes = $combination->getAttributesName((int) $this->context->language->id); foreach ($attributes as $attribute) { $quantity_discount['attributes'] = $attribute['name'] . ' - '; } $quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - '); } if ((int) $quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') { $quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency); } } $product_price = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false) * 10; $address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $this->context->smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $ecotax_tax_amount), 'ecotax_tax_inc' => $ecotax_tax_amount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'productPriceWithoutEcoTax' => (double) $product_price_without_eco_tax, 'group_reduction' => $group_reduction, 'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address), 'ecotax' => !count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'tax_enabled' => Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'), 'customer_group_without_tax' => Group::getPriceDisplayMethod($this->context->customer->id_default_group))); }
public static function getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_product_attribute = null, $all_combinations = false, $id_customer = 0) { if (!SpecificPrice::isFeatureActive()) { return array(); } $now = date('Y-m-d H:i:s'); $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT *, ' . SpecificPrice::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_customer) . ' FROM `' . _DB_PREFIX_ . 'specific_price` WHERE `id_product` IN(0, ' . (int) $id_product . ') AND ' . (!$all_combinations ? '`id_product_attribute` IN(0, ' . (int) $id_product_attribute . ') AND ' : '') . ' `id_shop` IN(0, ' . (int) $id_shop . ') AND `id_currency` IN(0, ' . (int) $id_currency . ') AND `id_country` IN(0, ' . (int) $id_country . ') AND `id_group` IN(0, ' . (int) $id_group . ') AND `id_customer` IN(0, ' . (int) $id_customer . ') AND ( (`from` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' >= `from`) AND (`to` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' <= `to`) ) ORDER BY `from_quantity` ASC, `id_specific_price_rule` ASC, `score` DESC '); $targeted_prices = array(); $last_quantity = array(); foreach ($res as $specific_price) { if (!isset($last_quantity[(int) $specific_price['id_product_attribute']])) { $last_quantity[(int) $specific_price['id_product_attribute']] = $specific_price['from_quantity']; } elseif ($last_quantity[(int) $specific_price['id_product_attribute']] == $specific_price['from_quantity']) { continue; } $last_quantity[(int) $specific_price['id_product_attribute']] = $specific_price['from_quantity']; if ($specific_price['from_quantity'] > PP::getSpecificPriceFromQty((int) $id_product)) { $targeted_prices[] = $specific_price; } } return $targeted_prices; }
public static function getQuantityDiscount($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute = null, $id_customer = 0) { $context = Context::getContext(); if ($context->customer->id) { $groups = array(); $customer_groups = Db::getInstance()->executeS("SELECT id_group FROM ps_customer_group WHERE id_customer={$context->customer->id}"); foreach ($customer_groups as $row_group) { $groups[] = $row_group['id_group']; } } else { $groups = array($id_group); } $groups = implode(',', $groups); if (!SpecificPrice::isFeatureActive()) { return array(); } $now = date('Y-m-d H:i:s'); $sql = ' SELECT *, ' . SpecificPrice::_getScoreQuery($id_product, $id_shop, $id_currency, $id_country, $id_group, $id_customer) . ' FROM `' . _DB_PREFIX_ . 'specific_price` WHERE `id_product` IN(0, ' . (int) $id_product . ') AND `id_product_attribute` IN(0, ' . (int) $id_product_attribute . ') AND `id_shop` IN(0, ' . (int) $id_shop . ') AND `id_currency` IN(0, ' . (int) $id_currency . ') AND `id_country` IN(0, ' . (int) $id_country . ') AND `id_group` IN(0, ' . $groups . ') AND `id_customer` IN(0, ' . (int) $id_customer . ') AND `from_quantity` >= ' . (int) $quantity . ' AND ( (`from` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' >= `from`) AND (`to` = \'0000-00-00 00:00:00\' OR \'' . $now . '\' <= `to`) ) ORDER BY `from_quantity` DESC, `score` DESC '; return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql); }
protected function setDetailProductPrice(Order $order, Cart $cart, $product) { $this->setContext((int) $product['id_shop']); $specific_price = $null = null; Product::getPriceStatic((int) $product['id_product'], true, (int) $product['id_product_attribute'], 6, null, false, true, array($product['cart_quantity'], $product['cart_quantity_fractional']), false, (int) $order->id_customer, (int) $order->id_cart, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $specific_price, true, true, $this->context); $this->specificPrice = $specific_price; $this->original_product_price = Product::getPriceStatic($product['id_product'], false, (int) $product['id_product_attribute'], 6, null, false, false, 1, false, null, null, null, $null, true, true, $this->context); $this->product_price = $this->original_product_price; $this->unit_price_tax_incl = (double) $product['price_wt']; $this->unit_price_tax_excl = (double) $product['price']; $this->total_price_tax_incl = (double) $product['total_wt']; $this->total_price_tax_excl = (double) $product['total']; $this->purchase_supplier_price = (double) $product['wholesale_price']; if ($product['id_supplier'] > 0 && ($supplier_price = ProductSupplier::getProductPrice((int) $product['id_supplier'], $product['id_product'], $product['id_product_attribute'], true)) > 0) { $this->purchase_supplier_price = (double) $supplier_price; } $this->setSpecificPrice($order, $product); $this->group_reduction = (double) Group::getReduction((int) $order->id_customer); $shop_id = $this->context->shop->id; $quantity_discount = SpecificPrice::getQuantityDiscount((int) $product['id_product'], $shop_id, (int) $cart->id_currency, (int) $this->vat_address->id_country, (int) $this->customer->id_default_group, (int) PP::resolveQty($product['cart_quantity'], $product['cart_quantity_fractional']), false, null, null, $null, true, true, $this->context); $unit_price = Product::getPriceStatic((int) $product['id_product'], true, $product['id_product_attribute'] ? (int) $product['id_product_attribute'] : null, 2, null, false, true, 1, false, (int) $order->id_customer, null, (int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}, $null, true, true, $this->context); $this->product_quantity_discount = 0.0; if ($quantity_discount) { $this->product_quantity_discount = $unit_price; if (Product::getTaxCalculationMethod((int) $order->id_customer) == PS_TAX_EXC) { $this->product_quantity_discount = Tools::ps_round($unit_price, 2); } if (isset($this->tax_calculator)) { $this->product_quantity_discount -= $this->tax_calculator->addTaxes($quantity_discount['price']); } } $this->discount_quantity_applied = $this->specificPrice && $this->specificPrice['from_quantity'] > PP::getSpecificPriceFromQty((int) $product['id_product']) ? 1 : 0; $this->id_cart_product = (int) $product['id_cart_product']; $this->product_quantity_fractional = (double) $product['cart_quantity_fractional']; $ppropertiessmartprice_hook3 = null; }
protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups) { $content = ''; if (!($obj = $this->loadObject())) { return; } $specific_prices = SpecificPrice::getByProductId((int) $obj->id); $specific_price_priorities = SpecificPrice::getPriority((int) $obj->id); $tax_rate = $obj->getTaxesRate(Address::initialize()); $tmp = array(); foreach ($shops as $shop) { $tmp[$shop['id_shop']] = $shop; } $shops = $tmp; $tmp = array(); foreach ($currencies as $currency) { $tmp[$currency['id_currency']] = $currency; } $currencies = $tmp; $tmp = array(); foreach ($countries as $country) { $tmp[$country['id_country']] = $country; } $countries = $tmp; $tmp = array(); foreach ($groups as $group) { $tmp[$group['id_group']] = $group; } $groups = $tmp; if (!is_array($specific_prices) || !count($specific_prices)) { $content .= ' <tr> <td class="text-center" colspan="13"><i class="icon-warning-sign"></i> ' . $this->l('No specific prices.') . '</td> </tr>'; } else { $i = 0; foreach ($specific_prices as $specific_price) { $current_specific_currency = $currencies[$specific_price['id_currency'] ? $specific_price['id_currency'] : $defaultCurrency->id]; if ($specific_price['reduction_type'] == 'percentage') { $impact = '- ' . $specific_price['reduction'] * 100 . ' %'; } elseif ($specific_price['reduction'] > 0) { $impact = '- ' . Tools::displayPrice(Tools::ps_round($specific_price['reduction'], 2), $current_specific_currency); } else { $impact = '--'; } if ($specific_price['from'] == '0000-00-00 00:00:00' && $specific_price['to'] == '0000-00-00 00:00:00') { $period = $this->l('Unlimited'); } else { $period = $this->l('From') . ' ' . ($specific_price['from'] != '0000-00-00 00:00:00' ? $specific_price['from'] : '0000-00-00 00:00:00') . '<br />' . $this->l('To') . ' ' . ($specific_price['to'] != '0000-00-00 00:00:00' ? $specific_price['to'] : '0000-00-00 00:00:00'); } if ($specific_price['id_product_attribute']) { $combination = new Combination((int) $specific_price['id_product_attribute']); $attributes = $combination->getAttributesName((int) $this->context->language->id); $attributes_name = ''; foreach ($attributes as $attribute) { $attributes_name .= $attribute['name'] . ' - '; } $attributes_name = rtrim($attributes_name, ' - '); } else { $attributes_name = $this->l('All combinations'); } $rule = new SpecificPriceRule((int) $specific_price['id_specific_price_rule']); $rule_name = $rule->id ? $rule->name : '--'; if ($specific_price['id_customer']) { $customer = new Customer((int) $specific_price['id_customer']); if (Validate::isLoadedObject($customer)) { $customer_full_name = $customer->firstname . ' ' . $customer->lastname; } unset($customer); } if (!$specific_price['id_shop'] || in_array($specific_price['id_shop'], Shop::getContextListShopID())) { $content .= ' <tr ' . ($i % 2 ? 'class="alt_row"' : '') . '> <td>' . $rule_name . '</td> <td>' . $attributes_name . '</td>'; $can_delete_specific_prices = true; if (Shop::isFeatureActive()) { $id_shop_sp = $specific_price['id_shop']; $can_delete_specific_prices = count($this->context->employee->getAssociatedShops()) > 1 && !$id_shop_sp || $id_shop_sp; $content .= ' <td>' . ($id_shop_sp ? $shops[$id_shop_sp]['name'] : $this->l('All shops')) . '</td>'; } $price = Tools::ps_round($specific_price['price'], 2); $fixed_price = $price == Tools::ps_round($obj->price, 2) || $specific_price['price'] == -1 ? '--' : Tools::displayPrice($price, $current_specific_currency); $content .= ' <td>' . ($specific_price['id_currency'] ? $currencies[$specific_price['id_currency']]['name'] : $this->l('All currencies')) . '</td> <td>' . ($specific_price['id_country'] ? $countries[$specific_price['id_country']]['name'] : $this->l('All countries')) . '</td> <td>' . ($specific_price['id_group'] ? $groups[$specific_price['id_group']]['name'] : $this->l('All groups')) . '</td> <td title="' . $this->l('ID:') . ' ' . $specific_price['id_customer'] . '">' . (isset($customer_full_name) ? $customer_full_name : $this->l('All customers')) . '</td> <td>' . $fixed_price . '</td> <td>' . $impact . '</td> <td>' . $period . '</td> <td>' . $specific_price['from_quantity'] . '</th> <td>' . (!$rule->id && $can_delete_specific_prices ? '<a class="btn btn-default" name="delete_link" href="' . self::$currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&action=deleteSpecificPrice&id_specific_price=' . (int) $specific_price['id_specific_price'] . '&token=' . Tools::getValue('token') . '"><i class="icon-trash"></i></a>' : '') . '</td> </tr>'; $i++; unset($customer_full_name); } } } $content .= ' </tbody> </table> </div> <div class="panel-footer"> <a href="' . $this->context->link->getAdminLink('AdminProducts') . '" class="btn btn-default"><i class="process-icon-cancel"></i> ' . $this->l('Cancel') . '</a> <button id="product_form_submit_btn" type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save') . '</button> <button id="product_form_submit_btn" type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save and stay') . '</button> </div> </div>'; $content .= ' <script type="text/javascript"> var currencies = new Array(); currencies[0] = new Array(); currencies[0]["sign"] = "' . $defaultCurrency->sign . '"; currencies[0]["format"] = ' . $defaultCurrency->format . '; '; foreach ($currencies as $currency) { $content .= ' currencies[' . $currency['id_currency'] . '] = new Array(); currencies[' . $currency['id_currency'] . ']["sign"] = "' . $currency['sign'] . '"; currencies[' . $currency['id_currency'] . ']["format"] = ' . $currency['format'] . '; '; } $content .= ' </script> '; // Not use id_customer if ($specific_price_priorities[0] == 'id_customer') { unset($specific_price_priorities[0]); } // Reindex array starting from 0 $specific_price_priorities = array_values($specific_price_priorities); $content .= '<div class="panel"> <h3>' . $this->l('Priority management') . '</h3> <div class="alert alert-info"> ' . $this->l('Sometimes one customer can fit into multiple price rules. Priorities allow you to define which rule applies to the customer.') . ' </div>'; $content .= ' <div class="form-group"> <label class="control-label col-lg-3" for="specificPricePriority1">' . $this->l('Priorities') . '</label> <div class="input-group col-lg-9"> <select id="specificPricePriority1" name="specificPricePriority[]"> <option value="id_shop"' . ($specific_price_priorities[0] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option> <option value="id_currency"' . ($specific_price_priorities[0] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specific_price_priorities[0] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specific_price_priorities[0] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> <span class="input-group-addon"><i class="icon-chevron-right"></i></span> <select name="specificPricePriority[]"> <option value="id_shop"' . ($specific_price_priorities[1] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option> <option value="id_currency"' . ($specific_price_priorities[1] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specific_price_priorities[1] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specific_price_priorities[1] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> <span class="input-group-addon"><i class="icon-chevron-right"></i></span> <select name="specificPricePriority[]"> <option value="id_shop"' . ($specific_price_priorities[2] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option> <option value="id_currency"' . ($specific_price_priorities[2] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specific_price_priorities[2] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specific_price_priorities[2] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> <span class="input-group-addon"><i class="icon-chevron-right"></i></span> <select name="specificPricePriority[]"> <option value="id_shop"' . ($specific_price_priorities[3] == 'id_shop' ? ' selected="selected"' : '') . '>' . $this->l('Shop') . '</option> <option value="id_currency"' . ($specific_price_priorities[3] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specific_price_priorities[3] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specific_price_priorities[3] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> </div> </div> <div class="form-group"> <div class="col-lg-9 col-lg-offset-3"> <p class="checkbox"> <label for="specificPricePriorityToAll"><input type="checkbox" name="specificPricePriorityToAll" id="specificPricePriorityToAll" />' . $this->l('Apply to all products') . '</label> </p> </div> </div> <div class="panel-footer"> <a href="' . $this->context->link->getAdminLink('AdminProducts') . '" class="btn btn-default"><i class="process-icon-cancel"></i> ' . $this->l('Cancel') . '</a> <button id="product_form_submit_btn" type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save') . '</button> <button id="product_form_submit_btn" type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> ' . $this->l('Save and stay') . '</button> </div> </div> '; return $content; }
public static function duplicateSpecificPrices($oldProductId, $productId) { foreach (SpecificPrice::getIdsByProductId((int) $oldProductId) as $data) { $specificPrice = new SpecificPrice((int) $data['id_specific_price']); if (!$specificPrice->duplicate((int) $productId)) { return false; } } return true; }
protected function productImportOne($info, $default_language_id, $id_lang, $force_ids, $regenerate, $shop_is_feature_active, $shop_ids, $match_ref, &$accessories, $validateOnly = false) { if ($force_ids && isset($info['id']) && (int) $info['id']) { $product = new Product((int) $info['id']); } elseif ($match_ref && array_key_exists('reference', $info)) { $datas = Db::getInstance()->getRow(' SELECT p.`id_product` FROM `' . _DB_PREFIX_ . 'product` p ' . Shop::addSqlAssociation('product', 'p') . ' WHERE p.`reference` = "' . pSQL($info['reference']) . '" ', false); if (isset($datas['id_product']) && $datas['id_product']) { $product = new Product((int) $datas['id_product']); } else { $product = new Product(); } } elseif (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) { $product = new Product((int) $info['id']); } else { $product = new Product(); } $update_advanced_stock_management_value = false; if (isset($product->id) && $product->id && Product::existsInDatabase((int) $product->id, 'product')) { $product->loadStockData(); $update_advanced_stock_management_value = true; $category_data = Product::getProductCategories((int) $product->id); if (is_array($category_data)) { foreach ($category_data as $tmp) { if (!isset($product->category) || !$product->category || is_array($product->category)) { $product->category[] = $tmp; } } } } AdminImportController::setEntityDefaultValues($product); AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product); if (!$shop_is_feature_active) { $product->shop = (int) Configuration::get('PS_SHOP_DEFAULT'); } elseif (!isset($product->shop) || empty($product->shop)) { $product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID()); } if (!$shop_is_feature_active) { $product->id_shop_default = (int) Configuration::get('PS_SHOP_DEFAULT'); } else { $product->id_shop_default = (int) Context::getContext()->shop->id; } // link product to shops $product->id_shop_list = array(); foreach (explode($this->multiple_value_separator, $product->shop) as $shop) { if (!empty($shop) && !is_numeric($shop)) { $product->id_shop_list[] = Shop::getIdByName($shop); } elseif (!empty($shop)) { $product->id_shop_list[] = $shop; } } if ((int) $product->id_tax_rules_group != 0) { if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) { $address = $this->context->shop->getAddress(); $tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group); $product_tax_calculator = $tax_manager->getTaxCalculator(); $product->tax_rate = $product_tax_calculator->getTotalRate(); } else { $this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, $this->trans('Unknown tax rule group ID. You need to create a group with this ID first.', array(), 'Admin.Parameters.Notification')); } } if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) { $product->id_manufacturer = (int) $product->manufacturer; } elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) { if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) { $product->id_manufacturer = (int) $manufacturer; } else { $manufacturer = new Manufacturer(); $manufacturer->name = $product->manufacturer; $manufacturer->active = true; if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $manufacturer->add()) { $product->id_manufacturer = (int) $manufacturer->id; $manufacturer->associateTo($product->id_shop_list); } else { if (!$validateOnly) { $this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null'); } if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } } } if (isset($product->supplier) && is_numeric($product->supplier) && Supplier::supplierExists((int) $product->supplier)) { $product->id_supplier = (int) $product->supplier; } elseif (isset($product->supplier) && is_string($product->supplier) && !empty($product->supplier)) { if ($supplier = Supplier::getIdByName($product->supplier)) { $product->id_supplier = (int) $supplier; } else { $supplier = new Supplier(); $supplier->name = $product->supplier; $supplier->active = true; if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $supplier->add()) { $product->id_supplier = (int) $supplier->id; $supplier->associateTo($product->id_shop_list); } else { if (!$validateOnly) { $this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $supplier->name, isset($supplier->id) && !empty($supplier->id) ? $supplier->id : 'null'); } if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } } } if (isset($product->price_tex) && !isset($product->price_tin)) { $product->price = $product->price_tex; } elseif (isset($product->price_tin) && !isset($product->price_tex)) { $product->price = $product->price_tin; // If a tax is already included in price, withdraw it from price if ($product->tax_rate) { $product->price = (double) number_format($product->price / (1 + $product->tax_rate / 100), 6, '.', ''); } } elseif (isset($product->price_tin) && isset($product->price_tex)) { $product->price = $product->price_tex; } if (!Configuration::get('PS_USE_ECOTAX')) { $product->ecotax = 0; } if (isset($product->category) && is_array($product->category) && count($product->category)) { $product->id_category = array(); // Reset default values array foreach ($product->category as $value) { if (is_numeric($value)) { if (Category::categoryExists((int) $value)) { $product->id_category[] = (int) $value; } else { $category_to_create = new Category(); $category_to_create->id = (int) $value; $category_to_create->name = AdminImportController::createMultiLangField($value); $category_to_create->active = 1; $category_to_create->id_parent = Configuration::get('PS_HOME_CATEGORY'); // Default parent is home for unknown category to create $category_link_rewrite = Tools::link_rewrite($category_to_create->name[$default_language_id]); $category_to_create->link_rewrite = AdminImportController::createMultiLangField($category_link_rewrite); if (($field_error = $category_to_create->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $category_to_create->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $category_to_create->add()) { $product->id_category[] = (int) $category_to_create->id; } else { if (!$validateOnly) { $this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $category_to_create->name[$default_language_id], isset($category_to_create->id) && !empty($category_to_create->id) ? $category_to_create->id : 'null'); } if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) { $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } } } } elseif (!$validateOnly && is_string($value) && !empty($value)) { $category = Category::searchByPath($default_language_id, trim($value), $this, 'productImportCreateCat'); if ($category['id_category']) { $product->id_category[] = (int) $category['id_category']; } else { $this->errors[] = sprintf($this->trans('%1$s cannot be saved', array(), 'Admin.Parameters.Notification'), trim($value)); } } } $product->id_category = array_values(array_unique($product->id_category)); // Will update default category if category column is not ignored AND if there is categories that are set in the import file row. if (isset($product->id_category[0])) { $product->id_category_default = (int) $product->id_category[0]; } else { $defaultProductShop = new Shop($product->id_shop_default); $product->id_category_default = Category::getRootCategory(null, Validate::isLoadedObject($defaultProductShop) ? $defaultProductShop : null)->id; } } // Will update default category if there is none set here. Home if no category at all. if (!isset($product->id_category_default) || !$product->id_category_default) { // this if will avoid ereasing default category if category column is not present in the CSV file (or ignored) if (isset($product->id_category[0])) { $product->id_category_default = (int) $product->id_category[0]; } else { $defaultProductShop = new Shop($product->id_shop_default); $product->id_category_default = Category::getRootCategory(null, Validate::isLoadedObject($defaultProductShop) ? $defaultProductShop : null)->id; } } $link_rewrite = is_array($product->link_rewrite) && isset($product->link_rewrite[$id_lang]) ? trim($product->link_rewrite[$id_lang]) : ''; $valid_link = Validate::isLinkRewrite($link_rewrite); if (isset($product->link_rewrite[$id_lang]) && empty($product->link_rewrite[$id_lang]) || !$valid_link) { $link_rewrite = Tools::link_rewrite($product->name[$id_lang]); if ($link_rewrite == '') { $link_rewrite = 'friendly-url-autogeneration-failed'; } } if (!$valid_link) { $this->informations[] = sprintf($this->trans('Rewrite link for %1$s (ID %2$s): re-written as %3$s.', array(), 'Admin.Parameters.Notification'), $product->name[$id_lang], isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null', $link_rewrite); } if (!$valid_link || !($match_ref || $force_ids) || !(is_array($product->link_rewrite) && count($product->link_rewrite) && !empty($product->link_rewrite[$id_lang]))) { $product->link_rewrite = AdminImportController::createMultiLangField($link_rewrite); } // replace the value of separator by coma if ($this->multiple_value_separator != ',') { if (is_array($product->meta_keywords)) { foreach ($product->meta_keywords as &$meta_keyword) { if (!empty($meta_keyword)) { $meta_keyword = str_replace($this->multiple_value_separator, ',', $meta_keyword); } } } } // Convert comma into dot for all floating values foreach (Product::$definition['fields'] as $key => $array) { if ($array['type'] == Product::TYPE_FLOAT) { $product->{$key} = str_replace(',', '.', $product->{$key}); } } // Indexation is already 0 if it's a new product, but not if it's an update $product->indexed = 0; $productExistsInDatabase = false; if ($product->id && Product::existsInDatabase((int) $product->id, 'product')) { $productExistsInDatabase = true; } if ($match_ref && $product->reference && $product->existsRefInDatabase($product->reference) || $productExistsInDatabase) { $product->date_upd = date('Y-m-d H:i:s'); } $res = false; $field_error = $product->validateFields(UNFRIENDLY_ERROR, true); $lang_field_error = $product->validateFieldsLang(UNFRIENDLY_ERROR, true); if ($field_error === true && $lang_field_error === true) { // check quantity if ($product->quantity == null) { $product->quantity = 0; } // If match ref is specified && ref product && ref product already in base, trying to update if ($match_ref && $product->reference && $product->existsRefInDatabase($product->reference)) { $datas = Db::getInstance()->getRow(' SELECT product_shop.`date_add`, p.`id_product` FROM `' . _DB_PREFIX_ . 'product` p ' . Shop::addSqlAssociation('product', 'p') . ' WHERE p.`reference` = "' . pSQL($product->reference) . '" ', false); $product->id = (int) $datas['id_product']; $product->date_add = pSQL($datas['date_add']); $res = $validateOnly || $product->update(); } elseif ($productExistsInDatabase) { $datas = Db::getInstance()->getRow(' SELECT product_shop.`date_add` FROM `' . _DB_PREFIX_ . 'product` p ' . Shop::addSqlAssociation('product', 'p') . ' WHERE p.`id_product` = ' . (int) $product->id, false); $product->date_add = pSQL($datas['date_add']); $res = $validateOnly || $product->update(); } // If no id_product or update failed $product->force_id = (bool) $force_ids; if (!$res) { if (isset($product->date_add) && $product->date_add != '') { $res = $validateOnly || $product->add(false); } else { $res = $validateOnly || $product->add(); } } if (!$validateOnly) { if ($product->getType() == Product::PTYPE_VIRTUAL) { StockAvailable::setProductOutOfStock((int) $product->id, 1); } else { StockAvailable::setProductOutOfStock((int) $product->id, (int) $product->out_of_stock); } if ($product_download_id = ProductDownload::getIdFromIdProduct((int) $product->id)) { $product_download = new ProductDownload($product_download_id); $product_download->delete(true); } if ($product->getType() == Product::PTYPE_VIRTUAL) { $product_download = new ProductDownload(); $product_download->filename = ProductDownload::getNewFilename(); Tools::copy($info['file_url'], _PS_DOWNLOAD_DIR_ . $product_download->filename); $product_download->id_product = (int) $product->id; $product_download->nb_downloadable = (int) $info['nb_downloadable']; $product_download->date_expiration = $info['date_expiration']; $product_download->nb_days_accessible = (int) $info['nb_days_accessible']; $product_download->display_filename = basename($info['file_url']); $product_download->add(); } } } $shops = array(); $product_shop = explode($this->multiple_value_separator, $product->shop); foreach ($product_shop as $shop) { if (empty($shop)) { continue; } $shop = trim($shop); if (!empty($shop) && !is_numeric($shop)) { $shop = Shop::getIdByName($shop); } if (in_array($shop, $shop_ids)) { $shops[] = $shop; } else { $this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Shop is not valid')); } } if (empty($shops)) { $shops = Shop::getContextListShopID(); } // If both failed, mysql error if (!$res) { $this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), isset($info['name']) && !empty($info['name']) ? Tools::safeOutput($info['name']) : 'No Name', isset($info['id']) && !empty($info['id']) ? Tools::safeOutput($info['id']) : 'No ID'); $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError(); } else { // Product supplier if (!$validateOnly && isset($product->id) && $product->id && isset($product->id_supplier) && property_exists($product, 'supplier_reference')) { $id_product_supplier = (int) ProductSupplier::getIdByProductAndSupplier((int) $product->id, 0, (int) $product->id_supplier); if ($id_product_supplier) { $product_supplier = new ProductSupplier($id_product_supplier); } else { $product_supplier = new ProductSupplier(); } $product_supplier->id_product = (int) $product->id; $product_supplier->id_product_attribute = 0; $product_supplier->id_supplier = (int) $product->id_supplier; $product_supplier->product_supplier_price_te = $product->wholesale_price; $product_supplier->product_supplier_reference = $product->supplier_reference; $product_supplier->save(); } // SpecificPrice (only the basic reduction feature is supported by the import) if (!$shop_is_feature_active) { $info['shop'] = 1; } elseif (!isset($info['shop']) || empty($info['shop'])) { $info['shop'] = implode($this->multiple_value_separator, Shop::getContextListShopID()); } // Get shops for each attributes $info['shop'] = explode($this->multiple_value_separator, $info['shop']); $id_shop_list = array(); foreach ($info['shop'] as $shop) { if (!empty($shop) && !is_numeric($shop)) { $id_shop_list[] = (int) Shop::getIdByName($shop); } elseif (!empty($shop)) { $id_shop_list[] = $shop; } } if (isset($info['reduction_price']) && $info['reduction_price'] > 0 || isset($info['reduction_percent']) && $info['reduction_percent'] > 0) { foreach ($id_shop_list as $id_shop) { $specific_price = SpecificPrice::getSpecificPrice($product->id, $id_shop, 0, 0, 0, 1, 0, 0, 0, 0); if (is_array($specific_price) && isset($specific_price['id_specific_price'])) { $specific_price = new SpecificPrice((int) $specific_price['id_specific_price']); } else { $specific_price = new SpecificPrice(); } $specific_price->id_product = (int) $product->id; $specific_price->id_specific_price_rule = 0; $specific_price->id_shop = $id_shop; $specific_price->id_currency = 0; $specific_price->id_country = 0; $specific_price->id_group = 0; $specific_price->price = -1; $specific_price->id_customer = 0; $specific_price->from_quantity = 1; $specific_price->reduction = isset($info['reduction_price']) && $info['reduction_price'] ? $info['reduction_price'] : $info['reduction_percent'] / 100; $specific_price->reduction_type = isset($info['reduction_price']) && $info['reduction_price'] ? 'amount' : 'percentage'; $specific_price->from = isset($info['reduction_from']) && Validate::isDate($info['reduction_from']) ? $info['reduction_from'] : '0000-00-00 00:00:00'; $specific_price->to = isset($info['reduction_to']) && Validate::isDate($info['reduction_to']) ? $info['reduction_to'] : '0000-00-00 00:00:00'; if (!$validateOnly && !$specific_price->save()) { $this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Discount is invalid')); } } } if (!$validateOnly && isset($product->tags) && !empty($product->tags)) { if (isset($product->id) && $product->id) { $tags = Tag::getProductTags($product->id); if (is_array($tags) && count($tags)) { if (!empty($product->tags)) { $product->tags = explode($this->multiple_value_separator, $product->tags); } if (is_array($product->tags) && count($product->tags)) { foreach ($product->tags as $key => $tag) { if (!empty($tag)) { $product->tags[$key] = trim($tag); } } $tags[$id_lang] = $product->tags; $product->tags = $tags; } } } // Delete tags for this id product, for no duplicating error Tag::deleteTagsForProduct($product->id); if (!is_array($product->tags) && !empty($product->tags)) { $product->tags = AdminImportController::createMultiLangField($product->tags); foreach ($product->tags as $key => $tags) { $is_tag_added = Tag::addTags($key, $product->id, $tags, $this->multiple_value_separator); if (!$is_tag_added) { $this->addProductWarning(Tools::safeOutput($info['name']), $product->id, $this->l('Tags list is invalid')); break; } } } else { foreach ($product->tags as $key => $tags) { $str = ''; foreach ($tags as $one_tag) { $str .= $one_tag . $this->multiple_value_separator; } $str = rtrim($str, $this->multiple_value_separator); $is_tag_added = Tag::addTags($key, $product->id, $str, $this->multiple_value_separator); if (!$is_tag_added) { $this->addProductWarning(Tools::safeOutput($info['name']), (int) $product->id, 'Invalid tag(s) (' . $str . ')'); break; } } } } //delete existing images if "delete_existing_images" is set to 1 if (!$validateOnly && isset($product->delete_existing_images)) { if ((bool) $product->delete_existing_images) { $product->deleteImages(); } } if (!$validateOnly && isset($product->image) && is_array($product->image) && count($product->image)) { $product_has_images = (bool) Image::getImages($this->context->language->id, (int) $product->id); foreach ($product->image as $key => $url) { $url = trim($url); $error = false; if (!empty($url)) { $url = str_replace(' ', '%20', $url); $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; $image->cover = !$key && !$product_has_images ? true : false; $alt = $product->image_alt[$key]; if (strlen($alt) > 0) { $image->legend = self::createMultiLangField($alt); } // file_exists doesn't work with HTTP protocol if (($field_error = $image->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $image->add()) { // associate image to selected shops $image->associateTo($shops); if (!AdminImportController::copyImg($product->id, $image->id, $url, 'products', !$regenerate)) { $image->delete(); $this->warnings[] = sprintf($this->trans('Error copying image: %s', array(), 'Admin.Parameters.Notification'), $url); } } else { $error = true; } } else { $error = true; } if ($error) { $this->warnings[] = sprintf($this->trans('Product #%1$d: the picture (%2$s) cannot be saved.', array(), 'Admin.Parameters.Notification'), $image->id_product, $url); } } } if (!$validateOnly && isset($product->id_category) && is_array($product->id_category)) { $product->updateCategories(array_map('intval', $product->id_category)); } $product->checkDefaultAttributes(); if (!$validateOnly && !$product->cache_default_attribute) { Product::updateDefaultAttribute($product->id); } // Features import $features = get_object_vars($product); if (!$validateOnly && isset($features['features']) && !empty($features['features'])) { foreach (explode($this->multiple_value_separator, $features['features']) as $single_feature) { if (empty($single_feature)) { continue; } $tab_feature = explode(':', $single_feature); $feature_name = isset($tab_feature[0]) ? trim($tab_feature[0]) : ''; $feature_value = isset($tab_feature[1]) ? trim($tab_feature[1]) : ''; $position = isset($tab_feature[2]) ? (int) $tab_feature[2] - 1 : false; $custom = isset($tab_feature[3]) ? (int) $tab_feature[3] : false; if (!empty($feature_name) && !empty($feature_value)) { $id_feature = (int) Feature::addFeatureImport($feature_name, $position); $id_product = null; if ($force_ids || $match_ref) { $id_product = (int) $product->id; } $id_feature_value = (int) FeatureValue::addFeatureValueImport($id_feature, $feature_value, $id_product, $id_lang, $custom); Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value); } } } // clean feature positions to avoid conflict Feature::cleanPositions(); // set advanced stock managment if (!$validateOnly && isset($product->advanced_stock_management)) { if ($product->advanced_stock_management != 1 && $product->advanced_stock_management != 0) { $this->warnings[] = sprintf($this->trans('Advanced stock management has incorrect value. Not set for product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]); } elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management == 1) { $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot enable on product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]); } elseif ($update_advanced_stock_management_value) { $product->setAdvancedStockManagement($product->advanced_stock_management); } // automaticly disable depends on stock, if a_s_m set to disabled if (StockAvailable::dependsOnStock($product->id) == 1 && $product->advanced_stock_management == 0) { StockAvailable::setProductDependsOnStock($product->id, 0); } } // Check if warehouse exists if (isset($product->warehouse) && $product->warehouse) { if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) { $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, warehouse not set on product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]); } elseif (!$validateOnly) { if (Warehouse::exists($product->warehouse)) { // Get already associated warehouses $associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id); // Delete any entry in warehouse for this product foreach ($associated_warehouses_collection as $awc) { $awc->delete(); } $warehouse_location_entity = new WarehouseProductLocation(); $warehouse_location_entity->id_product = $product->id; $warehouse_location_entity->id_product_attribute = 0; $warehouse_location_entity->id_warehouse = $product->warehouse; if (WarehouseProductLocation::getProductLocation($product->id, 0, $product->warehouse) !== false) { $warehouse_location_entity->update(); } else { $warehouse_location_entity->save(); } StockAvailable::synchronize($product->id); } else { $this->warnings[] = sprintf($this->trans('Warehouse did not exist, cannot set on product %1$s.', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]); } } } // stock available if (isset($product->depends_on_stock)) { if ($product->depends_on_stock != 0 && $product->depends_on_stock != 1) { $this->warnings[] = sprintf($this->trans('Incorrect value for "Depends on stock" for product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]); } elseif ((!$product->advanced_stock_management || $product->advanced_stock_management == 0) && $product->depends_on_stock == 1) { $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot set "Depends on stock" for product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]); } elseif (!$validateOnly) { StockAvailable::setProductDependsOnStock($product->id, $product->depends_on_stock); } // This code allows us to set qty and disable depends on stock if (!$validateOnly && isset($product->quantity) && (int) $product->quantity) { // if depends on stock and quantity, add quantity to stock if ($product->depends_on_stock == 1) { $stock_manager = StockManagerFactory::getManager(); $price = str_replace(',', '.', $product->wholesale_price); if ($price == 0) { $price = 1.0E-6; } $price = round(floatval($price), 6); $warehouse = new Warehouse($product->warehouse); if ($stock_manager->addProduct((int) $product->id, 0, $warehouse, (int) $product->quantity, 1, $price, true)) { StockAvailable::synchronize((int) $product->id); } } else { if ($shop_is_feature_active) { foreach ($shops as $shop) { StockAvailable::setQuantity((int) $product->id, 0, (int) $product->quantity, (int) $shop); } } else { StockAvailable::setQuantity((int) $product->id, 0, (int) $product->quantity, (int) $this->context->shop->id); } } } } elseif (!$validateOnly) { // if not depends_on_stock set, use normal qty if ($shop_is_feature_active) { foreach ($shops as $shop) { StockAvailable::setQuantity((int) $product->id, 0, (int) $product->quantity, (int) $shop); } } else { StockAvailable::setQuantity((int) $product->id, 0, (int) $product->quantity, (int) $this->context->shop->id); } } // Accessories linkage if (isset($product->accessories) && !$validateOnly && is_array($product->accessories) && count($product->accessories)) { $accessories[$product->id] = $product->accessories; } } }
public function add($autodate = true, $null_values = true) { if (parent::add($autodate, $null_values)) { return SpecificPrice::deleteByIdCart($this->id_cart); } return false; }
$product = new Order($id_order); SpecificPrice::deleteByProductId($id_product); $specificPriceIDs = SpecificPrice::getIdsByProductId($id_product); if (count($specificPriceIDs) > 0) { $specificPrice = new SpecificPrice((int) $specificPriceIDs[0]['id_specific_price']); //delete discount if the prices are equal update otherwise if (round($mrp) > round($newPrice)) { $specificPrice->reduction_type = "amount"; $specificPrice->reduction = $mrp - $newPrice; $specificPrice->update(); } else { SpecificPrice::deleteByProductId($id_product); } } else { if (round($mrp) > round($newPrice)) { $specificPrice = new SpecificPrice(); $specificPrice->id_product = $id_product; $specificPrice->reduction_type = "amount"; $specificPrice->reduction = $mrp - $newPrice; $specificPrice->from_quantity = 1; $specificPrice->from = date('Y-m-d H:i:s'); $specificPrice->update(); } } SolrSearch::updateProduct($id_product); $count++; } fclose($f); echo 'Total ' . $count . ' products updated. Thanks for your attention.'; } else { // error
public static function setPriorities($priorities) { $value = ''; foreach ($priorities as $priority) { $value .= pSQL($priority) . ';'; } SpecificPrice::deletePriorities(); return Configuration::updateValue('PS_SPECIFIC_PRICE_PRIORITIES', rtrim($value, ';')); }
public function ajaxProcessAddProductOnOrder() { // Load object $order = new Order((int) Tools::getValue('id_order')); if (!Validate::isLoadedObject($order)) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('The order object cannot be loaded.')))); } if ($order->hasBeenShipped()) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('You cannot add products to delivered orders. ')))); } $product_informations = $_POST['add_product']; if (isset($_POST['add_invoice'])) { $invoice_informations = $_POST['add_invoice']; } else { $invoice_informations = array(); } $product = new Product($product_informations['product_id'], false, $order->id_lang); if (!Validate::isLoadedObject($product)) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('The product object cannot be loaded.')))); } if (isset($product_informations['product_attribute_id']) && $product_informations['product_attribute_id']) { $combination = new Combination($product_informations['product_attribute_id']); if (!Validate::isLoadedObject($combination)) { die(Tools::jsonEncode(array('result' => false, 'error' => Tools::displayError('The combination object cannot be loaded.')))); } } // Total method $total_method = Cart::BOTH_WITHOUT_SHIPPING; // Create new cart $cart = new Cart(); $cart->id_shop_group = $order->id_shop_group; $cart->id_shop = $order->id_shop; $cart->id_customer = $order->id_customer; $cart->id_carrier = $order->id_carrier; $cart->id_address_delivery = $order->id_address_delivery; $cart->id_address_invoice = $order->id_address_invoice; $cart->id_currency = $order->id_currency; $cart->id_lang = $order->id_lang; $cart->secure_key = $order->secure_key; // Save new cart $cart->add(); // Save context (in order to apply cart rule) $this->context->cart = $cart; $this->context->customer = new Customer($order->id_customer); // always add taxes even if there are not displayed to the customer $use_taxes = true; $initial_product_price_tax_incl = Product::getPriceStatic($product->id, $use_taxes, isset($combination) ? $combination->id : null, 2, null, false, true, 1, false, $order->id_customer, $cart->id, $order->{Configuration::get('PS_TAX_ADDRESS_TYPE', null, null, $order->id_shop)}); // Creating specific price if needed if ($product_informations['product_price_tax_incl'] != $initial_product_price_tax_incl) { $specific_price = new SpecificPrice(); $specific_price->id_shop = 0; $specific_price->id_shop_group = 0; $specific_price->id_currency = 0; $specific_price->id_country = 0; $specific_price->id_group = 0; $specific_price->id_customer = $order->id_customer; $specific_price->id_product = $product->id; if (isset($combination)) { $specific_price->id_product_attribute = $combination->id; } else { $specific_price->id_product_attribute = 0; } $specific_price->price = $product_informations['product_price_tax_excl']; $specific_price->from_quantity = 1; $specific_price->reduction = 0; $specific_price->reduction_type = 'amount'; $specific_price->from = '0000-00-00 00:00:00'; $specific_price->to = '0000-00-00 00:00:00'; $specific_price->add(); } // Add product to cart $update_quantity = $cart->updateQty($product_informations['product_quantity'], $product->id, isset($product_informations['product_attribute_id']) ? $product_informations['product_attribute_id'] : null, isset($combination) ? $combination->id : null, 'up', 0, new Shop($cart->id_shop)); if ($update_quantity < 0) { // If product has attribute, minimal quantity is set with minimal quantity of attribute $minimal_quantity = $product_informations['product_attribute_id'] ? Attribute::getAttributeMinimalQty($product_informations['product_attribute_id']) : $product->minimal_quantity; die(Tools::jsonEncode(array('error' => sprintf(Tools::displayError('You must add %d minimum quantity', false), $minimal_quantity)))); } elseif (!$update_quantity) { die(Tools::jsonEncode(array('error' => Tools::displayError('You already have the maximum quantity available for this product.', false)))); } // If order is valid, we can create a new invoice or edit an existing invoice if ($order->hasInvoice()) { $order_invoice = new OrderInvoice($product_informations['invoice']); // Create new invoice if ($order_invoice->id == 0) { // If we create a new invoice, we calculate shipping cost $total_method = Cart::BOTH; // Create Cart rule in order to make free shipping if (isset($invoice_informations['free_shipping']) && $invoice_informations['free_shipping']) { $cart_rule = new CartRule(); $cart_rule->id_customer = $order->id_customer; $cart_rule->name = array(Configuration::get('PS_LANG_DEFAULT') => $this->l('[Generated] CartRule for Free Shipping')); $cart_rule->date_from = date('Y-m-d H:i:s', time()); $cart_rule->date_to = date('Y-m-d H:i:s', time() + 24 * 3600); $cart_rule->quantity = 1; $cart_rule->quantity_per_user = 1; $cart_rule->minimum_amount_currency = $order->id_currency; $cart_rule->reduction_currency = $order->id_currency; $cart_rule->free_shipping = true; $cart_rule->active = 1; $cart_rule->add(); // Add cart rule to cart and in order $cart->addCartRule($cart_rule->id); $values = array('tax_incl' => $cart_rule->getContextualValue(true), 'tax_excl' => $cart_rule->getContextualValue(false)); $order->addCartRule($cart_rule->id, $cart_rule->name[Configuration::get('PS_LANG_DEFAULT')], $values); } $order_invoice->id_order = $order->id; if ($order_invoice->number) { Configuration::updateValue('PS_INVOICE_START_NUMBER', false, false, null, $order->id_shop); } else { $order_invoice->number = Order::getLastInvoiceNumber() + 1; } $invoice_address = new Address((int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE', null, null, $order->id_shop)}); $carrier = new Carrier((int) $order->id_carrier); $tax_calculator = $carrier->getTaxCalculator($invoice_address); $order_invoice->total_paid_tax_excl = Tools::ps_round((double) $cart->getOrderTotal(false, $total_method), 2); $order_invoice->total_paid_tax_incl = Tools::ps_round((double) $cart->getOrderTotal($use_taxes, $total_method), 2); $order_invoice->total_products = (double) $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS); $order_invoice->total_products_wt = (double) $cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS); $order_invoice->total_shipping_tax_excl = (double) $cart->getTotalShippingCost(null, false); $order_invoice->total_shipping_tax_incl = (double) $cart->getTotalShippingCost(); $order_invoice->total_wrapping_tax_excl = abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING)); $order_invoice->total_wrapping_tax_incl = abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING)); $order_invoice->shipping_tax_computation_method = (int) $tax_calculator->computation_method; // Update current order field, only shipping because other field is updated later $order->total_shipping += $order_invoice->total_shipping_tax_incl; $order->total_shipping_tax_excl += $order_invoice->total_shipping_tax_excl; $order->total_shipping_tax_incl += $use_taxes ? $order_invoice->total_shipping_tax_incl : $order_invoice->total_shipping_tax_excl; $order->total_wrapping += abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING)); $order->total_wrapping_tax_excl += abs($cart->getOrderTotal(false, Cart::ONLY_WRAPPING)); $order->total_wrapping_tax_incl += abs($cart->getOrderTotal($use_taxes, Cart::ONLY_WRAPPING)); $order_invoice->add(); $order_invoice->saveCarrierTaxCalculator($tax_calculator->getTaxesAmount($order_invoice->total_shipping_tax_excl)); $order_carrier = new OrderCarrier(); $order_carrier->id_order = (int) $order->id; $order_carrier->id_carrier = (int) $order->id_carrier; $order_carrier->id_order_invoice = (int) $order_invoice->id; $order_carrier->weight = (double) $cart->getTotalWeight(); $order_carrier->shipping_cost_tax_excl = (double) $order_invoice->total_shipping_tax_excl; $order_carrier->shipping_cost_tax_incl = $use_taxes ? (double) $order_invoice->total_shipping_tax_incl : (double) $order_invoice->total_shipping_tax_excl; $order_carrier->add(); } else { $order_invoice->total_paid_tax_excl += Tools::ps_round((double) $cart->getOrderTotal(false, $total_method), 2); $order_invoice->total_paid_tax_incl += Tools::ps_round((double) $cart->getOrderTotal($use_taxes, $total_method), 2); $order_invoice->total_products += (double) $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS); $order_invoice->total_products_wt += (double) $cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS); $order_invoice->update(); } } // Create Order detail information $order_detail = new OrderDetail(); $order_detail->createList($order, $cart, $order->getCurrentOrderState(), $cart->getProducts(), isset($order_invoice) ? $order_invoice->id : 0, $use_taxes, (int) Tools::getValue('add_product_warehouse')); // update totals amount of order $order->total_products += (double) $cart->getOrderTotal(false, Cart::ONLY_PRODUCTS); $order->total_products_wt += (double) $cart->getOrderTotal($use_taxes, Cart::ONLY_PRODUCTS); $order->total_paid += Tools::ps_round((double) $cart->getOrderTotal(true, $total_method), 2); $order->total_paid_tax_excl += Tools::ps_round((double) $cart->getOrderTotal(false, $total_method), 2); $order->total_paid_tax_incl += Tools::ps_round((double) $cart->getOrderTotal($use_taxes, $total_method), 2); if (isset($order_invoice) && Validate::isLoadedObject($order_invoice)) { $order->total_shipping = $order_invoice->total_shipping_tax_incl; $order->total_shipping_tax_incl = $order_invoice->total_shipping_tax_incl; $order->total_shipping_tax_excl = $order_invoice->total_shipping_tax_excl; } // discount $order->total_discounts += (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS)); $order->total_discounts_tax_excl += (double) abs($cart->getOrderTotal(false, Cart::ONLY_DISCOUNTS)); $order->total_discounts_tax_incl += (double) abs($cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS)); // Save changes of order $order->update(); // Update weight SUM $order_carrier = new OrderCarrier((int) $order->getIdOrderCarrier()); if (Validate::isLoadedObject($order_carrier)) { $order_carrier->weight = (double) $order->getTotalWeight(); if ($order_carrier->update()) { $order->weight = sprintf("%.3f " . Configuration::get('PS_WEIGHT_UNIT'), $order_carrier->weight); } } // Update Tax lines $order_detail->updateTaxAmount($order); // Delete specific price if exists if (isset($specific_price)) { $specific_price->delete(); } $products = $this->getProducts($order); // Get the last product $product = end($products); $resume = OrderSlip::getProductSlipResume((int) $product['id_order_detail']); $product['quantity_refundable'] = $product['product_quantity'] - $resume['product_quantity']; $product['amount_refundable'] = $product['total_price_tax_incl'] - $resume['amount_tax_incl']; $product['amount_refund'] = Tools::displayPrice($resume['amount_tax_incl']); $product['return_history'] = OrderReturn::getProductReturnDetail((int) $product['id_order_detail']); $product['refund_history'] = OrderSlip::getProductSlipDetail((int) $product['id_order_detail']); if ($product['id_warehouse'] != 0) { $warehouse = new Warehouse((int) $product['id_warehouse']); $product['warehouse_name'] = $warehouse->name; } else { $product['warehouse_name'] = '--'; } // Get invoices collection $invoice_collection = $order->getInvoicesCollection(); $invoice_array = array(); foreach ($invoice_collection as $invoice) { $invoice->name = $invoice->getInvoiceNumberFormatted(Context::getContext()->language->id, (int) $order->id_shop); $invoice_array[] = $invoice; } // Assign to smarty informations in order to show the new product line $this->context->smarty->assign(array('product' => $product, 'order' => $order, 'currency' => new Currency($order->id_currency), 'can_edit' => $this->tabAccess['edit'], 'invoices_collection' => $invoice_collection, 'current_id_lang' => Context::getContext()->language->id, 'link' => Context::getContext()->link, 'current_index' => self::$currentIndex, 'display_warehouse' => (int) Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'))); $this->sendChangedNotification($order); die(Tools::jsonEncode(array('result' => true, 'view' => $this->createTemplate('_product_line.tpl')->fetch(), 'can_edit' => $this->tabAccess['add'], 'order' => $order, 'invoices' => $invoice_array, 'documents_html' => $this->createTemplate('_documents.tpl')->fetch(), 'shipping_html' => $this->createTemplate('_shipping.tpl')->fetch(), 'discount_form_html' => $this->createTemplate('_discount_form.tpl')->fetch()))); }
public function ajaxProcessUpdateProductPrice() { if ($this->tabAccess['edit'] === '1') { SpecificPrice::deleteByIdCart((int) $this->context->cart->id, (int) Tools::getValue('id_product'), (int) Tools::getValue('id_product_attribute')); $specific_price = new SpecificPrice(); $specific_price->id_cart = (int) $this->context->cart->id; $specific_price->id_shop = 0; $specific_price->id_shop_group = 0; $specific_price->id_currency = 0; $specific_price->id_country = 0; $specific_price->id_group = 0; $specific_price->id_customer = (int) $this->context->customer->id; $specific_price->id_product = (int) Tools::getValue('id_product'); $specific_price->id_product_attribute = (int) Tools::getValue('id_product_attribute'); $specific_price->price = (double) Tools::getValue('price'); $specific_price->from_quantity = 1; $specific_price->reduction = 0; $specific_price->reduction_type = 'amount'; $specific_price->from = '0000-00-00 00:00:00'; $specific_price->to = '0000-00-00 00:00:00'; $specific_price->add(); echo Tools::jsonEncode($this->ajaxReturnVars()); } }
public function productImport() { global $cookie; $this->receiveTab(); $handle = $this->openCsvFile(); $defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT'); self::setLocale(); for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) { if (Tools::getValue('convert')) { $line = $this->utf8_encode_array($line); } $info = self::getMaskedRow($line); if (array_key_exists('id', $info) and (int) $info['id'] and Product::existsInDatabase((int) $info['id'], 'product')) { $product = new Product((int) $info['id']); $categoryData = Product::getProductCategories((int) $product->id); foreach ($categoryData as $tmp) { $product->category[] = $tmp; } } else { $product = new Product(); } self::setEntityDefaultValues($product); self::array_walk($info, array('AdminImport', 'fillInfo'), $product); if ((int) $product->id_tax_rules_group != 0) { if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) { $product->tax_rate = TaxRulesGroup::getTaxesRate((int) $product->id_tax_rules_group, Configuration::get('PS_COUNTRY_DEFAULT'), 0, 0); } else { $this->_addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, Tools::displayError('Invalid tax rule group ID, you first need a group with this ID.')); } } if (isset($product->manufacturer) and is_numeric($product->manufacturer) and Manufacturer::manufacturerExists((int) $product->manufacturer)) { $product->id_manufacturer = (int) $product->manufacturer; } elseif (isset($product->manufacturer) and is_string($product->manufacturer) and !empty($product->manufacturer)) { if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) { $product->id_manufacturer = (int) $manufacturer; } else { $manufacturer = new Manufacturer(); $manufacturer->name = $product->manufacturer; if (($fieldError = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $manufacturer->add()) { $product->id_manufacturer = (int) $manufacturer->id; } else { $this->_errors[] = $manufacturer->name . (isset($manufacturer->id) ? ' (' . $manufacturer->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved'); $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error(); } } } if (isset($product->supplier) and is_numeric($product->supplier) and Supplier::supplierExists((int) $product->supplier)) { $product->id_supplier = (int) $product->supplier; } elseif (isset($product->supplier) and is_string($product->supplier) and !empty($product->supplier)) { if ($supplier = Supplier::getIdByName($product->supplier)) { $product->id_supplier = (int) $supplier; } else { $supplier = new Supplier(); $supplier->name = $product->supplier; if (($fieldError = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $supplier->add()) { $product->id_supplier = (int) $supplier->id; } else { $this->_errors[] = $supplier->name . (isset($supplier->id) ? ' (' . $supplier->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved'); $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error(); } } } if (isset($product->price_tex) and !isset($product->price_tin)) { $product->price = $product->price_tex; } elseif (isset($product->price_tin) and !isset($product->price_tex)) { $product->price = $product->price_tin; // If a tax is already included in price, withdraw it from price if ($product->tax_rate) { $product->price = (double) number_format($product->price / (1 + $product->tax_rate / 100), 6, '.', ''); } } elseif (isset($product->price_tin) and isset($product->price_tex)) { $product->price = $product->price_tex; } if (isset($product->category) and is_array($product->category) and sizeof($product->category)) { $product->id_category = array(); // Reset default values array foreach ($product->category as $value) { if (is_numeric($value)) { if (Category::categoryExists((int) $value)) { $product->id_category[] = (int) $value; } else { $categoryToCreate = new Category(); $categoryToCreate->id = (int) $value; $categoryToCreate->name = self::createMultiLangField($value); $categoryToCreate->active = 1; $categoryToCreate->id_parent = 1; // Default parent is home for unknown category to create if (($fieldError = $categoryToCreate->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $categoryToCreate->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $categoryToCreate->add()) { $product->id_category[] = (int) $categoryToCreate->id; } else { $this->_errors[] = $categoryToCreate->name[$defaultLanguageId] . (isset($categoryToCreate->id) ? ' (' . $categoryToCreate->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved'); $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error(); } } } elseif (is_string($value) and !empty($value)) { $category = Category::searchByName($defaultLanguageId, $value, true); if ($category['id_category']) { $product->id_category[] = (int) $category['id_category']; } else { $categoryToCreate = new Category(); $categoryToCreate->name = self::createMultiLangField($value); $categoryToCreate->active = 1; $categoryToCreate->id_parent = 1; // Default parent is home for unknown category to create if (($fieldError = $categoryToCreate->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $categoryToCreate->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $categoryToCreate->add()) { $product->id_category[] = (int) $categoryToCreate->id; } else { $this->_errors[] = $categoryToCreate->name[$defaultLanguageId] . (isset($categoryToCreate->id) ? ' (' . $categoryToCreate->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved'); $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error(); } } } } } $product->id_category_default = isset($product->id_category[0]) ? (int) $product->id_category[0] : ''; $link_rewrite = is_array($product->link_rewrite) && count($product->link_rewrite) ? $product->link_rewrite[$defaultLanguageId] : ''; $valid_link = Validate::isLinkRewrite($link_rewrite); if (isset($product->link_rewrite[$defaultLanguageId]) and empty($product->link_rewrite[$defaultLanguageId]) or !$valid_link) { $link_rewrite = Tools::link_rewrite($product->name[$defaultLanguageId]); if ($link_rewrite == '') { $link_rewrite = 'friendly-url-autogeneration-failed'; } } if (!$valid_link) { $this->_warnings[] = Tools::displayError('Rewrite link for') . ' ' . $link_rewrite . (isset($info['id']) ? ' (ID ' . $info['id'] . ') ' : '') . ' ' . Tools::displayError('was re-written as') . ' ' . $link_rewrite; } $product->link_rewrite = self::createMultiLangField($link_rewrite); $res = false; $fieldError = $product->validateFields(UNFRIENDLY_ERROR, true); $langFieldError = $product->validateFieldsLang(UNFRIENDLY_ERROR, true); if ($fieldError === true and $langFieldError === true) { // check quantity if ($product->quantity == NULL) { $product->quantity = 0; } // If match ref is specified AND ref product AND ref product already in base, trying to update if (Tools::getValue('match_ref') == 1 and $product->reference and Product::existsRefInDatabase($product->reference)) { $datas = Db::getInstance()->getRow('SELECT `date_add`, `id_product` FROM `' . _DB_PREFIX_ . 'product` WHERE `reference` = "' . $product->reference . '"'); $product->id = pSQL($datas['id_product']); $product->date_add = pSQL($datas['date_add']); $res = $product->update(); } else { if ($product->id and Product::existsInDatabase((int) $product->id, 'product')) { $datas = Db::getInstance()->getRow('SELECT `date_add` FROM `' . _DB_PREFIX_ . 'product` WHERE `id_product` = ' . (int) $product->id); $product->date_add = pSQL($datas['date_add']); $res = $product->update(); } } // If no id_product or update failed if (!$res) { if (isset($product->date_add) && $product->date_add != '') { $res = $product->add(false); } else { $res = $product->add(); } } } // If both failed, mysql error if (!$res) { $this->_errors[] = $info['name'] . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('Cannot be saved'); $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error(); } else { // SpecificPrice (only the basic reduction feature is supported by the import) if (isset($info['reduction_price']) and $info['reduction_price'] > 0 or isset($info['reduction_percent']) and $info['reduction_percent'] > 0) { $specificPrice = new SpecificPrice(); $specificPrice->id_product = (int) $product->id; $specificPrice->id_shop = (int) Shop::getCurrentShop(); $specificPrice->id_currency = 0; $specificPrice->id_country = 0; $specificPrice->id_group = 0; $specificPrice->price = 0.0; $specificPrice->from_quantity = 1; $specificPrice->reduction = (isset($info['reduction_price']) and $info['reduction_price']) ? $info['reduction_price'] : $info['reduction_percent'] / 100; $specificPrice->reduction_type = (isset($info['reduction_price']) and $info['reduction_price']) ? 'amount' : 'percentage'; $specificPrice->from = (isset($info['reduction_from']) and Validate::isDate($info['reduction_from'])) ? $info['reduction_from'] : '0000-00-00 00:00:00'; $specificPrice->to = (isset($info['reduction_to']) and Validate::isDate($info['reduction_to'])) ? $info['reduction_to'] : '0000-00-00 00:00:00'; if (!$specificPrice->add()) { $this->_addProductWarning($info['name'], $product->id, $this->l('Discount is invalid')); } } if (isset($product->tags) and !empty($product->tags)) { // Delete tags for this id product, for no duplicating error Tag::deleteTagsForProduct($product->id); $tag = new Tag(); if (!is_array($product->tags)) { $product->tags = self::createMultiLangField($product->tags); foreach ($product->tags as $key => $tags) { $isTagAdded = $tag->addTags($key, $product->id, $tags); if (!$isTagAdded) { $this->_addProductWarning($info['name'], $product->id, $this->l('Tags list') . ' ' . $this->l('is invalid')); break; } } } else { foreach ($product->tags as $key => $tags) { $str = ''; foreach ($tags as $one_tag) { $str .= $one_tag . ','; } $str = rtrim($str, ','); $isTagAdded = $tag->addTags($key, $product->id, $str); if (!$isTagAdded) { $this->_addProductWarning($info['name'], $product->id, 'Invalid tag(s) (' . $str . ')'); break; } } } } //delete existing images if "delete_existing_images" is set to 1 if (isset($product->delete_existing_images)) { if ((bool) $product->delete_existing_images) { $product->deleteImages(); } elseif (isset($product->image) and is_array($product->image) and sizeof($product->image)) { $product->deleteImages(); } } if (isset($product->image) and is_array($product->image) and sizeof($product->image)) { $productHasImages = (bool) Image::getImages((int) $cookie->id_lang, (int) $product->id); foreach ($product->image as $key => $url) { if (!empty($url)) { $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; $image->cover = (!$key and !$productHasImages) ? true : false; $image->legend = self::createMultiLangField($product->name[$defaultLanguageId]); if (($fieldError = $image->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $image->add()) { if (!self::copyImg($product->id, $image->id, $url)) { $this->_warnings[] = Tools::displayError('Error copying image: ') . $url; } } else { $this->_warnings[] = $image->legend[$defaultLanguageId] . (isset($image->id_product) ? ' (' . $image->id_product . ')' : '') . ' ' . Tools::displayError('Cannot be saved'); $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error(); } } } } if (isset($product->id_category)) { $product->updateCategories(array_map('intval', $product->id_category)); } $features = get_object_vars($product); foreach ($features as $feature => $value) { if (!strncmp($feature, '#F_', 3) and Tools::strlen($product->{$feature})) { $feature_name = str_replace('#F_', '', $feature); $id_feature = Feature::addFeatureImport($feature_name); $id_feature_value = FeatureValue::addFeatureValueImport($id_feature, $product->{$feature}); Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value); } } } } $this->closeCsvFile($handle); }
/** * Return cart products * * @result array Products */ public function getProducts($refresh = false, $id_product = false, $id_country = null) { if (!$this->id) { return array(); } // Product cache must be strictly compared to NULL, or else an empty cart will add dozens of queries if ($this->_products !== null && !$refresh) { // Return product row with specified ID if it exists if (is_int($id_product)) { foreach ($this->_products as $product) { if ($product['id_product'] == $id_product) { return array($product); } } return array(); } return $this->_products; } // Build query $sql = new DbQuery(); // Build SELECT $sql->select('cp.`id_product_attribute`, cp.`id_product`, cp.`quantity` AS cart_quantity, cp.id_shop, pl.`name`, p.`is_virtual`, cp.`price_more`,cp.`price_more_text`, cp.price_more_id, pl.`description_short`, pl.`available_now`, pl.`available_later`, product_shop.`id_category_default`, p.`id_supplier`, p.`id_manufacturer`, product_shop.`on_sale`, product_shop.`ecotax`, product_shop.`additional_shipping_cost`, product_shop.`available_for_order`, product_shop.`price`, product_shop.`active`, product_shop.`unity`, product_shop.`unit_price_ratio`, stock.`quantity` AS quantity_available, p.`width`, p.`height`, p.`depth`, stock.`out_of_stock`, p.`weight`, p.`date_add`, p.`date_upd`, IFNULL(stock.quantity, 0) as quantity, pl.`link_rewrite`, cl.`link_rewrite` AS category, CONCAT(LPAD(cp.`id_product`, 10, 0), LPAD(IFNULL(cp.`id_product_attribute`, 0), 10, 0), IFNULL(cp.`id_address_delivery`, 0)) AS unique_id, cp.id_address_delivery, product_shop.advanced_stock_management, ps.product_supplier_reference supplier_reference'); // Build FROM $sql->from('cart_product', 'cp'); // Build JOIN $sql->leftJoin('product', 'p', 'p.`id_product` = cp.`id_product`'); $sql->innerJoin('product_shop', 'product_shop', '(product_shop.`id_shop` = cp.`id_shop` AND product_shop.`id_product` = p.`id_product`)'); $sql->leftJoin('product_lang', 'pl', ' p.`id_product` = pl.`id_product` AND pl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('pl', 'cp.id_shop')); $sql->leftJoin('category_lang', 'cl', ' product_shop.`id_category_default` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->id_lang . Shop::addSqlRestrictionOnLang('cl', 'cp.id_shop')); $sql->leftJoin('product_supplier', 'ps', 'ps.`id_product` = cp.`id_product` AND ps.`id_product_attribute` = cp.`id_product_attribute` AND ps.`id_supplier` = p.`id_supplier`'); // @todo test if everything is ok, then refactorise call of this method $sql->join(Product::sqlStock('cp', 'cp')); // Build WHERE clauses $sql->where('cp.`id_cart` = ' . (int) $this->id); if ($id_product) { $sql->where('cp.`id_product` = ' . (int) $id_product); } $sql->where('p.`id_product` IS NOT NULL'); // Build ORDER BY $sql->orderBy('cp.`date_add`, cp.`id_product`, cp.`id_product_attribute` ASC'); if (Customization::isFeatureActive()) { $sql->select('cu.`id_customization`, cu.`quantity` AS customization_quantity'); $sql->leftJoin('customization', 'cu', 'p.`id_product` = cu.`id_product` AND cp.`id_product_attribute` = cu.`id_product_attribute` AND cu.`id_cart` = ' . (int) $this->id); $sql->groupBy('cp.`id_product_attribute`, cp.`id_product`, cp.`id_shop`'); } else { $sql->select('NULL AS customization_quantity, NULL AS id_customization'); } if (Combination::isFeatureActive()) { $sql->select(' product_attribute_shop.`price` AS price_attribute, product_attribute_shop.`ecotax` AS ecotax_attr, IF (IFNULL(pa.`reference`, \'\') = \'\', p.`reference`, pa.`reference`) AS reference, (p.`weight`+ pa.`weight`) weight_attribute, IF (IFNULL(pa.`ean13`, \'\') = \'\', p.`ean13`, pa.`ean13`) AS ean13, IF (IFNULL(pa.`upc`, \'\') = \'\', p.`upc`, pa.`upc`) AS upc, IFNULL(product_attribute_shop.`minimal_quantity`, product_shop.`minimal_quantity`) as minimal_quantity, IF(product_attribute_shop.wholesale_price > 0, product_attribute_shop.wholesale_price, product_shop.`wholesale_price`) wholesale_price '); $sql->leftJoin('product_attribute', 'pa', 'pa.`id_product_attribute` = cp.`id_product_attribute`'); $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cp.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)'); } else { $sql->select('p.`reference` AS reference, p.`ean13`, p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity, product_shop.`wholesale_price` wholesale_price'); } $sql->select('image_shop.`id_image` id_image, il.`legend`'); $sql->leftJoin('image_shop', 'image_shop', 'image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $this->id_shop); $sql->leftJoin('image_lang', 'il', 'il.`id_image` = image_shop.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang); $result = Db::getInstance()->executeS($sql); // Reset the cache before the following return, or else an empty cart will add dozens of queries $products_ids = array(); $pa_ids = array(); if ($result) { foreach ($result as $key => $row) { $products_ids[] = $row['id_product']; $pa_ids[] = $row['id_product_attribute']; $specific_price = SpecificPrice::getSpecificPrice($row['id_product'], $this->id_shop, $this->id_currency, $id_country, $this->id_shop_group, $row['cart_quantity'], $row['id_product_attribute'], $this->id_customer, $this->id); if ($specific_price) { $reduction_type_row = array('reduction_type' => $specific_price['reduction_type']); } else { $reduction_type_row = array('reduction_type' => 0); } $result[$key] = array_merge($row, $reduction_type_row); } } // Thus you can avoid one query per product, because there will be only one query for all the products of the cart Product::cacheProductsFeatures($products_ids); Cart::cacheSomeAttributesLists($pa_ids, $this->id_lang); $this->_products = array(); if (empty($result)) { return array(); } $ecotax_rate = (double) Tax::getProductEcotaxRate($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $apply_eco_tax = Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX'); $cart_shop_context = Context::getContext()->cloneContext(); foreach ($result as &$row) { if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) { $row['ecotax'] = (double) $row['ecotax_attr']; } $row['stock_quantity'] = (int) $row['quantity']; // for compatibility with 1.2 themes $row['quantity'] = (int) $row['cart_quantity']; if (isset($row['id_product_attribute']) && (int) $row['id_product_attribute'] && isset($row['weight_attribute'])) { $row['weight'] = (double) $row['weight_attribute']; } if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') { $address_id = (int) $this->id_address_invoice; } else { $address_id = (int) $row['id_address_delivery']; } if (!Address::addressExists($address_id)) { $address_id = null; } if ($cart_shop_context->shop->id != $row['id_shop']) { $cart_shop_context->shop = new Shop((int) $row['id_shop']); } $address = Address::initialize($address_id, true); $id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $row['id_product'], $cart_shop_context); $tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator(); $row['price_without_reduction'] = Product::getPriceStatic((int) $row['id_product'], true, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, false, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, true, true, $cart_shop_context); $row['price_with_reduction'] = Product::getPriceStatic((int) $row['id_product'], true, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, true, true, $cart_shop_context); $row['price'] = $row['price_with_reduction_without_tax'] = Product::getPriceStatic((int) $row['id_product'], false, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, true, true, $cart_shop_context); if ($row['price_more']) { $row['price'] += $row['price_more']; } switch (Configuration::get('PS_ROUND_TYPE')) { case Order::ROUND_TOTAL: $row['total'] = $row['price_with_reduction_without_tax'] * (int) $row['cart_quantity']; $row['total_wt'] = $row['price_with_reduction'] * (int) $row['cart_quantity']; break; case Order::ROUND_LINE: $row['total'] = Tools::ps_round($row['price_with_reduction_without_tax'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_); $row['total_wt'] = Tools::ps_round($row['price_with_reduction'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_); break; case Order::ROUND_ITEM: default: $row['total'] = Tools::ps_round($row['price_with_reduction_without_tax'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity']; $row['total_wt'] = Tools::ps_round($row['price_with_reduction'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity']; break; } $row['price_wt'] = $row['price_with_reduction']; $row['description_short'] = Tools::nl2br($row['description_short']); if ($row['price_more']) { $row['price_wt'] += $row['price_more']; } // check if a image associated with the attribute exists if ($row['id_product_attribute']) { $row2 = Image::getBestImageAttribute($row['id_shop'], $this->id_lang, $row['id_product'], $row['id_product_attribute']); if ($row2) { $row = array_merge($row, $row2); } } $row['reduction_applies'] = $specific_price_output && (double) $specific_price_output['reduction']; $row['quantity_discount_applies'] = $specific_price_output && $row['cart_quantity'] >= (int) $specific_price_output['from_quantity']; $row['id_image'] = Product::defineProductImage($row, $this->id_lang); $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']); $row['features'] = Product::getFeaturesStatic((int) $row['id_product']); if (array_key_exists($row['id_product_attribute'] . '-' . $this->id_lang, self::$_attributesLists)) { $row = array_merge($row, self::$_attributesLists[$row['id_product_attribute'] . '-' . $this->id_lang]); } $row = Product::getTaxesInformations($row, $cart_shop_context); $this->_products[] = $row; } return $this->_products; }
if ((double) substr(_PS_VERSION_, 0, 3) < 1.6) { $reference = '\'' . $reference . '\''; } $combination = $product_attribute_id . '|' . $quantity . '|' . $new_price . '|0|' . $image . '|' . $reference . '|0.00|' . $minimal_quantity . '|'; // Add for Prestashop 1.5 version and above if ((double) substr(_PS_VERSION_, 0, 3) >= 1.5) { // Add product attribute shop Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'product_attribute_shop (id_product_attribute, id_shop, price, wholesale_price, weight, minimal_quantity, available_date) VALUES (' . $product_attribute_id . ', ' . $shop_id . ', ' . $new_price . ', ' . $wholesale_price . ', ' . $weight . ', ' . $minimal_quantity . ', "0000-00-00")'); // Add stock availability $product_tmp = new Product($request_product); Db::getInstance()->Execute('INSERT INTO ' . _DB_PREFIX_ . 'stock_available (id_product, id_product_attribute, id_shop, id_shop_group, quantity, out_of_stock) VALUES (' . $request_product . ', ' . $product_attribute_id . ', ' . $shop_id . ', 0, ' . $quantity . ', ' . $product_tmp->out_of_stock . ')'); // Update stock for base product Db::getInstance()->Execute('UPDATE ' . _DB_PREFIX_ . 'stock_available SET quantity = quantity + ' . $quantity . ' WHERE id_product = ' . $request_product . ' AND id_product_attribute = 0 AND ' . 'id_shop = ' . $shop_id); // Specific price $country_id = (int) Db::getInstance()->getValue('SELECT id_country FROM ' . _DB_PREFIX_ . 'address WHERE id_customer = ' . (int) $cookie->id_customer . ' AND active = 1 ORDER by id_address ASC'); $specific_price = SpecificPrice::getSpecificPrice($request_product, $shop_id, (int) $cookie->id_currency, $country_id, $group_id, $quantity, $product_attribute_id, (int) $cookie->id_customer); if (!empty($specific_price)) { if ($specific_price['reduction_type'] == 'percentage') { $specific_price_combination = (double) $specific_price['reduction'] * 100 . '|0|' . (double) $specific_price['price'] . '|percentage|'; } else { $specific_price_combination = '0|' . (double) $specific_price['reduction'] . '|' . (double) $specific_price['price'] . '|amount|'; } } else { $specific_price_combination = '0|0|0|\'\'|'; } // Attribute datas $group_name = Db::getInstance()->getValue('SELECT name FROM ' . _DB_PREFIX_ . 'attribute_group_lang WHERE id_attribute_group = ' . $group . ' AND id_lang = ' . (int) $cookie->id_lang); $attribute = $attribute_id . '|\'' . $request_value . '\'|\'' . $group_name . '\'|\'' . $group . '\'|'; // Return string $combination .= '0000-00-00|' . $specific_price_combination . $attribute; // Add weight, attributes names for Prestashop 1.6.0.6 and above
public function handleConfirm($update = false) { global $currentIndex, $cookie, $smarty; $products_to_import = array(); $defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT'); $file_path = Tools::getValue('current_file'); $overwrite_imgs = Tools::getValue("overwrite_imgs"); //$file_path = '/Users/rohit/webroot/indusdiva/admin12/product-uploads/upload_sheet_1.csv'; $f = fopen($file_path, 'r'); $file_error = false; if ($f) { //discard header $line = fgetcsv($f); while ($line = fgetcsv($f)) { //ignore empty lines if (empty($line)) { continue; } //trim data foreach ($line as $key => $value) { $line[$key] = trim($value); } $id_product = $line[0]; $images = $line[1]; $product_name = $line[2]; $fabric = $line[3]; $color = $line[4]; $mrp = $line[5]; $supplier_code = $line[6]; $reference = $line[7]; $location = $line[8]; $length = $line[9]; $width = $line[10]; $blouse_length = $line[11]; $garment_type = $line[12]; $work_type = $line[13]; $weight = $line[14]; $description = $line[15]; $other_info = $line[16]; $wash_care = $line[17]; $shipping_estimate = $line[18]; $supplier_price = $line[19]; $manufacturer = $line[20]; $categories = explode(",", $line[21]); $tax_rule = $line[22]; $quantity = $line[23]; $active = $line[24]; $discount = $line[25]; $tags = $line[26]; $kameez_style = $line[27]; $salwar_style = $line[28]; $sleeves = $line[29]; $customizable = $line[30]; $generic_color = $line[31]; $skirt_length = $line[32]; $dupatta_length = $line[33]; $stone = $line[34]; $plating = $line[35]; $material = $line[36]; $dimensions = $line[37]; $look = $line[38]; $as_shown = isset($line[39]) && !empty($line[39]) ? intval($line[39]) : 0; $id_sizechart = isset($line[40]) && !empty($line[40]) ? intval($line[40]) : 0; $is_exclusive = isset($line[41]) && !empty($line[41]) ? intval($line[41]) : 0; $handbag_occasion = isset($line[42]) && !empty($line[42]) ? $line[42] : null; $handbag_style = isset($line[43]) && !empty($line[43]) ? $line[43] : null; $handbag_material = isset($line[44]) && !empty($line[44]) ? $line[44] : null; $images = explode(",", $images); $error = false; //validate fields if (!Validate::isFloat($mrp)) { $error = 'MRP should be a number: ' . trim($reference); } elseif (!Validate::isFloat($supplier_price)) { $error = 'Supplier Price should be a number: ' . trim($reference); } $importCategories = array(); if (is_array($categories)) { $categories = array_unique($categories); foreach ($categories as $category) { $category = intval(trim($category)); if (empty($category)) { continue; } if (!is_numeric($category) || !Category::categoryExists($category)) { $error = 'Category does not exist: ' . $category; } $importCategories[] = $category; } } else { $error = 'Atleast one category required: ' . trim($reference); } if (!Validate::isFloat($weight)) { $error = 'Weight has to be a number: ' . trim($reference); } if (!empty($manufacturer) && (!is_numeric($manufacturer) || !Manufacturer::manufacturerExists((int) $manufacturer))) { $error = 'Manufacturer does not exist'; } if ($quantity && !is_numeric($quantity) || $discount && !is_numeric($discount)) { $error = 'Quantity and discount should be numbers: ' . trim($reference); } if (!Validate::isLoadedObject(new TaxRulesGroup($tax_rule))) { $error = 'Tax rate invalid: ' . trim($reference); } if (!$update) { $sql = "SELECT `reference`\n\t\t\t\t\t\t\tFROM " . _DB_PREFIX_ . "product p\n\t\t\t\t\t\t\tWHERE p.`reference` = '" . $reference . "'"; $row = Db::getInstance()->getRow($sql); if (isset($row['reference'])) { $error = "Duplicate indusdiva code : " . trim($reference); } } //check for souring price if ($supplier_price > $mrp / 1.2) { $error = "MRP too low : " . trim($reference); } //check for images if (!$update || $overwrite_imgs == "on") { foreach ($images as $image_name) { $image_name = trim($image_name); $image_path = IMAGE_UPLOAD_PATH . $image_name; if (!empty($image_name) && !file_exists($image_path)) { $error = "Image not found for: " . trim($reference) . ", Image Name: " . $image_name; break; } } } $vendor_code = substr($reference, 0, 6); $sql = "select id_supplier from ps_supplier where code = '{$vendor_code}'"; $row = Db::getInstance()->getRow($sql); if (!isset($row['id_supplier'])) { $error = "Vendor Details not found for : " . trim($reference); } else { $id_supplier = $row['id_supplier']; } //For sudarshan, supplier_code (vendor product code) is mandatory if (false) { //(int) $id_supplier === 2 ) { if (empty($supplier_code)) { $error = "Reference: {$reference} -- Supplier Code is Mandatory for Vendor {$vendor_code}"; } else { if (strpos("::", ${$supplier_code}) === false) { $error = "Reference: {$reference} -- Supplier Code:{$supplier_code} is not in DESIGN_NO::ITEM_CODE format for Vendor {$vendor_code}"; } } } if (!$error) { if ($update && !empty($id_product)) { $product = new Product((int) $id_product); if (!Validate::isLoadedObject($product)) { $error = "Error loading the product: " . $id_product; return; } } elseif (!$update) { $product = new Product(); } $product->id_tax_rules_group = $tax_rule; $product->reference = $reference; $product->id_supplier = $id_supplier; $product->location = $location; $product->tax_rate = TaxRulesGroup::getTaxesRate((int) $product->id_tax_rules_group, Configuration::get('PS_COUNTRY_DEFAULT'), 0, 0); if (isset($manufacturer) and is_numeric($manufacturer) and Manufacturer::manufacturerExists((int) $manufacturer)) { $product->id_manufacturer = $manufacturer; } $product->price = (double) $mrp; $product->price = (double) number_format($product->price / (1 + $product->tax_rate / 100), 6, '.', ''); $product->id_category = $importCategories; $product->id_category_default = 1; $product->name = array(); $product->name[$defaultLanguageId] = $product_name; $product->description_short = array(); $product->description_short[$defaultLanguageId] = $style_tips; $product->description = array(); $product->description[$defaultLanguageId] = $description; $link_rewrite = Tools::link_rewrite($product->name[$defaultLanguageId]); $product->link_rewrite = array(); $product->link_rewrite[$defaultLanguageId] = $link_rewrite; $product->quantity = $quantity ? intval($quantity) : 0; if ($discount && is_numeric($discount)) { $product->discount = $discount; } if (!empty($tags)) { $product->tags = $tags; } $product->weight = is_numeric($weight) ? $weight : 0; $product->width = is_numeric($width) ? $width : 0; $product->height = is_numeric($length) ? $length : 0; $product->supplier_reference = $supplier_code; $product->wholesale_price = $supplier_price ? (double) $supplier_price : 0; $product->active = $active == 1 ? 1 : 0; $product->images = $images; $product->fabric = $fabric; $product->color = $color; $product->generic_color = $generic_color; $product->garment_type = $garment_type; $product->work_type = $work_type; $product->blouse_length = $blouse_length ? $blouse_length : ' '; $product->wash_care = $wash_care ? $wash_care : ' '; $product->other_info = $other_info ? $other_info : ' '; $product->shipping_estimate = $shipping_estimate ? $shipping_estimate : ' '; $product->is_customizable = $customizable == 1 ? 1 : 0; $product->kameez_style = $kameez_style; $product->salwar_style = $salwar_style; $product->sleeves = $sleeves; $product->skirt_length = $skirt_length; $product->dupatta_length = $dupatta_length; $product->stone = $stone; $product->plating = $plating; $product->material = $material; $product->dimensions = $dimensions; $product->look = $look; $product->as_shown = $as_shown; $product->id_sizechart = $id_sizechart; $product->is_exclusive = $is_exclusive; $product->handbag_occasion = $handbag_occasion; $product->handbag_style = $handbag_style; $product->handbag_material = $handbag_material; $product->indexed = 0; $products_to_import[] = $product; } else { $smarty->assign('error', $error); return; $file_error = true; } } if (!$file_error) { $added_product_ids = array(); foreach ($products_to_import as $product) { $fieldError = $product->validateFields(UNFRIENDLY_ERROR, true); $langFieldError = $product->validateFieldsLang(UNFRIENDLY_ERROR, true); if ($fieldError === true and $langFieldError === true) { // check quantity if ($product->quantity == NULL) { $product->quantity = 0; } // If no id_product or update failed if ($update && $product->id) { $res = $product->update(); } else { $res = $product->add(); } $added_product_ids[] = $product->id; } if (isset($product->discount) && $product->discount > 0) { SpecificPrice::deleteByProductId((int) $product->id); $specificPrice = new SpecificPrice(); $specificPrice->id_product = (int) $product->id; $specificPrice->id_shop = (int) Shop::getCurrentShop(); $specificPrice->id_currency = 0; $specificPrice->id_country = 0; $specificPrice->id_group = 0; $specificPrice->from_quantity = 1; $specificPrice->reduction = $product->discount / 100; $specificPrice->reduction_type = 'percentage'; $specificPrice->from = '2012-01-01 00:00:00'; $specificPrice->to = '2016-01-01 00:00:00'; $specificPrice->price = $product->price; $specificPrice->add(); } if (isset($product->tags) and !empty($product->tags)) { // Delete tags for this id product, for no duplicating error Tag::deleteTagsForProduct($product->id); $tag = new Tag(); $tag->addTags($defaultLanguageId, $product->id, $tags); } if (isset($product->images) and is_array($product->images) and sizeof($product->images) and !$update || $overwrite_imgs == "on") { $product->deleteImages(); $first_image = true; foreach ($product->images as $image_name) { $image_name = trim($image_name); $image_path = IMAGE_UPLOAD_PATH . $image_name; if (!empty($image_name)) { $image = new Image(); $image->id_product = (int) $product->id; $image->position = Image::getHighestPosition($product->id) + 1; $image->cover = $first_image; $image->legend[$defaultLanguageId] = $product->name[$defaultLanguageId]; if (($fieldError = $image->validateFields(false, true)) === true and ($langFieldError = $image->validateFieldsLang(false, true)) === true and $image->add()) { if (!self::copyImg($product->id, $image->id, $image_path)) { $_warnings[] = Tools::displayError('Error copying image: ') . $image_path; } else { //delete the original image @unlink($image_path); } } else { $_warnings[] = $image->legend[$defaultLanguageId] . (isset($image->id_product) ? ' (' . $image->id_product . ')' : '') . ' ' . Tools::displayError('Cannot be saved'); $_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error(); } } $first_image = false; } } if (isset($product->id_category)) { $product->updateCategories(array_map('intval', $product->id_category)); } $this->addFeature($product->id, 'fabric', $product->fabric); $this->addFeature($product->id, 'color', $product->color); $this->addFeature($product->id, 'garment_type', $product->garment_type); $this->addFeature($product->id, 'work_type', $product->work_type); $this->addFeature($product->id, 'blouse_length', $product->blouse_length); $this->addFeature($product->id, 'wash_care', $product->wash_care); $this->addFeature($product->id, 'other_info', $product->other_info); // to avoid type errors in the catalog sheet - construct the string here again $shipping_sla = (int) preg_replace('/\\D/', '', $product->shipping_estimate); $shipping_estimate_str = ""; if ($shipping_sla > 0) { $shipping_estimate_str = $shipping_sla === 1 ? "Ready to be shipped in 1 day" : "Ready to be shipped in {$shipping_sla} days"; } $this->addFeature($product->id, 'shipping_estimate', $shipping_estimate_str); $this->addFeature($product->id, 'kameez_style', $product->kameez_style); $this->addFeature($product->id, 'salwar_style', $product->salwar_style); $this->addFeature($product->id, 'sleeves', $product->sleeves); $this->addFeature($product->id, 'generic_color', $product->generic_color); $this->addFeature($product->id, 'skirt_length', $product->skirt_length); $this->addFeature($product->id, 'dupatta_length', $product->dupatta_length); $this->addFeature($product->id, 'stone', $product->stone); $this->addFeature($product->id, 'plating', $product->plating); $this->addFeature($product->id, 'material', $product->material); $this->addFeature($product->id, 'dimensions', $product->dimensions); $this->addFeature($product->id, 'look', $product->look); $this->addFeature($product->id, 'handbag_occasion', $product->handbag_occasion); $this->addFeature($product->id, 'handbag_style', $product->handbag_style); $this->addFeature($product->id, 'handbag_material', $product->handbag_material); } $smarty->assign("products_affected", $products_to_import); //reindex the products SolrSearch::updateProducts($added_product_ids); $smarty->assign("is_update", $update); } else { $smarty->assign('file_error', 1); } } else { $smarty->assign('error_reading', 1); } }
public static function priceCalculation($id_shop, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency, $id_group, $quantity, $use_tax, $decimals, $only_reduc, $use_reduc, $with_ecotax, &$specific_price, $use_group_reduction, $id_customer = 0, $use_customer_price = true, $id_cart = 0, $real_quantity = 0, $service_date = null, $service_time_from = null, $service_time_to = null) { require_once dirname(__FILE__) . '/../../modules/aphrodinet/classes/AphCustomPrice.php'; static $address = null; static $context = null; if ($address === null) { $address = new Address(); } if ($context == null) { $context = Context::getContext()->cloneContext(); } if ($id_shop !== null && $context->shop->id != (int) $id_shop) { $context->shop = new Shop((int) $id_shop); } if (!$use_customer_price) { $id_customer = 0; } if ($id_product_attribute === null) { $id_product_attribute = Product::getDefaultAttribute($id_product); } if (!empty($id_cart)) { $res = Db::getInstance()->executeS('SELECT `delivery_date`, `delivery_time_from`, `delivery_time_to` ' . 'FROM ' . _DB_PREFIX_ . 'cart_product ' . 'WHERE `id_cart` = ' . (int) $id_cart . ' AND `id_product` = ' . (int) $id_product . ' AND `id_product_attribute` = ' . (int) $id_product_attribute . ' ' . 'LIMIT 1'); if (!empty($res) && empty($service_date)) { $res = $res[0]; if (!empty($res)) { $service_date = $res['delivery_date']; $service_time_from = $res['delivery_time_from']; $service_time_to = $res['delivery_time_to']; } } } if (!empty($service_time_from) && strlen($service_time_from) == 5) { $service_time_from .= ':00'; } if (!empty($service_time_to) && strlen($service_time_to) == 5) { $service_time_to .= ':00'; } $cache_id = (int) $id_product . '-' . (int) $id_shop . '-' . (int) $id_currency . '-' . (int) $id_country . '-' . $id_state . '-' . $zipcode . '-' . (int) $id_group . '-' . (int) $quantity . '-' . (int) $id_product_attribute . '-' . (int) $with_ecotax . '-' . (int) $id_customer . '-' . (int) $use_group_reduction . '-' . (int) $id_cart . '-' . (int) $real_quantity . '-' . ($only_reduc ? '1' : '0') . '-' . ($use_reduc ? '1' : '0') . '-' . ($use_tax ? '1' : '0') . '-' . (int) $decimals . (!empty($service_date) && $service_date != '0000-00-00' ? '-' . $service_date : '') . (!empty($service_time_to) && $service_time_to != '00:00:00' ? '-' . $service_time_from : '') . (!empty($service_time_to) && $service_time_to != '00:00:00' ? '-' . $service_time_to : ''); // reference parameter is filled before any returns $specific_price = SpecificPrice::getSpecificPrice((int) $id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute, $id_customer, $id_cart, $real_quantity); if (isset(self::$_prices[$cache_id])) { if (isset($specific_price['price']) && $specific_price['price'] > 0) { $specific_price['price'] = self::$_prices[$cache_id]; } return self::$_prices[$cache_id]; } $cache_id_2 = $id_product . '-' . $id_shop . (!empty($service_date) && $service_date != '0000-00-00' ? '-' . $service_date : '') . (!empty($service_time_to) && $service_time_to != '00:00:00' ? '-' . $service_time_from : '') . (!empty($service_time_to) && $service_time_to != '00:00:00' ? '-' . $service_time_to : ''); if (!isset(self::$_pricesLevel2[$cache_id_2])) { $base_price_wt = 0; $service_date_ts = strtotime($service_date); $service_date_week_day = date('w', $service_date_ts); if (!empty($service_date) && $service_date != '0000-00-00') { // cerco il prezzo del giorno $custom_prices = AphCustomPrice::getByDate($id_shop, $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, -1, NULL, 1); if (!empty($custom_prices)) { $base_price_wt = $custom_prices[0]['price_wt']; } } if (!empty($service_date) && $service_date != '0000-00-00') { $offer_prices = AphCustomPrice::getByDate($id_shop, $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, -1, 0, 1); } if (!empty($service_date) && $service_date != '0000-00-00') { $offer_prices = AphCustomPrice::getByDate($id_shop, $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, $service_date_week_day, 0, 1); } if (!empty($service_date) && $service_date != '0000-00-00' && empty($offer_prices)) { $custom_prices = AphCustomPrice::getByDate($id_shop, $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, -1); } if (!empty($service_date) && $service_date != '0000-00-00' && empty($offer_prices)) { $custom_prices = AphCustomPrice::getByDate($id_shop, $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, $service_date_week_day); } if (!empty($service_date) && $service_date != '0000-00-00' && !empty($service_time_to) && $service_time_to != '00:00:00' && empty($custom_prices) && empty($offer_prices)) { $custom_prices = AphCustomPrice::getByDate($id_shop, $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, -1, $service_time_from); } if (!empty($service_date) && $service_date != '0000-00-00' && !empty($service_time_to) && $service_time_to != '00:00:00' && empty($custom_prices) && empty($offer_prices)) { $custom_prices = AphCustomPrice::getByDate($id_shop, $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, $service_date_week_day, $service_time_from); } if (!empty($service_date) && $service_date != '0000-00-00' && empty($custom_prices) && empty($offer_prices)) { $custom_prices = AphCustomPrice::getByDate(Configuration::get('PS_SHOP_DEFAULT'), $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, -1); } if (!empty($service_date) && $service_date != '0000-00-00' && empty($custom_prices) && empty($offer_prices)) { $custom_prices = AphCustomPrice::getByDate(Configuration::get('PS_SHOP_DEFAULT'), $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, $service_date_week_day); } if (!empty($service_date) && $service_date != '0000-00-00' && !empty($service_time_to) && $service_time_to != '00:00:00' && empty($custom_prices) && empty($offer_prices)) { $custom_prices = AphCustomPrice::getByDate(Configuration::get('PS_SHOP_DEFAULT'), $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, -1, $service_time_from); } if (!empty($service_date) && $service_date != '0000-00-00' && !empty($service_time_to) && $service_time_to != '00:00:00' && empty($custom_prices) && empty($offer_prices)) { $custom_prices = AphCustomPrice::getByDate(Configuration::get('PS_SHOP_DEFAULT'), $id_currency, $id_country, $id_group, $service_date, $id_customer, (int) $id_product, $service_date_week_day, $service_time_from); } if (!empty($offer_prices)) { $res = $offer_prices; } elseif (!empty($custom_prices)) { $res = $custom_prices; } else { $sql = new DbQuery(); $sql->select('product_shop.`price`, product_shop.`ecotax`'); $sql->from('product', 'p'); $sql->innerJoin('product_shop', 'product_shop', '(product_shop.id_product=p.id_product AND product_shop.id_shop = ' . (int) $id_shop . ')'); $sql->where('p.`id_product` = ' . (int) $id_product); if (Combination::isFeatureActive()) { $sql->select('IFNULL(product_attribute_shop.id_product_attribute,0) id_product_attribute, product_attribute_shop.`price` AS attribute_price, product_attribute_shop.default_on'); $sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.id_product = p.id_product AND product_attribute_shop.id_shop = ' . (int) $id_shop . ')'); } else { $sql->select('0 as id_product_attribute'); } $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } if (is_array($res) && count($res)) { foreach ($res as $row) { if ($row['price'] < 0) { if ($row['reduction_type'] == 'amount') { $row['price'] = 0; //$base_price_wt - $row['reduction']; } else { $row['price'] = 0; //$base_price_wt - (($row['reduction'] * $base_price_wt) / 100); } } else { $row['price'] = 0; //$row['price_wt']; } $array_tmp = array('price' => $row['price'], 'ecotax' => !empty($row['ecotax']), 'attribute_price' => isset($row['attribute_price']) ? $row['attribute_price'] : null); self::$_pricesLevel2[$cache_id_2][(int) $row['id_product_attribute']] = $array_tmp; if (isset($row['default_on']) && $row['default_on'] == 1) { self::$_pricesLevel2[$cache_id_2][0] = $array_tmp; } } } } if (!isset(self::$_pricesLevel2[$cache_id_2][(int) $id_product_attribute])) { return; } $result = self::$_pricesLevel2[$cache_id_2][(int) $id_product_attribute]; if (!$specific_price || $specific_price['price'] < 0) { $price = (double) $result['price']; } else { $price = (double) $specific_price['price']; } if (!$specific_price || !($specific_price['price'] >= 0 && $specific_price['id_currency'])) { $price = Tools::convertPrice($price, $id_currency); if (isset($specific_price['price'])) { $specific_price['price'] = $price; } } if (is_array($result) && (!$specific_price || !$specific_price['id_product_attribute'] || $specific_price['price'] < 0)) { $attribute_price = Tools::convertPrice($result['attribute_price'] !== null ? (double) $result['attribute_price'] : 0, $id_currency); if ($id_product_attribute !== false) { $price += $attribute_price; } } $address->id_country = $id_country; $address->id_state = $id_state; $address->postcode = $zipcode; $tax_manager = TaxManagerFactory::getManager($address, Product::getIdTaxRulesGroupByIdProduct((int) $id_product, $context)); $product_tax_calculator = $tax_manager->getTaxCalculator(); if ($use_tax) { $price = $product_tax_calculator->addTaxes($price); } if (($result['ecotax'] || isset($result['attribute_ecotax'])) && $with_ecotax) { $ecotax = $result['ecotax']; if (isset($result['attribute_ecotax']) && $result['attribute_ecotax'] > 0) { $ecotax = $result['attribute_ecotax']; } if ($id_currency) { $ecotax = Tools::convertPrice($ecotax, $id_currency); } if ($use_tax) { $tax_manager = TaxManagerFactory::getManager($address, (int) Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID')); $ecotax_tax_calculator = $tax_manager->getTaxCalculator(); $price += $ecotax_tax_calculator->addTaxes($ecotax); } else { $price += $ecotax; } } $specific_price_reduction = 0; if (($only_reduc || $use_reduc) && $specific_price) { if ($specific_price['reduction_type'] == 'amount') { $reduction_amount = $specific_price['reduction']; if (!$specific_price['id_currency']) { $reduction_amount = Tools::convertPrice($reduction_amount, $id_currency); } $specific_price_reduction = $reduction_amount; if (!$use_tax && $specific_price['reduction_tax']) { $specific_price_reduction = $product_tax_calculator->removeTaxes($specific_price_reduction); } if ($use_tax && !$specific_price['reduction_tax']) { $specific_price_reduction = $product_tax_calculator->addTaxes($specific_price_reduction); } } else { $specific_price_reduction = $price * $specific_price['reduction']; } } if ($use_reduc) { $price -= $specific_price_reduction; } if ($use_group_reduction) { $reduction_from_category = GroupReduction::getValueForProduct($id_product, $id_group); if ($reduction_from_category !== false) { $group_reduction = $price * (double) $reduction_from_category; } else { // apply group reduction if there is no group reduction for this category $group_reduction = ($reduc = Group::getReductionByIdGroup($id_group)) != 0 ? $price * $reduc / 100 : 0; } $price -= $group_reduction; } if ($only_reduc) { return Tools::ps_round($specific_price_reduction, $decimals); } $price = Tools::ps_round($price, $decimals); if ($price < 0) { $price = 0; } self::$_prices[$cache_id] = $price; return self::$_prices[$cache_id]; }
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; } }
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'))); }
public static function applyRuleToProduct($id_rule, $id_product, $id_product_attribute = null) { $rule = new SpecificPriceRule((int) $id_rule); if (!Validate::isLoadedObject($rule)) { return false; } $specific_price = new SpecificPrice(); $specific_price->id_specific_price_rule = (int) $rule->id; $specific_price->id_product = (int) $id_product; $specific_price->id_product_attribute = (int) $id_product_attribute; $specific_price->id_customer = 0; $specific_price->id_shop = (int) $rule->id_shop; $specific_price->id_country = (int) $rule->id_country; $specific_price->id_currency = (int) $rule->id_currency; $specific_price->id_group = (int) $rule->id_group; $specific_price->from_quantity = (int) $rule->from_quantity; $specific_price->price = (double) $rule->price; $specific_price->reduction_type = $rule->reduction_type; $specific_price->reduction = $rule->reduction_type == 'percentage' ? $rule->reduction / 100 : (double) $rule->reduction; $specific_price->from = $rule->from; $specific_price->to = $rule->to; return $specific_price->add(); }
protected function _getProductIdByDate($beginning, $ending, Context $context = null, $with_combination_id = false, $id_customer = 0, $deal = false) { if (!$context) { $context = Context::getContext(); } $id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; $ids = Address::getCountryAndState($id_address); $id_country = $ids['id_country'] ? (int) $ids['id_country'] : (int) Configuration::get('PS_COUNTRY_DEFAULT'); if (!SpecificPrice::isFeatureActive()) { return array(); } if ($deal == true) { $where = '(`from` = \'0000-00-00 00:00:00\' OR \'' . pSQL($beginning) . '\' >= `from`) AND (`to` != \'0000-00-00 00:00:00\' AND \'' . pSQL($ending) . '\' <= `to`)'; } else { $where = '(`from` = \'0000-00-00 00:00:00\' OR \'' . pSQL($beginning) . '\' >= `from`) AND (`to` = \'0000-00-00 00:00:00\' OR \'' . pSQL($ending) . '\' <= `to`)'; } $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' SELECT `id_product`, `id_product_attribute` FROM `' . _DB_PREFIX_ . 'specific_price` WHERE `id_shop` IN(0, ' . (int) $context->shop->id . ') AND `id_currency` IN(0, ' . (int) $context->currency->id . ') AND `id_country` IN(0, ' . (int) $id_country . ') AND `id_group` IN(0, ' . (int) $context->customer->id_default_group . ') AND `id_customer` IN(0, ' . (int) $id_customer . ') AND `from_quantity` = 1 AND (' . $where . ') AND `reduction` > 0 ', false); $ids_product = array(); while ($row = Db::getInstance()->nextRow($result)) { $ids_product[] = $with_combination_id ? array('id_product' => (int) $row['id_product'], 'id_product_attribute' => (int) $row['id_product_attribute']) : (int) $row['id_product']; } return $ids_product; }
protected function _getProductIdByDate($beginning, $ending, Context $context = null, $with_combination = false) { if (!$context) { $context = Context::getContext(); } $id_address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; $ids = Address::getCountryAndState($id_address); $id_country = (int) ($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT')); return SpecificPrice::getProductIdByDate($context->shop->id, $context->currency->id, $id_country, $context->customer->id_default_group, $beginning, $ending, 0, $with_combination); }
protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups) { global $currentIndex; if (!($obj = $this->loadObject())) { return; } $specificPrices = SpecificPrice::getByProductId((int) $obj->id); $specificPricePriorities = SpecificPrice::getPriority((int) $obj->id); $default_country = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT')); $taxRate = TaxRulesGroup::getTaxesRate($obj->id_tax_rules_group, Configuration::get('PS_COUNTRY_DEFAULT'), 0, 0); $tmp = array(); foreach ($shops as $shop) { $tmp[$shop['id_shop']] = $shop; } $shops = $tmp; $tmp = array(); foreach ($currencies as $currency) { $tmp[$currency['id_currency']] = $currency; } $currencies = $tmp; $tmp = array(); foreach ($countries as $country) { $tmp[$country['id_country']] = $country; } $countries = $tmp; $tmp = array(); foreach ($groups as $group) { $tmp[$group['id_group']] = $group; } $groups = $tmp; echo ' <h4>' . $this->l('Current specific prices') . '</h4> <table style="text-align: center;width:100%" class="table" cellpadding="0" cellspacing="0"> <thead> <tr> <th class="cell border" style="width: 12%;">' . $this->l('Currency') . '</th> <th class="cell border" style="width: 11%;">' . $this->l('Country') . '</th> <th class="cell border" style="width: 13%;">' . $this->l('Group') . '</th> <th class="cell border" style="width: 12%;">' . $this->l('Price') . ' ' . ($default_country->display_tax_label ? $this->l('(tax excl.)') : '') . '</th> <th class="cell border" style="width: 10%;">' . $this->l('Reduction') . '</th> <th class="cell border" style="width: 15%;">' . $this->l('Period') . '</th> <th class="cell border" style="width: 10%;">' . $this->l('From (quantity)') . '</th> <th class="cell border" style="width: 15%;">' . $this->l('Final price') . ' ' . ($default_country->display_tax_label ? $this->l('(tax excl.)') : '') . '</th> <th class="cell border" style="width: 2%;">' . $this->l('Action') . '</th> </tr> </thead> <tbody>'; if (!is_array($specificPrices) or !sizeof($specificPrices)) { echo ' <tr> <td colspan="9">' . $this->l('No specific prices') . '</td> </tr>'; } else { $i = 0; foreach ($specificPrices as $specificPrice) { $current_specific_currency = $currencies[$specificPrice['id_currency'] ? $specificPrice['id_currency'] : $defaultCurrency->id]; if ($specificPrice['reduction_type'] == 'percentage') { $reduction = $specificPrice['reduction'] * 100 . ' %'; } else { $reduction = Tools::displayPrice(Tools::ps_round($specificPrice['reduction'], 2), $current_specific_currency); } if ($specificPrice['from'] == '0000-00-00 00:00:00' and $specificPrice['to'] == '0000-00-00 00:00:00') { $period = $this->l('Unlimited'); } else { $period = $this->l('From') . ' ' . ($specificPrice['from'] != '0000-00-00 00:00:00' ? $specificPrice['from'] : '0000-00-00 00:00:00') . '<br />' . $this->l('To') . ' ' . ($specificPrice['to'] != '0000-00-00 00:00:00' ? $specificPrice['to'] : '0000-00-00 00:00:00'); } echo ' <tr ' . ($i % 2 ? 'class="alt_row"' : '') . '> <td class="cell border">' . ($specificPrice['id_currency'] ? $currencies[$specificPrice['id_currency']]['name'] : $this->l('All currencies')) . '</td> <td class="cell border">' . ($specificPrice['id_country'] ? $countries[$specificPrice['id_country']]['name'] : $this->l('All countries')) . '</td> <td class="cell border">' . ($specificPrice['id_group'] ? $groups[$specificPrice['id_group']]['name'] : $this->l('All groups')) . '</td> <td class="cell border">' . Tools::displayPrice((double) $specificPrice['price'], $current_specific_currency) . '</td> <td class="cell border">' . $reduction . '</td> <td class="cell border">' . $period . '</td> <td class="cell border">' . $specificPrice['from_quantity'] . '</th> <td class="cell border"><b>' . Tools::displayPrice(Tools::ps_round((double) $this->_getFinalPrice($specificPrice, (double) $obj->price, $taxRate), 2), $current_specific_currency) . '</b></td> <td class="cell border"><a href="' . $currentIndex . (Tools::getValue('id_category') ? '&id_category=' . Tools::getValue('id_category') : '') . '&id_product=' . (int) Tools::getValue('id_product') . '&updateproduct&deleteSpecificPrice&id_specific_price=' . (int) $specificPrice['id_specific_price'] . '&token=' . Tools::getValue('token') . '"><img src="../img/admin/delete.gif" alt="' . $this->l('Delete') . '" /></a></td> </tr>'; $i++; } } echo ' </tbody> </table>'; echo ' <script type="text/javascript"> var currencies = new Array(); currencies[0] = new Array(); currencies[0]["sign"] = "' . $defaultCurrency->sign . '"; currencies[0]["format"] = ' . $defaultCurrency->format . '; '; foreach ($currencies as $currency) { echo ' currencies[' . $currency['id_currency'] . '] = new Array(); currencies[' . $currency['id_currency'] . ']["sign"] = "' . $currency['sign'] . '"; currencies[' . $currency['id_currency'] . ']["format"] = ' . $currency['format'] . '; '; } echo ' </script> '; echo ' <hr /> <h4>' . $this->l('Priorities management') . '</h4> <div class="hint clear" style="display:block;"> ' . $this->l('Sometimes one customer could fit in multiple rules, priorities allows you to define which rule to apply.') . ' </div> <br /> <label>' . $this->l('Priorities:') . '</label> <div class="margin-form"> <input type="hidden" name="specificPricePriority[]" value="id_shop" /> <select name="specificPricePriority[]"> <option value="id_currency"' . ($specificPricePriorities[1] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specificPricePriorities[1] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specificPricePriorities[1] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> > <select name="specificPricePriority[]"> <option value="id_currency"' . ($specificPricePriorities[2] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specificPricePriorities[2] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specificPricePriorities[2] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> > <select name="specificPricePriority[]"> <option value="id_currency"' . ($specificPricePriorities[3] == 'id_currency' ? ' selected="selected"' : '') . '>' . $this->l('Currency') . '</option> <option value="id_country"' . ($specificPricePriorities[3] == 'id_country' ? ' selected="selected"' : '') . '>' . $this->l('Country') . '</option> <option value="id_group"' . ($specificPricePriorities[3] == 'id_group' ? ' selected="selected"' : '') . '>' . $this->l('Group') . '</option> </select> </div> <div class="margin-form"> <input type="checkbox" name="specificPricePriorityToAll" id="specificPricePriorityToAll" /> <label class="t" for="specificPricePriorityToAll">' . $this->l('Apply to all products') . '</label> </div> <div class="margin-form"> <input class="button" type="submit" name="submitSpecificPricePriorities" value="' . $this->l('Apply') . '" /> </div> '; }
public static function deleteByProductId($id_product) { if (Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'specific_price` WHERE `id_product` = ' . (int) $id_product)) { // Refresh cache of feature detachable Configuration::updateGlobalValue('PS_SPECIFIC_PRICE_FEATURE_ACTIVE', SpecificPrice::isCurrentlyUsed('specific_price')); return true; } return false; }
protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups) { $lpdesmvcrvu = "specific_price_priorities"; ${"GLOBALS"}["gwvlvnhgf"] = "group"; $plkmtiqjex = "specific_price_priorities"; ${"GLOBALS"}["ertbhqqwavl"] = "tmp"; ${"GLOBALS"}["glybiybrjmv"] = "group"; ${"GLOBALS"}["nihfjn"] = "tmp"; $ivhgohevles = "taxRate"; ${${"GLOBALS"}["nkvjzc"]} = ""; ${"GLOBALS"}["ukanssy"] = "currencies"; if (!$this->object) { return; } ${"GLOBALS"}["tfufwuqnbgxc"] = "tmp"; ${${"GLOBALS"}["ixsaqwcye"]} = SpecificPrice::getByProductId((int) $this->object->id); $rarsexno = "shop"; $vrcmtksat = "shop"; $gedaion = "specific_price_priorities"; ${"GLOBALS"}["xsrbwsm"] = "shops"; ${$lpdesmvcrvu} = SpecificPrice::getPriority((int) $this->object->id); ${$ivhgohevles} = $this->object->getTaxesRate(Address::initialize()); $uhzkmfbqi = "shop"; $ahuedic = "specific_price_priorities"; ${${"GLOBALS"}["bdtyklee"]} = array(); foreach (${${"GLOBALS"}["xsrbwsm"]} as ${$uhzkmfbqi}) { ${${"GLOBALS"}["bdtyklee"]}[${$rarsexno}["id_shop"]] = ${$vrcmtksat}; } $rbdspr = "currencies"; ${"GLOBALS"}["ruiubiwy"] = "countries"; $nyuyhmkcene = "content"; ${${"GLOBALS"}["lazfnitt"]} = ${${"GLOBALS"}["bdtyklee"]}; $hcdvvpbef = "tmp"; $wdrtujtw = "currency"; ${${"GLOBALS"}["nihfjn"]} = array(); foreach (${$rbdspr} as ${${"GLOBALS"}["qwffcfylwvlg"]}) { ${${"GLOBALS"}["bdtyklee"]}[${$wdrtujtw}["id_currency"]] = ${${"GLOBALS"}["qwffcfylwvlg"]}; } ${${"GLOBALS"}["ukanssy"]} = ${${"GLOBALS"}["ertbhqqwavl"]}; ${${"GLOBALS"}["tfufwuqnbgxc"]} = array(); foreach (${${"GLOBALS"}["ruiubiwy"]} as ${${"GLOBALS"}["dtehljxk"]}) { ${${"GLOBALS"}["bdtyklee"]}[${${"GLOBALS"}["dtehljxk"]}["id_country"]] = ${${"GLOBALS"}["dtehljxk"]}; } $tclsxk = "specific_price_priorities"; ${${"GLOBALS"}["kroabu"]} = ${${"GLOBALS"}["bdtyklee"]}; ${$hcdvvpbef} = array(); foreach (${${"GLOBALS"}["myyouyoez"]} as ${${"GLOBALS"}["gwvlvnhgf"]}) { ${${"GLOBALS"}["bdtyklee"]}[${${"GLOBALS"}["oxbcew"]}["id_group"]] = ${${"GLOBALS"}["glybiybrjmv"]}; } ${"GLOBALS"}["cptxpwqsgzo"] = "content"; ${${"GLOBALS"}["myyouyoez"]} = ${${"GLOBALS"}["bdtyklee"]}; if (!is_array(${${"GLOBALS"}["ixsaqwcye"]}) || !count(${${"GLOBALS"}["ixsaqwcye"]})) { ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=\"13\">" . $this->l('No specific prices') . "</td>\n\t\t\t\t</tr>"; } else { ${"GLOBALS"}["ixvreqo"] = "specific_prices"; ${${"GLOBALS"}["eqiehjn"]} = 0; ${"GLOBALS"}["xwjpok"] = "specific_price"; foreach (${${"GLOBALS"}["ixvreqo"]} as ${${"GLOBALS"}["xwjpok"]}) { ${"GLOBALS"}["jgkoendjlpt"] = "specific_price"; $sdpwvfzmwy = "current_specific_currency"; ${"GLOBALS"}["drapxqkxjfw"] = "customer_full_name"; ${"GLOBALS"}["wrefbrz"] = "specific_price"; $ywnqxjizw = "impact"; $pmhlqxsivhg = "currencies"; ${"GLOBALS"}["lnqbpvxxuw"] = "i"; $qndkwpcllv = "specific_price"; ${"GLOBALS"}["cfbvjzjfz"] = "specific_price"; ${"GLOBALS"}["hyijedlreo"] = "specific_price"; ${"GLOBALS"}["bdnvmedpllw"] = "customer_full_name"; ${"GLOBALS"}["yonxxgguvyc"] = "shops"; ${"GLOBALS"}["brpkiqjctz"] = "specific_price"; ${"GLOBALS"}["cubiilo"] = "customer_full_name"; $msgvsejfwpg = "specific_price"; ${"GLOBALS"}["ihxryxdypi"] = "groups"; $frcvwum = "rule"; $fpsxqukp = "price"; ${"GLOBALS"}["ucfgiwdbfvge"] = "period"; ${"GLOBALS"}["pjigladsg"] = "fixed_price"; ${"GLOBALS"}["qrcsyna"] = "specific_price"; $nwumqlplzzwc = "specific_price"; $tihycjulltff = "impact"; ${$sdpwvfzmwy} = ${$pmhlqxsivhg}[${${"GLOBALS"}["oudwfbvcvoj"]}["id_currency"] ? ${${"GLOBALS"}["cfbvjzjfz"]}["id_currency"] : $defaultCurrency->id]; ${"GLOBALS"}["wxttwnsgf"] = "specific_price"; if (${${"GLOBALS"}["oudwfbvcvoj"]}["reduction_type"] == "percentage") { ${$ywnqxjizw} = "- " . ${${"GLOBALS"}["oudwfbvcvoj"]}["reduction"] * 100 . " %"; } elseif (${${"GLOBALS"}["oudwfbvcvoj"]}["reduction"] > 0) { ${${"GLOBALS"}["uaxmvunoy"]} = "- " . Tools::displayPrice(Tools::ps_round(${$nwumqlplzzwc}["reduction"], 2), ${${"GLOBALS"}["lbhedgts"]}); } else { ${$tihycjulltff} = "--"; } ${"GLOBALS"}["nwsoorkiv"] = "impact"; if (${${"GLOBALS"}["jgkoendjlpt"]}["from"] == "0000-00-00 00:00:00" && ${${"GLOBALS"}["oudwfbvcvoj"]}["to"] == "0000-00-00 00:00:00") { ${${"GLOBALS"}["zcpltzs"]} = $this->l('Unlimited'); } else { ${${"GLOBALS"}["zcpltzs"]} = $this->l('From') . " " . (${${"GLOBALS"}["wxttwnsgf"]}["from"] != "0000-00-00 00:00:00" ? ${${"GLOBALS"}["oudwfbvcvoj"]}["from"] : "0000-00-00 00:00:00") . "<br />" . $this->l('To') . " " . (${${"GLOBALS"}["oudwfbvcvoj"]}["to"] != "0000-00-00 00:00:00" ? ${${"GLOBALS"}["oudwfbvcvoj"]}["to"] : "0000-00-00 00:00:00"); } if (${${"GLOBALS"}["oudwfbvcvoj"]}["id_product_attribute"]) { ${"GLOBALS"}["ysyybwjtlnlr"] = "attributes_name"; $supdob = "attributes_name"; $nwznli = "attribute"; ${"GLOBALS"}["ucovwpfrg"] = "specific_price"; $ghrcpselphnv = "combination"; $gyrrgbrm = "attributes"; ${$ghrcpselphnv} = new Combination((int) ${${"GLOBALS"}["ucovwpfrg"]}["id_product_attribute"]); ${$gyrrgbrm} = $combination->getAttributesName((int) $this->context->language->id); ${${"GLOBALS"}["ysyybwjtlnlr"]} = ""; foreach (${${"GLOBALS"}["tecppiwmy"]} as ${${"GLOBALS"}["nmduzbby"]}) { ${${"GLOBALS"}["dkpnrhqmdel"]} .= ${$nwznli}["name"] . " - "; } ${$supdob} = rtrim(${${"GLOBALS"}["dkpnrhqmdel"]}, " - "); } else { ${${"GLOBALS"}["dkpnrhqmdel"]} = $this->l('All combinations'); } $seqiqveynpjq = "specific_price"; ${$frcvwum} = new SpecificPriceRule((int) ${${"GLOBALS"}["oudwfbvcvoj"]}["id_specific_price_rule"]); ${${"GLOBALS"}["qwfludjdg"]} = $rule->id ? $rule->name : "--"; if (${${"GLOBALS"}["oudwfbvcvoj"]}["id_customer"]) { ${"GLOBALS"}["oyqwsagds"] = "customer"; $zdwishb = "customer"; ${${"GLOBALS"}["mcehpjcdvu"]} = new Customer((int) ${${"GLOBALS"}["oudwfbvcvoj"]}["id_customer"]); if (Validate::isLoadedObject(${$zdwishb})) { ${${"GLOBALS"}["valsyupb"]} = $customer->firstname . " " . $customer->lastname; } unset(${${"GLOBALS"}["oyqwsagds"]}); } ${${"GLOBALS"}["judupfn"]} = Tools::ps_round(${$qndkwpcllv}["price"], 2); ${${"GLOBALS"}["pjigladsg"]} = ${${"GLOBALS"}["judupfn"]} == Tools::ps_round($this->object->price, 2) || ${${"GLOBALS"}["oudwfbvcvoj"]}["price"] == -1 ? "--" : Tools::displayPrice(${$fpsxqukp}); ${"GLOBALS"}["rtvaytzbs"] = "specific_price"; ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t\t\t<tr " . (${${"GLOBALS"}["eqiehjn"]} % 2 ? "class=\"alt_row\"" : "") . ">\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["qwfludjdg"]} . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["dkpnrhqmdel"]} . "</td>\n\t\t\t\t\t" . (Shop::isFeatureActive() ? "<td class=\"cell border\">" . (${${"GLOBALS"}["rtvaytzbs"]}["id_shop"] ? ${${"GLOBALS"}["yonxxgguvyc"]}[${$msgvsejfwpg}["id_shop"]]["name"] : $this->l('All shops')) . "</td>" : "") . "\n\t\t\t\t\t<td class=\"cell border\">" . (${${"GLOBALS"}["oudwfbvcvoj"]}["id_currency"] ? ${${"GLOBALS"}["qeyondtkko"]}[${$seqiqveynpjq}["id_currency"]]["name"] : $this->l('All currencies')) . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . (${${"GLOBALS"}["oudwfbvcvoj"]}["id_country"] ? ${${"GLOBALS"}["kroabu"]}[${${"GLOBALS"}["wrefbrz"]}["id_country"]]["name"] : $this->l('All countries')) . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . (${${"GLOBALS"}["brpkiqjctz"]}["id_group"] ? ${${"GLOBALS"}["ihxryxdypi"]}[${${"GLOBALS"}["oudwfbvcvoj"]}["id_group"]]["name"] : $this->l('All groups')) . "</td>\n\t\t\t\t\t<td class=\"cell border\" title=\"" . $this->l('ID:') . " " . ${${"GLOBALS"}["oudwfbvcvoj"]}["id_customer"] . "\">" . (isset(${${"GLOBALS"}["cubiilo"]}) ? ${${"GLOBALS"}["bdnvmedpllw"]} : $this->l('All customers')) . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["ojfggiuyn"]} . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["nwsoorkiv"]} . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["ucfgiwdbfvge"]} . "</td>\n\t\t\t\t\t<td class=\"cell border\">" . ${${"GLOBALS"}["hyijedlreo"]}["from_quantity"] . "</th>\n\t\t\t\t\t<td class=\"cell border\">" . (!$rule->id ? "<a name=\"delete_link\" href=\"" . __PS_BASE_URI__ . "modules/agilemultipleseller/ajax_products.php?action=DeleteSpecificPrice&id_product=" . $this->id_object . "&id_specific_price=" . (int) ${${"GLOBALS"}["qrcsyna"]}["id_specific_price"] . "\"><img src=\"" . __PS_BASE_URI__ . "img/admin/delete.gif\" alt=\"" . $this->l('Delete') . "\" /></a>" : "") . "</td>\n\t\t\t\t</tr>"; ${${"GLOBALS"}["lnqbpvxxuw"]}++; unset(${${"GLOBALS"}["drapxqkxjfw"]}); } } $dvylzfofp = "currency"; ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t\t\t</tbody>\n\t\t\t</table>\n\t\t</div>"; ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t<script type=\"text/javascript\">\n\t\t\tvar currencies = new Array();\n\t\t\tcurrencies[0] = new Array();\n\t\t\tcurrencies[0][\"sign\"] = \"" . $defaultCurrency->sign . "\";\n\t\t\tcurrencies[0][\"format\"] = " . $defaultCurrency->format . ";\n\t\t\t"; foreach (${${"GLOBALS"}["qeyondtkko"]} as ${$dvylzfofp}) { ${"GLOBALS"}["orynunkni"] = "currency"; $glvdhrwfpl = "currency"; $dnugvdxrefxp = "currency"; $jtxjbwyjntp = "content"; $gocuffop = "currency"; ${$jtxjbwyjntp} .= "\n\t\t\t\tcurrencies[" . ${$glvdhrwfpl}["id_currency"] . "] = new Array();\n\t\t\t\tcurrencies[" . ${${"GLOBALS"}["orynunkni"]}["id_currency"] . "][\"sign\"] = \"" . ${${"GLOBALS"}["qwffcfylwvlg"]}["sign"] . "\";\n\t\t\t\tcurrencies[" . ${$dnugvdxrefxp}["id_currency"] . "][\"format\"] = " . ${$gocuffop}["format"] . ";\n\t\t\t\t"; } ${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t</script>\n\t\t"; $djpchkks = "specific_price_priorities"; ${"GLOBALS"}["bkvknwhmmk"] = "specific_price_priorities"; $pecvkmoo = "specific_price_priorities"; ${"GLOBALS"}["csovwwlu"] = "specific_price_priorities"; if (${$plkmtiqjex}[0] == "id_customer") { unset(${$djpchkks}[0]); } ${${"GLOBALS"}["tupdle"]} = array_values(${${"GLOBALS"}["tupdle"]}); ${$nyuyhmkcene} .= "<div id=\"agile\"class=\"panel\">\n\t\t<h3>" . $this->l('Priority management') . "</h3>\n\t\t<div class=\"alert alert-info\">\n\t\t\t\t" . $this->l('Sometimes one customer can fit into multiple price rules. Priorities allow you to define which rule applies to the customer.') . "\n\t\t</div>"; ${${"GLOBALS"}["cptxpwqsgzo"]} .= "\n\t\t<div class=\"form-group\">\n\t\t\t<label class=\"control-label agile-col-sm-3 agile-col-md-3 agile-col-lg-3 agile-col-xl-3\" for=\"specificPricePriority1\">" . $this->l('Priorities:') . "</label>\n\t\t\t<div class=\"input-group agile-col-sm-9 agile-col-md9 col-lg-9 agile-col-xl-9\">\n\t\t\t\t<select id=\"specificPricePriority1\" name=\"specificPricePriority[]\">\n\t\t\t\t\t<option value=\"id_shop\"" . (${${"GLOBALS"}["tupdle"]}[0] == "id_shop" ? " selected=\"selected\"" : "") . ">" . $this->l('Shop') . "</option>\n\t\t\t\t\t<option value=\"id_currency\"" . (${$gedaion}[0] == "id_currency" ? " selected=\"selected\"" : "") . ">" . $this->l('Currency') . "</option>\n\t\t\t\t\t<option value=\"id_country\"" . (${${"GLOBALS"}["tupdle"]}[0] == "id_country" ? " selected=\"selected\"" : "") . ">" . $this->l('Country') . "</option>\n\t\t\t\t\t<option value=\"id_group\"" . (${${"GLOBALS"}["tupdle"]}[0] == "id_group" ? " selected=\"selected\"" : "") . ">" . $this->l('Group') . "</option>\n\t\t\t\t</select>\n\t\t\t\t<span class=\"input-group-addon\"><i class=\"icon-chevron-right\"></i></span>\n\t\t\t\t<select name=\"specificPricePriority[]\">\n\t\t\t\t\t<option value=\"id_shop\"" . (${$pecvkmoo}[1] == "id_shop" ? " selected=\"selected\"" : "") . ">" . $this->l('Shop') . "</option>\n\t\t\t\t\t<option value=\"id_currency\"" . (${${"GLOBALS"}["csovwwlu"]}[1] == "id_currency" ? " selected=\"selected\"" : "") . ">" . $this->l('Currency') . "</option>\n\t\t\t\t\t<option value=\"id_country\"" . (${${"GLOBALS"}["tupdle"]}[1] == "id_country" ? " selected=\"selected\"" : "") . ">" . $this->l('Country') . "</option>\n\t\t\t\t\t<option value=\"id_group\"" . (${${"GLOBALS"}["tupdle"]}[1] == "id_group" ? " selected=\"selected\"" : "") . ">" . $this->l('Group') . "</option>\n\t\t\t\t</select>\n\t\t\t\t<span class=\"input-group-addon\"><i class=\"icon-chevron-right\"></i></span>\n\t\t\t\t<select name=\"specificPricePriority[]\">\n\t\t\t\t\t<option value=\"id_shop\"" . (${${"GLOBALS"}["tupdle"]}[2] == "id_shop" ? " selected=\"selected\"" : "") . ">" . $this->l('Shop') . "</option>\n\t\t\t\t\t<option value=\"id_currency\"" . (${${"GLOBALS"}["tupdle"]}[2] == "id_currency" ? " selected=\"selected\"" : "") . ">" . $this->l('Currency') . "</option>\n\t\t\t\t\t<option value=\"id_country\"" . (${${"GLOBALS"}["tupdle"]}[2] == "id_country" ? " selected=\"selected\"" : "") . ">" . $this->l('Country') . "</option>\n\t\t\t\t\t<option value=\"id_group\"" . (${${"GLOBALS"}["tupdle"]}[2] == "id_group" ? " selected=\"selected\"" : "") . ">" . $this->l('Group') . "</option>\n\t\t\t\t</select>\n\t\t\t\t<span class=\"input-group-addon\"><i class=\"icon-chevron-right\"></i></span>\n\t\t\t\t<select name=\"specificPricePriority[]\">\n\t\t\t\t\t<option value=\"id_shop\"" . (${${"GLOBALS"}["bkvknwhmmk"]}[3] == "id_shop" ? " selected=\"selected\"" : "") . ">" . $this->l('Shop') . "</option>\n\t\t\t\t\t<option value=\"id_currency\"" . (${$ahuedic}[3] == "id_currency" ? " selected=\"selected\"" : "") . ">" . $this->l('Currency') . "</option>\n\t\t\t\t\t<option value=\"id_country\"" . (${${"GLOBALS"}["tupdle"]}[3] == "id_country" ? " selected=\"selected\"" : "") . ">" . $this->l('Country') . "</option>\n\t\t\t\t\t<option value=\"id_group\"" . (${$tclsxk}[3] == "id_group" ? " selected=\"selected\"" : "") . ">" . $this->l('Group') . "</option>\n\t\t\t\t</select>\n\t\t\t</div>\n\t\t</div>\n\t\t<div class=\"form-group\">\n\t\t\t<div class=\" agile-col-sm-9 agile-sm-offset-3 agile-col-md-9 agile-md-offset-3 col-lg-9 col-lg-offset-3 agile-col-xl-9 agile-xl-ooffset-3\">\n\t\t\t\t<p class=\"checkbox\">\n\t\t\t\t\t<label for=\"specificPricePriorityToAll\"><input type=\"checkbox\" name=\"specificPricePriorityToAll\" id=\"specificPricePriorityToAll\" />" . $this->l('Apply to all products') . "</label>\n\t\t\t\t</p>\n\t\t\t</div>\n\t\t</div>\n\t\t</div>\n\t\t"; return ${${"GLOBALS"}["nkvjzc"]}; }