本文整理汇总了PHP中WarehouseProductLocation::getCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP WarehouseProductLocation::getCollection方法的具体用法?PHP WarehouseProductLocation::getCollection怎么用?PHP WarehouseProductLocation::getCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WarehouseProductLocation
的用法示例。
在下文中一共展示了WarehouseProductLocation::getCollection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPackWarehouses
/**
* For a given pack, returns the warehouse it can be shipped from
*
* @param int $id_product
* @return int|bool id_warehouse or false
*/
public static function getPackWarehouses($id_product, $id_shop = null)
{
if (!Pack::isPack($id_product)) {
return false;
}
if (is_null($id_shop)) {
$id_shop = Context::getContext()->shop->id;
}
// warehouses of the pack
$pack_warehouses = WarehouseProductLocation::getCollection((int) $id_product);
// products in the pack
$products = Pack::getItems((int) $id_product, Configuration::get('PS_LANG_DEFAULT'));
// array with all warehouses id to check
$list = array();
// fills $list
foreach ($pack_warehouses as $pack_warehouse) {
$list['pack_warehouses'][] = (int) $pack_warehouse->id_warehouse;
}
// for each products in the pack
foreach ($products as $product) {
if ($product->advanced_stock_management) {
// gets the warehouses of one product
$product_warehouses = Warehouse::getProductWarehouseList((int) $product->id, 0, (int) $id_shop);
$list[(int) $product->id] = array();
// fills array with warehouses for this product
foreach ($product_warehouses as $product_warehouse) {
$list[(int) $product->id][] = $product_warehouse['id_warehouse'];
}
}
}
$res = false;
// returns final list
if (count($list) > 1) {
$res = call_user_func_array('array_intersect', $list);
}
return $res;
}
示例2: productImportOne
//.........这里部分代码省略.........
$id_feature = (int) Feature::addFeatureImport($feature_name, $position);
$id_product = null;
if ($force_ids || $match_ref) {
$id_product = (int) $product->id;
}
$id_feature_value = (int) FeatureValue::addFeatureValueImport($id_feature, $feature_value, $id_product, $id_lang, $custom);
Product::addFeatureProductImport($product->id, $id_feature, $id_feature_value);
}
}
}
// clean feature positions to avoid conflict
Feature::cleanPositions();
// set advanced stock managment
if (!$validateOnly && isset($product->advanced_stock_management)) {
if ($product->advanced_stock_management != 1 && $product->advanced_stock_management != 0) {
$this->warnings[] = sprintf($this->trans('Advanced stock management has incorrect value. Not set for product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]);
} elseif (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management == 1) {
$this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot enable on product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]);
} elseif ($update_advanced_stock_management_value) {
$product->setAdvancedStockManagement($product->advanced_stock_management);
}
// automaticly disable depends on stock, if a_s_m set to disabled
if (StockAvailable::dependsOnStock($product->id) == 1 && $product->advanced_stock_management == 0) {
StockAvailable::setProductDependsOnStock($product->id, 0);
}
}
// Check if warehouse exists
if (isset($product->warehouse) && $product->warehouse) {
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
$this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, warehouse not set on product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]);
} elseif (!$validateOnly) {
if (Warehouse::exists($product->warehouse)) {
// Get already associated warehouses
$associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id);
// Delete any entry in warehouse for this product
foreach ($associated_warehouses_collection as $awc) {
$awc->delete();
}
$warehouse_location_entity = new WarehouseProductLocation();
$warehouse_location_entity->id_product = $product->id;
$warehouse_location_entity->id_product_attribute = 0;
$warehouse_location_entity->id_warehouse = $product->warehouse;
if (WarehouseProductLocation::getProductLocation($product->id, 0, $product->warehouse) !== false) {
$warehouse_location_entity->update();
} else {
$warehouse_location_entity->save();
}
StockAvailable::synchronize($product->id);
} else {
$this->warnings[] = sprintf($this->trans('Warehouse did not exist, cannot set on product %1$s.', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]);
}
}
}
// stock available
if (isset($product->depends_on_stock)) {
if ($product->depends_on_stock != 0 && $product->depends_on_stock != 1) {
$this->warnings[] = sprintf($this->trans('Incorrect value for "Depends on stock" for product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]);
} elseif ((!$product->advanced_stock_management || $product->advanced_stock_management == 0) && $product->depends_on_stock == 1) {
$this->warnings[] = sprintf($this->trans('Advanced stock management is not enabled, cannot set "Depends on stock" for product %1$s ', array(), 'Admin.Parameters.Notification'), $product->name[$default_language_id]);
} elseif (!$validateOnly) {
StockAvailable::setProductDependsOnStock($product->id, $product->depends_on_stock);
}
// This code allows us to set qty and disable depends on stock
if (!$validateOnly && isset($product->quantity) && (int) $product->quantity) {
// if depends on stock and quantity, add quantity to stock
if ($product->depends_on_stock == 1) {
示例3: 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);
}
}
}
Feature::cleanPositions();
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);
}
if (StockAvailable::dependsOnStock($product->id) == 1 && $product->advanced_stock_management == 0) {
StockAvailable::setProductDependsOnStock($product->id, 0);
}
}
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)) {
$associated_warehouses_collection = WarehouseProductLocation::getCollection($product->id);
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]);
}
}
}
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);
}
if (isset($product->quantity) && $product->quantity) {
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((double) $price, 6);
$warehouse = new Warehouse($product->warehouse);
if ($stock_manager->addProduct((int) $product->id, 0, $warehouse, $product->quantity, 1, $price, true)) {
StockAvailable::synchronize((int) $product->id);
}
} else {
if (Shop::isFeatureActive()) {
foreach ($shops as $shop) {
StockAvailable::setQuantity((int) $product->id, 0, $product->quantity, (int) $shop);
}
} else {
StockAvailable::setQuantity((int) $product->id, 0, $product->quantity, (int) $this->context->shop->id);
}
}
}
} else {
if (Shop::isFeatureActive()) {
foreach ($shops as $shop) {
StockAvailable::setQuantity((int) $product->id, 0, $product->quantity, (int) $shop);
}
} else {
StockAvailable::setQuantity((int) $product->id, 0, $product->quantity, (int) $this->context->shop->id);
}
}
}
}
$this->closeCsvFile($handle);
}