当前位置: 首页>>代码示例>>PHP>>正文


PHP StockAvailable::setQuantity方法代码示例

本文整理汇总了PHP中StockAvailable::setQuantity方法的典型用法代码示例。如果您正苦于以下问题:PHP StockAvailable::setQuantity方法的具体用法?PHP StockAvailable::setQuantity怎么用?PHP StockAvailable::setQuantity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StockAvailable的用法示例。


在下文中一共展示了StockAvailable::setQuantity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: processGenerate

 public function processGenerate()
 {
     if (!is_array(Tools::getValue('options'))) {
         $this->errors[] = Tools::displayError('Please select at least one attribute.');
     } else {
         $tab = array_values(Tools::getValue('options'));
         if (count($tab) && Validate::isLoadedObject($this->product)) {
             AdminAttributeGeneratorController::setAttributesImpacts($this->product->id, $tab);
             $this->combinations = array_values(AdminAttributeGeneratorController::createCombinations($tab));
             $values = array_values(array_map(array($this, 'addAttribute'), $this->combinations));
             // @since 1.5.0
             if ($this->product->depends_on_stock == 0) {
                 $attributes = Product::getProductAttributesIds($this->product->id, true);
                 foreach ($attributes as $attribute) {
                     StockAvailable::removeProductFromStockAvailable($this->product->id, $attribute['id_product_attribute'], Context::getContext()->shop);
                 }
             }
             SpecificPriceRule::disableAnyApplication();
             $this->product->deleteProductAttributes();
             $this->product->generateMultipleCombinations($values, $this->combinations);
             // @since 1.5.0
             if ($this->product->depends_on_stock == 0) {
                 $attributes = Product::getProductAttributesIds($this->product->id, true);
                 $quantity = str_replace(',', '.', Tools::getValue('quantity'));
                 foreach ($attributes as $attribute) {
                     StockAvailable::setQuantity($this->product->id, $attribute['id_product_attribute'], $quantity);
                 }
             } else {
                 StockAvailable::synchronize($this->product->id);
             }
             SpecificPriceRule::enableAnyApplication();
             SpecificPriceRule::applyAllRules(array((int) $this->product->id));
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts') . '&id_product=' . (int) Tools::getValue('id_product') . '&updateproduct&key_tab=Combinations&conf=4');
         } else {
             $this->errors[] = Tools::displayError('Unable to initialize these parameters. A combination is missing or an object cannot be loaded.');
         }
     }
 }
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:38,代码来源:AdminAttributeGeneratorController.php

示例2: ajaxProcessProductQuantity

 public function ajaxProcessProductQuantity()
 {
     if ($this->tabAccess['edit'] === '0') {
         return die(Tools::jsonEncode(array('error' => $this->l('You do not have the right permission'))));
     }
     if (!Tools::getValue('actionQty')) {
         return Tools::jsonEncode(array('error' => $this->l('Undefined action')));
     }
     $product = new Product((int) Tools::getValue('id_product'), true);
     switch (Tools::getValue('actionQty')) {
         case 'depends_on_stock':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if ((int) Tools::getValue('value') != 0 && (int) Tools::getValue('value') != 1) {
                 die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
             }
             if (!$product->advanced_stock_management && (int) Tools::getValue('value') == 1) {
                 die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. '))));
             }
             if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) Tools::getValue('value') == 1 && (Pack::isPack($product->id) && !Pack::allUsesAdvancedStockManagement($product->id) && ($product->pack_stock_type == 2 || $product->pack_stock_type == 1 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)))) {
                 die(Tools::jsonEncode(array('error' => $this->l('You cannot use advanced stock management for this pack because') . '<br />' . $this->l('- advanced stock management is not enabled for these products') . '<br />' . $this->l('- you have chosen to decrement products quantities.'))));
             }
             StockAvailable::setProductDependsOnStock($product->id, (int) Tools::getValue('value'));
             break;
         case 'pack_stock_type':
             $value = Tools::getValue('value');
             if ($value === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if ((int) $value != 0 && (int) $value != 1 && (int) $value != 2 && (int) $value != 3) {
                 die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
             }
             if ($product->depends_on_stock && !Pack::allUsesAdvancedStockManagement($product->id) && ((int) $value == 1 || (int) $value == 2 || (int) $value == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2))) {
                 die(Tools::jsonEncode(array('error' => $this->l('You cannot use this stock management option because:') . '<br />' . $this->l('- advanced stock management is not enabled for these products') . '<br />' . $this->l('- advanced stock management is enabled for the pack'))));
             }
             Product::setPackStockType($product->id, $value);
             break;
         case 'out_of_stock':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if (!in_array((int) Tools::getValue('value'), array(0, 1, 2))) {
                 die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
             }
             StockAvailable::setProductOutOfStock($product->id, (int) Tools::getValue('value'));
             break;
         case 'set_qty':
             if (Tools::getValue('value') === false || !is_numeric(trim(Tools::getValue('value')))) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if (Tools::getValue('id_product_attribute') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined id product attribute'))));
             }
             StockAvailable::setQuantity($product->id, (int) Tools::getValue('id_product_attribute'), (int) Tools::getValue('value'));
             Hook::exec('actionProductUpdate', array('id_product' => (int) $product->id, 'product' => $product));
             // Catch potential echo from modules
             $error = ob_get_contents();
             if (!empty($error)) {
                 ob_end_clean();
                 die(Tools::jsonEncode(array('error' => $error)));
             }
             break;
         case 'advanced_stock_management':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if ((int) Tools::getValue('value') != 1 && (int) Tools::getValue('value') != 0) {
                 die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
             }
             if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) Tools::getValue('value') == 1) {
                 die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. '))));
             }
             $product->setAdvancedStockManagement((int) Tools::getValue('value'));
             if (StockAvailable::dependsOnStock($product->id) == 1 && (int) Tools::getValue('value') == 0) {
                 StockAvailable::setProductDependsOnStock($product->id, 0);
             }
             break;
     }
     die(Tools::jsonEncode(array('error' => false)));
 }
开发者ID:Rohit-jn,项目名称:hotelcommerce,代码行数:81,代码来源:AdminProductsController.php

示例3: addProductAttribute

 /**
  * addProductAttribute is deprecated
  *
  * The quantity params now set StockAvailable for the current shop with the specified quantity
  * The supplier_reference params now set the supplier reference of the default supplier of the product if possible
  *
  * @see StockManager if you want to manage real stock
  * @see StockAvailable if you want to manage available quantities for sale on your shop(s)
  * @see ProductSupplier for manage supplier reference(s)
  *
  * @deprecated since 1.5.0
  */
 public function addProductAttribute($price, $weight, $unit_impact, $ecotax, $quantity, $id_images, $reference, $id_supplier = null, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1)
 {
     Tools::displayAsDeprecated();
     $id_product_attribute = $this->addAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $ean13, $default, $location, $upc, $minimal_quantity);
     if (!$id_product_attribute) {
         return false;
     }
     StockAvailable::setQuantity($this->id, $id_product_attribute, $quantity);
     //Try to set the default supplier reference
     $this->addSupplierReference($id_supplier, $id_product_attribute);
     return $id_product_attribute;
 }
开发者ID:jicheng17,项目名称:vipinsg,代码行数:24,代码来源:Product.php

示例4: processSaveProduct

 private function processSaveProduct()
 {
     // die('<pre>' . print_r($_POST, true));
     // Address 2 and city
     /*$_POST['address2_2'] = $_POST['address2_1'];
      	$_POST['city_2'] = $_POST['city_1'];*/
     $dateNow = date('ymdhis');
     ${"GLOBALS"}["ndtbxrwjprt"] = "limit";
     ${"GLOBALS"}["tpztaib"] = "id_default_lang";
     if ($this->id_object == 0 and empty($_POST["link_rewrite_" . $this->id_language])) {
         $_POST["link_rewrite_" . $this->id_language] = $dateNow;
     }
     $_POST["link_rewrite_" . 1] = $dateNow;
     $_POST["link_rewrite_" . 2] = $dateNow;
     // $_POST["link_rewrite_" . $this->id_language] = Tools::link_rewrite($_POST["name_" . $this->id_language]);
     if ($this->id_language != 1) {
         $this->updateProductLangTableToEng();
     } else {
         $this->updateProductLangTableToOther();
     }
     if (empty($_POST['address_1'])) {
         $_POST['address_1'] = " ";
     }
     // die('<pre>' . print_r($_POST, true));
     ${${"GLOBALS"}["vqjtbm"]} = intval(Configuration::get("PS_LANG_DEFAULT"));
     if (${${"GLOBALS"}["tpztaib"]} != $this->id_language) {
         $rdapymdhyc = "id_default_lang";
         if (empty($_POST["link_rewrite_" . ${$rdapymdhyc}])) {
             $_POST["link_rewrite_" . ${${"GLOBALS"}["vqjtbm"]}] = $_POST["link_rewrite_" . $this->id_language];
         }
         if (empty($_POST["name_" . ${${"GLOBALS"}["vqjtbm"]}])) {
             $_POST["name_" . ${${"GLOBALS"}["vqjtbm"]}] = $_POST["name_" . $this->id_language];
         }
     }
     $this->copyFromPost($this->object, $this->table);
     $this->object->online_only = (int) Tools::getValue("online_only");
     $this->object->available_for_order = (int) Tools::getValue("available_for_order");
     $this->object->show_price = (int) Tools::getValue("show_price");
     if ($this->object->available_for_order) {
         $this->object->show_price = 1;
     }
     ${"GLOBALS"}["jcohmkpwkls"] = "limit";
     ${${"GLOBALS"}["pfkeshhubw"]} = (int) Configuration::get("PS_PRODUCT_SHORT_DESC_LIMIT");
     if (${${"GLOBALS"}["ndtbxrwjprt"]} <= 0) {
         ${${"GLOBALS"}["jcohmkpwkls"]} = 800;
     }
     if (strlen($this->object->description_short[$this->id_language]) > ${${"GLOBALS"}["pfkeshhubw"]}) {
         $this->errors[] = Tools::displayError("Short description is too long");
         return;
     }
     $this->validateRules();
     if (count($this->errors) > 0) {
         return;
     }
     if ($this->id_object <= 0) {
         $this->beforeAdd($this->object);
         if (method_exists($this->object, "add") && !$this->object->add()) {
             $this->errors[] = Tools::displayError("An error occurred while creating object.") . " <b>" . $this->table . " (" . Db::getInstance()->getMsgError() . ")</b>";
             return;
         }
         $qnkriesy = "languages";
         AgileSellerManager::assignObjectOwner("product", $this->object->id, $_POST["id_seller"]);
         $this->afterAdd($this->object);
         $this->updateAssoShop($this->object->id);
         StockAvailable::setQuantity($this->object->id, 0, (int) Tools::getValue("quantity"));
         $this->updateDefaultCategory($this->object->id_category_default, $this->object->id);
         Hook::exec("actionProductAdd", array("product" => $this->object));
         ${${"GLOBALS"}["emgichjdg"]} = Language::getLanguages(false);
         $this->updateTags(${$qnkriesy}, $this->object);
         $this->id_object = $this->object->id;
         $this->object = $this->agileLoadProduct($this->id_object, true);
     } else {
         if (method_exists($this->object, "update") && !$this->object->update()) {
             $this->errors[] = Tools::displayError("An error occurred while updating object.") . " <b>" . $this->table . " (" . Db::getInstance()->getMsgError() . ")</b>";
             return;
         }
         StockAvailable::setQuantity($this->object->id, 0, (int) Tools::getValue("quantity"));
         $this->updateDefaultCategory($this->object->id_category_default, $this->object->id);
         Hook::exec("actionProductUpdate", array("product" => $this->object));
         ${${"GLOBALS"}["emgichjdg"]} = Language::getLanguages(false);
         $this->updateTags(${${"GLOBALS"}["emgichjdg"]}, $this->object);
         $this->object = $this->agileLoadProduct($this->id_object, true);
         $this->afterUpdate($this->object);
     }
     if ($this->object->id_supplier > 0) {
         $this->object->addSupplierReference($this->object->id_supplier, 0);
     }
     /*  die('<pre>' . print_r($this->object, true));
         if($this->id_object == 0)
         	Tools::redirect('en');*/
 }
开发者ID:ecssjapan,项目名称:guiding-you-afteropen,代码行数:91,代码来源:sellerproductdetailbase.php

示例5: ajaxProcessProductQuantity

 public function ajaxProcessProductQuantity()
 {
     if (!Tools::getValue('actionQty')) {
         return Tools::jsonEncode(array('error' => $this->l('Undefined action')));
     }
     $product = new Product((int) Tools::getValue('id_product'), true);
     switch (Tools::getValue('actionQty')) {
         case 'depends_on_stock':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if ((int) Tools::getValue('value') != 0 && (int) Tools::getValue('value') != 1) {
                 die(Tools::jsonEncode(array('error' => $this->l('Uncorrect value'))));
             }
             if (!$product->advanced_stock_management && (int) Tools::getValue('value') == 1) {
                 die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is not enabled'))));
             }
             if ($product->advanced_stock_management && Pack::isPack($product->id)) {
                 die(Tools::jsonEncode(array('error' => $this->l('Not possible if the product is a pack'))));
             }
             StockAvailable::setProductDependsOnStock($product->id, (int) Tools::getValue('value'));
             break;
         case 'out_of_stock':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if (!in_array((int) Tools::getValue('value'), array(0, 1, 2))) {
                 die(Tools::jsonEncode(array('error' => $this->l('Uncorrect value'))));
             }
             StockAvailable::setProductOutOfStock($product->id, (int) Tools::getValue('value'));
             break;
         case 'set_qty':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if (Tools::getValue('id_product_attribute') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined id product attribute'))));
             }
             StockAvailable::setQuantity($product->id, (int) Tools::getValue('id_product_attribute'), (int) Tools::getValue('value'));
             break;
         case 'advanced_stock_management':
             if (Tools::getValue('value') === false) {
                 die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
             }
             if ((int) Tools::getValue('value') != 1 && (int) Tools::getValue('value') != 0) {
                 die(Tools::jsonEncode(array('error' => $this->l('Uncorrect value'))));
             }
             if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) Tools::getValue('value') == 1) {
                 die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is not enabled'))));
             }
             if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && Pack::isPack($product->id)) {
                 die(Tools::jsonEncode(array('error' => $this->l('Not possible if the product is a pack'))));
             }
             $product->setAdvancedStockManagement((int) Tools::getValue('value'));
             if (StockAvailable::dependsOnStock($product->id) == 1 && (int) Tools::getValue('value') == 0) {
                 StockAvailable::setProductDependsOnStock($product->id, 0);
             }
             break;
     }
     die(Tools::jsonEncode(array('error' => false)));
 }
开发者ID:jicheng17,项目名称:pengwine,代码行数:61,代码来源:AdminProductsController.php

示例6: createOrderDetails


//.........这里部分代码省略.........
                    if (!empty($res_product['attribute_name'])) {
                        $name .= ' - ' . $res_product['attribute_name'];
                    }
                    $control_attribute_product = true;
                }
                // Add product in cart
                $order = new Order($id_order);
                if (!Db::getInstance()->getRow('SELECT `id_cart` FROM `' . _DB_PREFIX_ . 'cart_product` WHERE `id_cart` = ' . (int) $order->id_cart . ' AND `id_product` = ' . (int) $res_product['id_product'] . ' AND `id_product_attribute` = ' . (int) $id_product_attribute)) {
                    Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'cart_product` (`id_cart`, `id_product`, `id_product_attribute`, `quantity`, `date_add`) VALUES (' . (int) $order->id_cart . ', ' . (int) $res_product['id_product'] . ', ' . (int) $id_product_attribute . ', ' . (int) $neteven_order->Quantity . ', "' . pSQL($date_now) . '")');
                }
                if ($this->time_analyse) {
                    $this->current_time_0 = time();
                    Toolbox::displayDebugMessage(self::getL('Order information') . ' : ' . ((int) $this->current_time_0 - (int) $this->current_time_2) . 's');
                }
                // Add order detail
                $tax = new Tax(Configuration::get('PS_TAX'), $cookie->id_lang);
                $price_product = ($neteven_order->Price->_ - floatval($neteven_order->VAT->_)) / $neteven_order->Quantity;
                $order_detail = new OrderDetail();
                $order_detail->id_order = $id_order;
                $order_detail->product_id = $res_product['id_product'];
                $order_detail->product_attribute_id = $id_product_attribute;
                $order_detail->product_name = $name;
                $order_detail->product_quantity = $neteven_order->Quantity;
                $order_detail->product_quantity_in_stock = $neteven_order->Quantity;
                $order_detail->product_quantity_refunded = 0;
                $order_detail->product_quantity_return = 0;
                $order_detail->product_quantity_reinjected = 0;
                $order_detail->product_price = number_format((double) $price_product, 4, '.', '');
                $order_detail->total_price_tax_excl = number_format((double) $price_product, 4, '.', '');
                $order_detail->unit_price_tax_incl = number_format((double) $price_product, 4, '.', '');
                $order_detail->unit_price_tax_excl = $tax->rate ? number_format((double) $price_product / ((double) $tax->rate / 100), 4, '.', '') : $price_product;
                $order_detail->reduction_percent = 0;
                $order_detail->reduction_amount = 0;
                $order_detail->group_reduction = 0;
                $order_detail->product_quantity_discount = 0;
                $order_detail->product_ean13 = NULL;
                $order_detail->product_upc = NULL;
                $order_detail->product_reference = $product_reference;
                $order_detail->product_supplier_reference = NULL;
                $order_detail->product_weight = !empty($res_product['weight']) ? (double) $res_product['weight'] : 0;
                $order_detail->tax_name = $tax->name;
                $order_detail->tax_rate = (double) $tax->rate;
                $order_detail->ecotax = 0;
                $order_detail->ecotax_tax_rate = 0;
                $order_detail->discount_quantity_applied = 0;
                $order_detail->download_hash = '';
                $order_detail->download_nb = 0;
                $order_detail->download_deadline = '0000-00-00 00:00:00';
                $order_detail->id_warehouse = 0;
                if (Configuration::get('PS_SHOP_ENABLE')) {
                    $order_detail->id_shop = (int) Configuration::get('PS_SHOP_DEFAULT');
                }
                if (!$order_detail->add()) {
                    Toolbox::addLogLine(self::getL('Failed for creation of order detail / NetEven Order Id') . ' ' . (int) $neteven_order->OrderID . ' ' . self::getL('NetEven order detail id') . ' ' . $neteven_order->OrderLineID);
                } else {
                    if ($this->time_analyse) {
                        $this->current_time_2 = time();
                        Toolbox::displayDebugMessage(self::getL('Order detail') . ' : ' . ((int) $this->current_time_2 - (int) $this->current_time_0) . 's');
                    }
                    $id_order_detail_temp = $order_detail->id;
                    Toolbox::addLogLine(self::getL('Creation of order detail for NetEven order Id') . ' ' . (int) $neteven_order->OrderID . ' ' . self::getL('NetEven order detail id') . ' ' . (int) $neteven_order->OrderLineID);
                    // Update quantity of product
                    if (class_exists('StockAvailable')) {
                        // Update quantity of product
                        if ($control_attribute_product) {
                            StockAvailable::setQuantity($res_product['id_product'], $id_product_attribute, StockAvailable::getQuantityAvailableByProduct($res_product['id_product'], $id_product_attribute) - $neteven_order->Quantity);
                        } else {
                            StockAvailable::setQuantity($res_product['id_product'], 0, StockAvailable::getQuantityAvailableByProduct($res_product['id_product']) - $neteven_order->Quantity);
                        }
                    } else {
                        $t_info_product = array();
                        $t_info_product['id_product'] = $res_product["id_product"];
                        $t_info_product['cart_quantity'] = $neteven_order->Quantity;
                        $t_info_product['id_product_attribute'] = NULL;
                        if ($control_attribute_product) {
                            $t_info_product['id_product_attribute'] = $id_product_attribute;
                        }
                        Product::updateQuantity($t_info_product);
                    }
                    if ($this->time_analyse) {
                        $this->current_time_0 = time();
                        Toolbox::displayDebugMessage(self::getL('Cart product') . ' : ' . ((int) $this->current_time_0 - (int) $this->current_time_2) . 's');
                    }
                    // Insert order in orders_gateway table
                    if (!Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'orders_gateway` (`id_order_neteven`, `id_order`, `id_order_detail_neteven`, `date_add`, `date_upd`) VALUES (' . (int) $neteven_order->OrderID . ', ' . (int) $id_order . ', ' . (int) $neteven_order->OrderLineID . ', "' . pSQL($date_now) . '", "' . pSQL($date_now) . '")')) {
                        Toolbox::addLogLine(self::getL('Failed for save export NetEven order Id') . ' ' . (int) $neteven_order->OrderID . ' ' . self::getL('NetEven order detail id') . ' ' . (int) $neteven_order->OrderLineID);
                    } else {
                        Toolbox::addLogLine(self::getL('Save export NetEven order Id') . ' ' . (int) $neteven_order->OrderID . ' ' . self::getL('NetEven order detail id') . ' ' . (int) $neteven_order->OrderLineID);
                    }
                }
            }
        } else {
            Toolbox::addLogLine(self::getL('Failed for creation of order detail of NetEven order Id') . $neteven_order->OrderID . ' ' . self::getL('NetEven order detail id') . ' ' . $neteven_order->OrderLineID . ' ' . self::getL('Product not found SKU') . ' ' . $neteven_order->SKU);
        }
        $order = new Order($id_order);
        $products = $order->getProductsDetail();
        if (count($products) == 0 && $this->getValue('mail_active')) {
            $this->sendDebugMail($this->getValue('mail_list_alert'), self::getL('Order imported is empty'), self::getL('Order Id') . ' ' . (int) $order->id);
        }
    }
开发者ID:juniorhq88,项目名称:PrestaShop-modules,代码行数:101,代码来源:GatewayOrder.php

示例7: importProducts

 protected function importProducts()
 {
     $this->truncateTables(array('product', 'product_lang', 'product_shop', 'product_sale', 'product_supplier', 'product_tag', 'feature_product', 'category_product', 'product_carrier', 'compare_product', 'product_attachment', 'product_country_tax', 'product_download', 'product_group_reduction_cache', 'scene_products', 'warehouse_product_location', 'customization', 'customization_field', 'customization_field_lang', 'supply_order_detail', 'attribute_impact', 'pack'));
     $handle = $this->openCsvFile('products.csv');
     $languages = Language::getLanguages(false);
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $product = new Product((int) $line[0]);
         $product->id = (int) $line[0];
         $product->active = $line[1];
         foreach ($languages as $lang) {
             $product->name[$lang['id_lang']] = $line['2'];
         }
         $categories = explode(',', $line[3]);
         $product->id_category_default = $categories[0] ? $categories[0] : Configuration::get('PS_HOME_CATEGORY');
         if (isset($categories) && $categories && count($categories)) {
             $product->addToCategories($categories);
         }
         if (isset($line[4])) {
             $product->price_tex = $line[4];
         }
         if (isset($line[5])) {
             $product->price_tin = $line[5];
         }
         $product->id_tax_rules_group = trim($line[6]) ? $line[6] : 0;
         $product->wholesale_price = trim($line[7]) ? $line[7] : 0;
         $product->on_sale = trim($line[8]) ? $line[8] : 0;
         if (trim($line[13])) {
             $product->reference = $line[13];
         }
         if (trim($line[14])) {
             $product->supplier_reference = trim($line[14]);
         }
         if (trim($line[15])) {
             $product->id_supplier = (int) $line[15];
         }
         if (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();
         }
         if (trim($line[16])) {
             $product->id_manufacturer = $line[16];
         }
         if (!Tools::isEmpty(trim($line[17]))) {
             $product->ean13 = $line[17];
         }
         if (trim($line[18])) {
             $product->upc = $line[18];
         }
         if (trim($line[19])) {
             $product->ecotax = $line[19];
         }
         $product->width = $line[20];
         $product->height = $line[21];
         $product->depth = $line[22];
         $product->weight = $line[23];
         if ($line[24]) {
             StockAvailable::setQuantity((int) $product->id, 0, (int) $line[24], (int) $this->context->shop->id);
         }
         $product->minimal_quantity = $line[25];
         $product->visibility = $line[26];
         $product->additional_shipping_cost = $line[27];
         if (trim($line[28])) {
             $product->unity = $line[28];
         }
         if (trim($line[29])) {
             $product->unit_price = $line[29];
         }
         foreach ($languages as $lang) {
             $product->description_short[$lang['id_lang']] = $line[30];
             $product->description[$lang['id_lang']] = $line[31];
         }
         if ($line[32]) {
             foreach ($languages as $lang) {
                 Tag::addTags($lang['id_lang'], $product->id, $line[32]);
             }
         }
         foreach ($languages as $lang) {
             $product->meta_title[$lang['id_lang']] = $line[33];
             $product->meta_keywords[$lang['id_lang']] = $line[34];
             $product->meta_description[$lang['id_lang']] = $line[35];
             $product->link_rewrite[$lang['id_lang']] = $line[36];
             $product->available_now[$lang['id_lang']] = $line[37];
             $product->available_later[$lang['id_lang']] = $line[38];
         }
         $product->available_for_order = $line[39];
         $product->available_date = $line[40];
         $product->date_add = $line[41];
         $product->show_price = $line[42];
         // Features import
//.........这里部分代码省略.........
开发者ID:evgrishin,项目名称:se1614,代码行数:101,代码来源:AdminSampleDataInstallImport.php

示例8: ajaxProcessProductQuantity

function ajaxProcessProductQuantity()
{
    $kvfqwksjfmi = "product";
    if (!Tools::getValue("actionQty")) {
        return Tools::jsonEncode(array("error" => Tools::displayError("Undefined action")));
    }
    ${$kvfqwksjfmi} = new Product((int) Tools::getValue("id_product"));
    switch (Tools::getValue("actionQty")) {
        case "depends_on_stock":
            if (Tools::getValue("value") === false) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Undefined value")));
            }
            if ((int) Tools::getValue("value") != 0 && (int) Tools::getValue("value") != 1) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Uncorrect value")));
            }
            if (!$product->advanced_stock_management && (int) Tools::getValue("value") == 1) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Not possible if advanced stock management is not enabled")));
            }
            if ($product->advanced_stock_management && Pack::isPack($product->id)) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Not possible if the product is a pack")));
            }
            StockAvailable::setProductDependsOnStock($product->id, (int) Tools::getValue("value"));
            break;
        case "out_of_stock":
            if (Tools::getValue("value") === false) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Undefined value")));
            }
            if (!in_array((int) Tools::getValue("value"), array(0, 1, 2))) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Uncorrect value")));
            }
            StockAvailable::setProductOutOfStock($product->id, (int) Tools::getValue("value"));
            break;
        case "set_qty":
            if (Tools::getValue("value") === false) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Undefined value")));
            }
            if (Tools::getValue("id_product_attribute") === false) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Undefined id product attribute")));
            }
            StockAvailable::setQuantity($product->id, (int) Tools::getValue("id_product_attribute"), (int) Tools::getValue("value"));
            break;
        case "advanced_stock_management":
            if (Tools::getValue("value") === false) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Undefined value")));
            }
            if ((int) Tools::getValue("value") != 1 && (int) Tools::getValue("value") != 0) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Uncorrect value")));
            }
            if (!Configuration::get("PS_ADVANCED_STOCK_MANAGEMENT") && (int) Tools::getValue("value") == 1) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Not possible if advanced stock management is not enabled")));
            }
            if (Configuration::get("PS_ADVANCED_STOCK_MANAGEMENT") && Pack::isPack($product->id)) {
                return Tools::jsonEncode(array("error" => Tools::displayError("Not possible if the product is a pack")));
            }
            $product->advanced_stock_management = (int) Tools::getValue("value");
            $product->save();
            if (StockAvailable::dependsOnStock($product->id) == 1 && (int) Tools::getValue("value") == 0) {
                StockAvailable::setProductDependsOnStock($product->id, 0);
            }
            break;
    }
    return Tools::jsonEncode(array("error" => false));
}
开发者ID:evilscripts,项目名称:gy,代码行数:63,代码来源:ajax_products.php

示例9: _addTaxesAndDutiesProduct

 private function _addTaxesAndDutiesProduct()
 {
     $product = new Product();
     $product->id_shop_default = (int) $this->context->shop->id;
     $product->id_manufacturer = 0;
     $product->id_supplier = 0;
     $product->reference = 'TAXDUTIES';
     $product->supplier_reference = '';
     $product->location = '';
     $product->width = 0;
     $product->height = 0;
     $product->depth = 0;
     $product->weight = 0;
     $product->quantity_discount = false;
     $product->ean13 = '';
     $product->upc = '';
     $product->is_virtual = false;
     $product->id_category_default = 2;
     $product->id_tax_rules_group = 1;
     $product->on_sale = 0;
     $product->online_only = 0;
     $product->ecotax = 0;
     $product->minimal_quantity = 1;
     $product->price = 0;
     $product->wholesale_price = 0;
     $product->unity = '';
     $product->unit_price_ratio = 1;
     $product->additional_shipping_cost = 0;
     $product->customizable = 0;
     $product->active = 1;
     $product->condition = 'new';
     $product->show_price = false;
     $product->visibility = 'none';
     $product->date_add = date('Y-m-d H:i:s');
     $product->date_upd = date('Y-m-d H:i:s');
     $product->name[(int) Configuration::get('PS_LANG_DEFAULT')] = $this->l('Taxes and Duties');
     $product->link_rewrite[(int) Configuration::get('PS_LANG_DEFAULT')] = 'taxes-and-duties';
     $result = $product->add();
     /* Allowed to be ordered even if stock = 0 */
     if ($result) {
         StockAvailable::setProductOutOfStock((int) $product->id, 1);
         StockAvailable::setProductDependsOnStock((int) $product->id, false);
         StockAvailable::setQuantity((int) $product->id, 0, 1000000);
     }
     return $result ? (int) $product->id : 0;
 }
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:46,代码来源:gointerpay.php

示例10: productImport


//.........这里部分代码省略.........
                        if (!empty($feature_name) && !empty($feature_value)) {
                            $id_feature = (int) Feature::addFeatureImport($feature_name, $position);
                            $id_product = null;
                            if (Tools::getValue('forceIDs') || Tools::getValue('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 (isset($product->advanced_stock_management)) {
                    if ($product->advanced_stock_management != 1 && $product->advanced_stock_management != 0) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management has incorrect value. Not set for product %1$s '), $product->name[$default_language_id]);
                    } elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management == 1) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, cannot enable on product %1$s '), $product->name[$default_language_id]);
                    } else {
                        $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(Tools::displayError('Advanced stock management is not enabled, warehouse not set on product %1$s '), $product->name[$default_language_id]);
                    } else {
                        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(Tools::displayError('Warehouse did not exist, cannot set on product %1$s.'), $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(Tools::displayError('Incorrect value for "depends on stock" for product %1$s '), $product->name[$default_language_id]);
                    } elseif ((!$product->advanced_stock_management || $product->advanced_stock_management == 0) && $product->depends_on_stock == 1) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management not enabled, cannot set "depends on stock" for product %1$s '), $product->name[$default_language_id]);
                    } else {
                        StockAvailable::setProductDependsOnStock($product->id, $product->depends_on_stock);
                    }
                    // This code allows us to set qty and disable depends on stock
                    if (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::isFeatureActive()) {
                                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);
                            }
                        }
                    }
                } else {
                    if (Shop::isFeatureActive()) {
                        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);
                    }
                }
            }
        }
        $this->closeCsvFile($handle);
    }
开发者ID:julienlerch,项目名称:xburning,代码行数:101,代码来源:AdminImportController.php

示例11: while

        while (($data = fgetcsv($handle, 10000, ';')) !== false) {
            $ref = $data[0];
            $qty = $data[1];
            $reference = new importerReference($ref);
            if (isset($reference->id_product) && $reference->id_product > 0) {
                if (version_compare(_PS_VERSION_, '1.5', '>=')) {
                    if ($reference->id_product_attribute) {
                        $allAT = importerReference::getAllProductIdByReference($ref);
                        if (count($allAT) < 1) {
                            $allAT[] = 0;
                        }
                        foreach ($allAT as $att) {
                            StockAvailable::setQuantity((int) $reference->id_product, (int) $att, (int) $qty, (int) getShopForRef($att, 1));
                        }
                    } else {
                        StockAvailable::setQuantity((int) $reference->id_product, 0, (int) $qty, (int) getShopForRef($ref, 2));
                    }
                } else {
                    updateProductQuantity($reference->id_product, $reference->id_product_attribute, $qty);
                }
            }
        }
        $catalog->updateMAJStock($etat);
    }
}
function getShopForRef($id, $typ)
{
    $shop = Db::getInstance()->getValue('SELECT `id_shop` FROM `' . _DB_PREFIX_ . 'stock_available` WHERE id_product' . ($typ = 1 ? '_attribute' : '') . '=' . (int) $id);
    if (!isset($shop) || $shop == 0) {
        return 1;
    } else {
开发者ID:ventsiwad,项目名称:presta_addons,代码行数:31,代码来源:stock.php

示例12: addDotpayVirtualProduct

 /**
  * Added Dotpay virtual product for extracharge option
  * @return bool
  */
 private function addDotpayVirtualProduct()
 {
     if (Validate::isInt($this->config->getDotpayExchVPid()) and Validate::isLoadedObject($product = new Product($this->config->getDotpayExchVPid())) and Validate::isInt($product->id)) {
         return true;
     }
     $product = new Product();
     $product->name = array((int) Configuration::get('PS_LANG_DEFAULT') => 'Online payment');
     $product->link_rewrite = array((int) Configuration::get('PS_LANG_DEFAULT') => 'online-payment');
     $product->visibility = 'none';
     $product->reference = 'DOTPAYFEE';
     $product->price = 0.0;
     $product->is_virtual = 1;
     $product->online_only = 1;
     $product->redirect_type = '404';
     $product->quantity = 9999999;
     $product->id_tax_rules_group = 0;
     $product->active = 1;
     $product->meta_keywords = 'payment';
     $product->id_category = 1;
     $product->id_category_default = 1;
     if (!$product->add()) {
         return false;
     }
     $product->addToCategories(array(1));
     StockAvailable::setQuantity($product->id, NULL, $product->quantity);
     $this->config->setDotpayExchVPid($product->id);
     return true;
 }
开发者ID:dotpay,项目名称:dotpay,代码行数:32,代码来源:dotpay.php

示例13: attributeImport


//.........这里部分代码省略.........
                        }
                        if (isset($attributes[$group . '_' . $attribute])) {
                            $attributes_to_add[] = (int) $attributes[$group . '_' . $attribute];
                        }
                        $obj = new Attribute();
                        $obj->cleanPositions((int) $id_attribute_group, false);
                        AttributeGroup::cleanPositions();
                    }
                }
            }
            $product->checkDefaultAttributes();
            if (!$product->cache_default_attribute) {
                Product::updateDefaultAttribute($product->id);
            }
            if ($id_product_attribute) {
                if ($id_product_attribute_update) {
                    Db::getInstance()->execute('
						DELETE FROM ' . _DB_PREFIX_ . 'product_attribute_combination
						WHERE id_product_attribute = ' . (int) $id_product_attribute);
                }
                foreach ($attributes_to_add as $attribute_to_add) {
                    Db::getInstance()->execute('
						INSERT IGNORE INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute)
						VALUES (' . (int) $attribute_to_add . ',' . (int) $id_product_attribute . ')');
                }
                if (isset($info['advanced_stock_management'])) {
                    if ($info['advanced_stock_management'] != 1 && $info['advanced_stock_management'] != 0) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management has incorrect value. Not set for product with id %d.'), $product->id);
                    } elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $info['advanced_stock_management'] == 1) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, cannot enable on product with id %d.'), $product->id);
                    } else {
                        $product->setAdvancedStockManagement($info['advanced_stock_management']);
                    }
                    if (StockAvailable::dependsOnStock($product->id) == 1 && $info['advanced_stock_management'] == 0) {
                        StockAvailable::setProductDependsOnStock($product->id, 0, null, $id_product_attribute);
                    }
                }
                if (isset($info['warehouse']) && $info['warehouse']) {
                    if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, warehouse is not set on product with id %d.'), $product->id);
                    } else {
                        if (Warehouse::exists($info['warehouse'])) {
                            $warehouse_location_entity = new WarehouseProductLocation();
                            $warehouse_location_entity->id_product = $product->id;
                            $warehouse_location_entity->id_product_attribute = $id_product_attribute;
                            $warehouse_location_entity->id_warehouse = $info['warehouse'];
                            if (WarehouseProductLocation::getProductLocation($product->id, $id_product_attribute, $info['warehouse']) !== false) {
                                $warehouse_location_entity->update();
                            } else {
                                $warehouse_location_entity->save();
                            }
                            StockAvailable::synchronize($product->id);
                        } else {
                            $this->warnings[] = sprintf(Tools::displayError('Warehouse did not exist, cannot set on product %1$s.'), $product->name[$default_language]);
                        }
                    }
                }
                if (isset($info['depends_on_stock'])) {
                    if ($info['depends_on_stock'] != 0 && $info['depends_on_stock'] != 1) {
                        $this->warnings[] = sprintf(Tools::displayError('Incorrect value for depends on stock for product %1$s '), $product->name[$default_language]);
                    } elseif ((!$info['advanced_stock_management'] || $info['advanced_stock_management'] == 0) && $info['depends_on_stock'] == 1) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, cannot set depends on stock %1$s '), $product->name[$default_language]);
                    } else {
                        StockAvailable::setProductDependsOnStock($product->id, $info['depends_on_stock'], null, $id_product_attribute);
                    }
                    if (isset($info['quantity']) && $info['quantity']) {
                        if ($info['depends_on_stock'] == 1) {
                            $stock_manager = StockManagerFactory::getManager();
                            $price = str_replace(',', '.', $info['wholesale_price']);
                            if ($price == 0) {
                                $price = 1.0E-6;
                            }
                            $price = round((double) $price, 6);
                            $warehouse = new Warehouse($info['warehouse']);
                            if ($stock_manager->addProduct((int) $product->id, $id_product_attribute, $warehouse, $info['quantity'], 1, $price, true)) {
                                StockAvailable::synchronize((int) $product->id);
                            }
                        } else {
                            if (Shop::isFeatureActive()) {
                                foreach ($id_shop_list as $shop) {
                                    StockAvailable::setQuantity((int) $product->id, $id_product_attribute, $info['quantity'], (int) $shop);
                                }
                            } else {
                                StockAvailable::setQuantity((int) $product->id, $id_product_attribute, $info['quantity'], $this->context->shop->id);
                            }
                        }
                    }
                } else {
                    if (Shop::isFeatureActive()) {
                        foreach ($id_shop_list as $shop) {
                            StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], (int) $shop);
                        }
                    } else {
                        StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], $this->context->shop->id);
                    }
                }
            }
        }
        $this->closeCsvFile($handle);
    }
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:101,代码来源:AdminImportController.php

示例14: addPaymentMethodCostVirtualItemToCart

 public function addPaymentMethodCostVirtualItemToCart($cart)
 {
     $config = $this->loadConfiguration();
     $langId = Context::getContext()->language->id;
     $product = new Product();
     $product->is_virtual = true;
     $product->indexed = false;
     $product->active = true;
     $product->price = $this->calculatePaymentCost($cart);
     $product->visibility = 'none';
     $product->name = array($langId => $config['PAYMENT_METHOD_COST_TITLE']);
     $product->link_rewrite = array($langId => uniqid());
     $product->id_tax_rules_group = 0;
     $product->add();
     StockAvailable::setQuantity($product->id, null, 1);
     $cart->updateQty(1, $product->id, null, false);
     $cart->update();
     $cart->getPackageList(true);
     return $product->id;
 }
开发者ID:invipay,项目名称:invipay-prestashop,代码行数:20,代码来源:Helper.php

示例15: attributeImportOne


//.........这里部分代码省略.........
        $product->checkDefaultAttributes();
        if (!$product->cache_default_attribute && !$validateOnly) {
            Product::updateDefaultAttribute($product->id);
        }
        if ($id_product_attribute) {
            if (!$validateOnly) {
                // now adds the attributes in the attribute_combination table
                if ($id_product_attribute_update) {
                    Db::getInstance()->execute('
						DELETE FROM ' . _DB_PREFIX_ . 'product_attribute_combination
						WHERE id_product_attribute = ' . (int) $id_product_attribute);
                }
                foreach ($attributes_to_add as $attribute_to_add) {
                    Db::getInstance()->execute('
						INSERT IGNORE INTO ' . _DB_PREFIX_ . 'product_attribute_combination (id_attribute, id_product_attribute)
						VALUES (' . (int) $attribute_to_add . ',' . (int) $id_product_attribute . ')', false);
                }
            }
            // set advanced stock managment
            if (isset($info['advanced_stock_management'])) {
                if ($info['advanced_stock_management'] != 1 && $info['advanced_stock_management'] != 0) {
                    $this->warnings[] = sprintf($this->trans('Advanced stock management has incorrect value. Not set for product with id %d.', array(), 'Admin.Parameters.Notification'), $product->id);
                } elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $info['advanced_stock_management'] == 1) {
                    $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot enable on product with id %d.', array(), 'Admin.Parameters.Notification'), $product->id);
                } elseif (!$validateOnly) {
                    $product->setAdvancedStockManagement($info['advanced_stock_management']);
                }
                // automaticly disable depends on stock, if a_s_m set to disabled
                if (!$validateOnly && StockAvailable::dependsOnStock($product->id) == 1 && $info['advanced_stock_management'] == 0) {
                    StockAvailable::setProductDependsOnStock($product->id, 0, null, $id_product_attribute);
                }
            }
            // Check if warehouse exists
            if (isset($info['warehouse']) && $info['warehouse']) {
                if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                    $this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, warehouse is not set on product with id %d.', array(), 'Admin.Parameters.Notification'), $product->id);
                } else {
                    if (Warehouse::exists($info['warehouse'])) {
                        $warehouse_location_entity = new WarehouseProductLocation();
                        $warehouse_location_entity->id_product = $product->id;
                        $warehouse_location_entity->id_product_attribute = $id_product_attribute;
                        $warehouse_location_entity->id_warehouse = $info['warehouse'];
                        if (!$validateOnly) {
                            if (WarehouseProductLocation::getProductLocation($product->id, $id_product_attribute, $info['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]);
                    }
                }
            }
            // stock available
            if (isset($info['depends_on_stock'])) {
                if ($info['depends_on_stock'] != 0 && $info['depends_on_stock'] != 1) {
                    $this->warnings[] = sprintf($this->trans('Incorrect value for "Depends on stock" for product %1$s ', array(), 'Admin.Notifications.Error'), $product->name[$default_language]);
                } elseif ((!$info['advanced_stock_management'] || $info['advanced_stock_management'] == 0) && $info['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]);
                } elseif (!$validateOnly) {
                    StockAvailable::setProductDependsOnStock($product->id, $info['depends_on_stock'], null, $id_product_attribute);
                }
                // This code allows us to set qty and disable depends on stock
                if (isset($info['quantity']) && (int) $info['quantity']) {
                    // if depends on stock and quantity, add quantity to stock
                    if ($info['depends_on_stock'] == 1) {
                        $stock_manager = StockManagerFactory::getManager();
                        $price = str_replace(',', '.', $info['wholesale_price']);
                        if ($price == 0) {
                            $price = 1.0E-6;
                        }
                        $price = round(floatval($price), 6);
                        $warehouse = new Warehouse($info['warehouse']);
                        if (!$validateOnly && $stock_manager->addProduct((int) $product->id, $id_product_attribute, $warehouse, (int) $info['quantity'], 1, $price, true)) {
                            StockAvailable::synchronize((int) $product->id);
                        }
                    } elseif (!$validateOnly) {
                        if ($shop_is_feature_active) {
                            foreach ($id_shop_list as $shop) {
                                StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], (int) $shop);
                            }
                        } else {
                            StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], $this->context->shop->id);
                        }
                    }
                }
            } elseif (!$validateOnly) {
                // if not depends_on_stock set, use normal qty
                if ($shop_is_feature_active) {
                    foreach ($id_shop_list as $shop) {
                        StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], (int) $shop);
                    }
                } else {
                    StockAvailable::setQuantity((int) $product->id, $id_product_attribute, (int) $info['quantity'], $this->context->shop->id);
                }
            }
        }
    }
开发者ID:M03G,项目名称:PrestaShop,代码行数:101,代码来源:AdminImportController.php


注:本文中的StockAvailable::setQuantity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。