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


PHP StockAvailable::setProductDependsOnStock方法代码示例

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


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

示例1: 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('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 ($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('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('product' => $this->object));
             // 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. '))));
             }
             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:,项目名称:,代码行数:68,代码来源:

示例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: 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) {
开发者ID:M03G,项目名称:PrestaShop,代码行数:67,代码来源:AdminImportController.php

示例4: 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

示例5: upsert


//.........这里部分代码省略.........
        $product->deleteFeatures();
        if ($line['author']) {
            $id_feature_value = FeatureValue::addFeatureValueImport(9, $line['author'], null, Configuration::get('PS_LANG_DEFAULT'));
            Product::addFeatureProductImport($product->id, 9, $id_feature_value);
        }

        if ($line['year']) {
            $id_feature_value = FeatureValue::addFeatureValueImport(10, $line['year'], null, Configuration::get('PS_LANG_DEFAULT'));
            Product::addFeatureProductImport($product->id, 10, $id_feature_value);
        }

        if ($line['paperback']) {
            Product::addFeatureProductImport($product->id, 11, 1); //1 - id значения "переплёт" у харакатеристики "Переплёт"
        }

        if ($line['pages']) {
            $id_feature_value = FeatureValue::addFeatureValueImport(12, $line['pages'], null, Configuration::get('PS_LANG_DEFAULT'), true);
            Product::addFeatureProductImport($product->id, 12, $id_feature_value);
        }

        /*
        if ($line['weight']) {
            $id_feature_value = FeatureValue::addFeatureValueImport(4, $line['weight'], null, Configuration::get('PS_LANG_DEFAULT'), true);
            Product::addFeatureProductImport($product->id, 4, $id_feature_value);
        }
        */

        if ($line['isbn']) {
            $id_feature_value = FeatureValue::addFeatureValueImport(13, $line['isbn'], null, Configuration::get('PS_LANG_DEFAULT'), true);
            Product::addFeatureProductImport($product->id, 13, $id_feature_value);
        }

        if ($line['publishing']) {
            $id_feature_value = FeatureValue::addFeatureValueImport(14, $line['publishing'], null, Configuration::get('PS_LANG_DEFAULT'), true);
            Product::addFeatureProductImport($product->id, 14, $id_feature_value);
        }

        $location = WarehouseProductLocation::getIdByProductAndWarehouse($product->id, 0, $line['warehouse']);
        $location = new WarehouseProductLocation($location);
        $location->id_product = $product->id;
        $location->id_product_attribute = 0;
        $location->id_warehouse = $line['warehouse'];
        $location->save();

        $stock = DB::getInstance()->getValue("SELECT `id_stock` FROM `" . _DB_PREFIX_ . "stock` WHERE `id_product` = {$product->id} AND `id_warehouse` = {$line['warehouse']}");
        $stock = new Stock($stock);
        $stock->id_product = $product->id;
        $stock->id_product_attribute = 0;
        $stock->id_warehouse = $line['warehouse'];
        $stock->physical_quantity = $line['count'];
        $stock->usable_quantity = $line['count'];
        $stock->price_te = 0;
        $stock->save();

        $available = DB::getInstance()->getValue("SELECT `id_stock_available` FROM `". _DB_PREFIX_ . "stock_available` WHERE `id_product` = {$product->id} AND `id_shop` = " . Context::getContext()->shop->id);
        $available = new StockAvailable($available);
        $available->id_product = $product->id;
        $available->id_product_attribute = 0;
        //$available->id_shop = Context::getContext()->shop->id;
        $available->quantity = StockManagerFactory::getManager()->getProductPhysicalQuantities($product->id, 0);
        $available->save();

        StockAvailable::setProductDependsOnStock($product->id, true, null);
        StockAvailable::setProductOutOfStock($product->id, 1, null); //allow

        while(strlen($line['reference']) < 9) {
            $line['reference'] = '0' . $line['reference'];
        }

        if (file_exists(_PS_ROOT_DIR_ . '/upload/import/' . $line['reference'] . '.jpg')) {
            $product->deleteImages();

            $image = new Image();
            $image->id_product = $product->id;
            $image->cover = 1;
            $image->position = 0;
            $image->save();

            $name = $image->getPathForCreation();

            copy(_PS_ROOT_DIR_ . '/upload/import/' . $line['reference'] . '.jpg', $name.'.'.$image->image_format);

            $types = ImageType::getImagesTypes('products');
            foreach ($types as $type) {
                ImageManager::resize(_PS_ROOT_DIR_ . '/upload/import/' . $line['reference'] . '.jpg', $name . '-' . $type['name'] . '.' . $image->image_format, $type['width'], $type['height'], $image->image_format);
            }
        }

        /*
        Db::getInstance()->update('stock_available', array(
           'depends_on_stock' => (int)1, //1 - доступное количество на основе ASM. 0 - указывается вручную
            'out_of_stock' => (int)1, //1-allow
        ), 'id_product='.$product->id.'');
         $affrows = Db::getInstance()->Affected_Rows();
         var_dump($affrows);
         */

        //var_dump($product->reference);
        //echo "<br/><br/><br/><br/>";
    }
开发者ID:,项目名称:,代码行数:101,代码来源:

示例6: _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

示例7: attributeImport


//.........这里部分代码省略.........
                        $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) {
                // 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 . ')');
                }
                // set advanced stock managment
                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 %s '), $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, can not enable on product with id %s '), $product->id);
                    } else {
                        $product->setAdvancedStockManagement($info['advanced_stock_management']);
                    }
                    // automaticly disable depends on stock, if a_s_m set to disabled
                    if (StockAvailable::dependsOnStock($product->id) == 1 && $info['advanced_stock_management'] == 0) {
                        StockAvailable::setProductDependsOnStock($product->id, 0, null, $id_product_attribute);
                    }
                }
                // Check if warehouse exists
                if ($info['warehouse']) {
                    if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management is not enabled, warehouse not set on product with id %s '), $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_id]);
                        }
                    }
                }
                // stock available
                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_id]);
                    } elseif ((!$info['advanced_stock_management'] || $info['advanced_stock_management'] == 0) && $info['depends_on_stock'] == 1) {
                        $this->warnings[] = sprintf(Tools::displayError('Advanced stock management not enabled, can not set depends on stock %1$s '), $product->name[$default_language_id]);
                    } else {
                        StockAvailable::setProductDependsOnStock($product->id, $info['depends_on_stock'], null, $id_product_attribute);
                    }
开发者ID:gks-stage,项目名称:prestashop,代码行数:67,代码来源:AdminImportController.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: productImport


//.........这里部分代码省略.........
                    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 (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) {
开发者ID:julienlerch,项目名称:xburning,代码行数:67,代码来源:AdminImportController.php

示例10: 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

示例11: attribute

 public function attribute()
 {
     $app = JFactory::getApplication();
     // Don't process if the combination fields have not been submitted
     if (!JeproshopCombinationModelCombination::isFeaturePublished() || !$app->input->get('attribute_combination_list')) {
         return;
     }
     if (Validate::isLoadedObject($product = $this->object)) {
         if ($this->isProductFieldUpdated('attribute_price') && (!Tools::getIsset('attribute_price') || Tools::getIsset('attribute_price') == null)) {
             $this->has_errors = Tools::displayError('The price attribute is required.');
         }
         if (!Tools::getIsset('attribute_combination_list') || Tools::isEmpty(Tools::getValue('attribute_combination_list'))) {
             $this->has_errors = Tools::displayError('You must add at least one attribute.');
         }
         $array_checks = array('reference' => 'isReference', 'supplier_reference' => 'isReference', 'location' => 'isReference', 'ean13' => 'isEan13', 'upc' => 'isUpc', 'wholesale_price' => 'isPrice', 'price' => 'isPrice', 'ecotax' => 'isPrice', 'quantity' => 'isInt', 'weight' => 'isUnsignedFloat', 'unit_price_impact' => 'isPrice', 'default_on' => 'isBool', 'minimal_quantity' => 'isUnsignedInt', 'available_date' => 'isDateFormat');
         foreach ($array_checks as $property => $check) {
             if (Tools::getValue('attribute_' . $property) !== false && !call_user_func(array('Validate', $check), Tools::getValue('attribute_' . $property))) {
                 $this->errors[] = sprintf(Tools::displayError('Field %s is not valid'), $property);
             }
         }
         if (!count($this->errors)) {
             if (!isset($_POST['attribute_wholesale_price'])) {
                 $_POST['attribute_wholesale_price'] = 0;
             }
             if (!isset($_POST['attribute_price_impact'])) {
                 $_POST['attribute_price_impact'] = 0;
             }
             if (!isset($_POST['attribute_weight_impact'])) {
                 $_POST['attribute_weight_impact'] = 0;
             }
             if (!isset($_POST['attribute_ecotax'])) {
                 $_POST['attribute_ecotax'] = 0;
             }
             if (Tools::getValue('attribute_default')) {
                 $product->deleteDefaultAttributes();
             }
             // Change existing one
             if (($id_product_attribute = (int) Tools::getValue('id_product_attribute')) || ($id_product_attribute = $product->productAttributeExists(Tools::getValue('attribute_combination_list'), false, null, true, true))) {
                 if ($this->tabAccess['edit'] === '1') {
                     if ($this->isProductFieldUpdated('available_date_attribute') && (Tools::getValue('available_date_attribute') != '' && !Validate::isDateFormat(Tools::getValue('available_date_attribute')))) {
                         $this->errors[] = Tools::displayError('Invalid date format.');
                     } else {
                         $product->updateAttribute((int) $id_product_attribute, $this->isProductFieldUpdated('attribute_wholesale_price') ? Tools::getValue('attribute_wholesale_price') : null, $this->isProductFieldUpdated('attribute_price_impact') ? Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact') : null, $this->isProductFieldUpdated('attribute_weight_impact') ? Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact') : null, $this->isProductFieldUpdated('attribute_unit_impact') ? Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact') : null, $this->isProductFieldUpdated('attribute_ecotax') ? Tools::getValue('attribute_ecotax') : null, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_ean13'), $this->isProductFieldUpdated('attribute_default') ? Tools::getValue('attribute_default') : null, Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), $this->isProductFieldUpdated('attribute_minimal_quantity') ? Tools::getValue('attribute_minimal_quantity') : null, $this->isProductFieldUpdated('available_date_attribute') ? Tools::getValue('available_date_attribute') : null, false);
                         StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute);
                         StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute);
                     }
                 } else {
                     $this->errors[] = Tools::displayError('You do not have permission to add this.');
                 }
             } else {
                 if ($this->tabAccess['add'] === '1') {
                     if ($product->productAttributeExists(Tools::getValue('attribute_combination_list'))) {
                         $this->errors[] = Tools::displayError('This combination already exists.');
                     } else {
                         $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), 0, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), null, Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('attribute_minimal_quantity'), array(), Tools::getValue('available_date_attribute'));
                         StockAvailable::setProductDependsOnStock((int) $product->id, $product->depends_on_stock, null, (int) $id_product_attribute);
                         StockAvailable::setProductOutOfStock((int) $product->id, $product->out_of_stock, null, (int) $id_product_attribute);
                     }
                 } else {
                     $this->errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('edit here.');
                 }
             }
             if (!count($this->errors)) {
                 $combination = new Combination((int) $id_product_attribute);
                 $combination->setAttributes(Tools::getValue('attribute_combination_list'));
                 // images could be deleted before
                 $id_images = Tools::getValue('id_image_attr');
                 if (!empty($id_images)) {
                     $combination->setImages($id_images);
                 }
                 $product->checkDefaultAttributes();
                 if (Tools::getValue('attribute_default')) {
                     Product::updateDefaultAttribute((int) $product->id);
                     if (isset($id_product_attribute)) {
                         $product->cache_default_attribute = (int) $id_product_attribute;
                     }
                     if ($available_date = Tools::getValue('available_date_attribute')) {
                         $product->setAvailableDate($available_date);
                     }
                 }
             }
         }
     }
 }
开发者ID:jeprodev,项目名称:jeproshop,代码行数:84,代码来源:product.php


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