本文整理汇总了PHP中StockManagerFactory类的典型用法代码示例。如果您正苦于以下问题:PHP StockManagerFactory类的具体用法?PHP StockManagerFactory怎么用?PHP StockManagerFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StockManagerFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getManager
/**
* Returns a StockManager
*
* @return StockManagerInterface
*/
public static function getManager()
{
if (!isset(StockManagerFactory::$stock_manager)) {
$stock_manager = StockManagerFactory::execHookStockManagerFactory();
if (!$stock_manager instanceof StockManagerInterface) {
$stock_manager = new StockManager();
}
StockManagerFactory::$stock_manager = $stock_manager;
}
return StockManagerFactory::$stock_manager;
}
开发者ID:IngenioContenidoDigital,项目名称:americana,代码行数:16,代码来源:StockManagerFactory.php
示例2: synchronize
public static function synchronize($id_product, $order_id_shop = null)
{
if (!Validate::isUnsignedId($id_product)) {
return false;
}
if (Pack::isPack($id_product)) {
if (Validate::isLoadedObject($product = new Product((int) $id_product))) {
if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0) {
$products_pack = Pack::getItems($id_product, (int) Configuration::get('PS_LANG_DEFAULT'));
foreach ($products_pack as $product_pack) {
StockAvailable::synchronize($product_pack->id, $order_id_shop);
}
}
} else {
return false;
}
}
$ids_warehouse = Warehouse::getWarehousesGroupedByShops();
if ($order_id_shop !== null) {
$order_warehouses = array();
$wh = Warehouse::getWarehouses(false, (int) $order_id_shop);
foreach ($wh as $warehouse) {
$order_warehouses[] = $warehouse['id_warehouse'];
}
}
$ids_product_attribute = array();
foreach (Product::getProductAttributesIds($id_product) as $id_product_attribute) {
$ids_product_attribute[] = $id_product_attribute['id_product_attribute'];
}
$out_of_stock = StockAvailable::outOfStock($id_product);
$manager = StockManagerFactory::getManager();
foreach ($ids_warehouse as $id_shop => $warehouses) {
if (StockAvailable::dependsOnStock($id_product, $id_shop)) {
$product_quantity = 0;
if (empty($ids_product_attribute)) {
$allowed_warehouse_for_product = WareHouse::getProductWarehouseList((int) $id_product, 0, (int) $id_shop);
$allowed_warehouse_for_product_clean = array();
foreach ($allowed_warehouse_for_product as $warehouse) {
$allowed_warehouse_for_product_clean[] = (int) $warehouse['id_warehouse'];
}
$allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses);
if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_product_clean, $order_warehouses))) {
continue;
}
$product_quantity = $manager->getProductRealQuantities($id_product, null, $allowed_warehouse_for_product_clean, true);
Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => 0, 'quantity' => $product_quantity));
} else {
foreach ($ids_product_attribute as $id_product_attribute) {
$allowed_warehouse_for_combination = WareHouse::getProductWarehouseList((int) $id_product, (int) $id_product_attribute, (int) $id_shop);
$allowed_warehouse_for_combination_clean = array();
foreach ($allowed_warehouse_for_combination as $warehouse) {
$allowed_warehouse_for_combination_clean[] = (int) $warehouse['id_warehouse'];
}
$allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses);
if ($order_id_shop != null && !count(array_intersect($allowed_warehouse_for_combination_clean, $order_warehouses))) {
continue;
}
$quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $allowed_warehouse_for_combination_clean, true);
$query = new DbQuery();
$query->select('COUNT(*)');
$query->from('stock_available');
$query->where('id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop));
if ((int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query)) {
$query = array('table' => 'stock_available', 'data' => PP::hydrateQty(array(), 'quantity', $quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute . StockAvailable::addSqlShopRestriction(null, $id_shop));
Db::getInstance()->update($query['table'], $query['data'], $query['where']);
} else {
$query = array('table' => 'stock_available', 'data' => PP::hydrateQty(array('depends_on_stock' => 1, 'out_of_stock' => $out_of_stock, 'id_product' => (int) $id_product, 'id_product_attribute' => (int) $id_product_attribute), 'quantity', $quantity));
StockAvailable::addSqlShopParams($query['data']);
Db::getInstance()->insert($query['table'], $query['data']);
}
$product_quantity += $quantity;
Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity));
}
}
$query = array('table' => 'stock_available', 'data' => PP::hydrateQty(array(), 'quantity', $product_quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = 0' . StockAvailable::addSqlShopRestriction(null, $id_shop));
Db::getInstance()->update($query['table'], $query['data'], $query['where']);
}
}
if (count($ids_warehouse) == 0 && StockAvailable::dependsOnStock((int) $id_product)) {
Db::getInstance()->update('stock_available', array('quantity' => 0, 'quantity_remainder' => 0), 'id_product = ' . (int) $id_product);
}
Cache::clean('StockAvailable::getQuantityAvailableByProduct_' . (int) $id_product . '*');
}
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:83,代码来源:StockAvailable.php
示例3: setProductCurrentStock
/**
*
* This method allow to add stock information on a product detail
* @param array &$product
*/
protected function setProductCurrentStock(&$product)
{
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) $product['advanced_stock_management'] == 1 && (int) $product['id_warehouse'] > 0) {
$product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], null, true);
} else {
$product['current_stock'] = '--';
}
}
开发者ID:jpodracky,项目名称:dogs,代码行数:13,代码来源:OrderInvoice.php
示例4: getPackageList
/**
* Get products grouped by package and by addresses to be sent individualy (one package = one shipping cost).
*
* @return array array(
* 0 => array( // First address
* 0 => array( // First package
* 'product_list' => array(...),
* 'carrier_list' => array(...),
* 'id_warehouse' => array(...),
* ),
* ),
* );
* @todo Add avaibility check
*/
public function getPackageList($flush = false)
{
static $cache = array();
if (isset($cache[(int) $this->id . '_' . (int) $this->id_address_delivery]) && $cache[(int) $this->id . '_' . (int) $this->id_address_delivery] !== false && !$flush) {
return $cache[(int) $this->id . '_' . (int) $this->id_address_delivery];
}
$product_list = $this->getProducts();
// Step 1 : Get product informations (warehouse_list and carrier_list), count warehouse
// Determine the best warehouse to determine the packages
// For that we count the number of time we can use a warehouse for a specific delivery address
$warehouse_count_by_address = array();
$warehouse_carrier_list = array();
$stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
foreach ($product_list as &$product) {
if ((int) $product['id_address_delivery'] == 0) {
$product['id_address_delivery'] = (int) $this->id_address_delivery;
}
if (!isset($warehouse_count_by_address[$product['id_address_delivery']])) {
$warehouse_count_by_address[$product['id_address_delivery']] = array();
}
$product['warehouse_list'] = array();
if ($stock_management_active && ((int) $product['advanced_stock_management'] == 1 || Pack::usesAdvancedStockManagement((int) $product['id_product']))) {
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute'], $this->id_shop);
if (count($warehouse_list) == 0) {
$warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']);
}
// Does the product is in stock ?
// If yes, get only warehouse where the product is in stock
$warehouse_in_stock = array();
$manager = StockManagerFactory::getManager();
foreach ($warehouse_list as $key => $warehouse) {
$product_real_quantities = $manager->getProductRealQuantities($product['id_product'], $product['id_product_attribute'], array($warehouse['id_warehouse']), true);
if ($product_real_quantities > 0 || Pack::isPack((int) $product['id_product'])) {
$warehouse_in_stock[] = $warehouse;
}
}
if (!empty($warehouse_in_stock)) {
$warehouse_list = $warehouse_in_stock;
$product['in_stock'] = true;
} else {
$product['in_stock'] = false;
}
} else {
//simulate default warehouse
$warehouse_list = array(0);
$product['in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']) > 0;
}
foreach ($warehouse_list as $warehouse) {
if (!isset($warehouse_carrier_list[$warehouse['id_warehouse']])) {
$warehouse_object = new Warehouse($warehouse['id_warehouse']);
$warehouse_carrier_list[$warehouse['id_warehouse']] = $warehouse_object->getCarriers();
}
$product['warehouse_list'][] = $warehouse['id_warehouse'];
if (!isset($warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']])) {
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']] = 0;
}
$warehouse_count_by_address[$product['id_address_delivery']][$warehouse['id_warehouse']]++;
}
}
unset($product);
arsort($warehouse_count_by_address);
// Step 2 : Group product by warehouse
$grouped_by_warehouse = array();
foreach ($product_list as &$product) {
if (!isset($grouped_by_warehouse[$product['id_address_delivery']])) {
$grouped_by_warehouse[$product['id_address_delivery']] = array('in_stock' => array(), 'out_of_stock' => array());
}
$product['carrier_list'] = array();
$id_warehouse = 0;
foreach ($warehouse_count_by_address[$product['id_address_delivery']] as $id_war => $val) {
if (in_array((int) $id_war, $product['warehouse_list'])) {
$product['carrier_list'] = array_merge($product['carrier_list'], Carrier::getAvailableCarrierList(new Product($product['id_product']), $id_war, $product['id_address_delivery'], null, $this));
if (!$id_warehouse) {
$id_warehouse = (int) $id_war;
}
}
}
if (!isset($grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse])) {
$grouped_by_warehouse[$product['id_address_delivery']]['in_stock'][$id_warehouse] = array();
$grouped_by_warehouse[$product['id_address_delivery']]['out_of_stock'][$id_warehouse] = array();
}
if (!$this->allow_seperated_package) {
$key = 'in_stock';
} else {
$key = $product['in_stock'] ? 'in_stock' : 'out_of_stock';
}
//.........这里部分代码省略.........
开发者ID:dev-lav,项目名称:htdocs,代码行数:101,代码来源:Cart.php
示例5: reinjectQuantity
protected function reinjectQuantity($order_detail, $qty_cancel_product, $delete = false)
{
// Reinject product
$reinjectable_quantity = (int) $order_detail->product_quantity - (int) $order_detail->product_quantity_reinjected;
$quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product;
// @since 1.5.0 : Advanced Stock Management
$product_to_inject = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
$product = new Product($order_detail->product_id, false, (int) $this->context->language->id, (int) $order_detail->id_shop);
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $product->advanced_stock_management && $order_detail->id_warehouse != 0) {
$manager = StockManagerFactory::getManager();
$movements = StockMvt::getNegativeStockMvts($order_detail->id_order, $order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject);
$left_to_reinject = $quantity_to_reinject;
foreach ($movements as $movement) {
if ($left_to_reinject > $movement['physical_quantity']) {
$quantity_to_reinject = $movement['physical_quantity'];
}
$left_to_reinject -= $quantity_to_reinject;
if (Pack::isPack((int) $product->id)) {
// Gets items
if ($product->pack_stock_type == 1 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && Configuration::get('PS_PACK_STOCK_TYPE') > 0) {
$products_pack = Pack::getItems((int) $product->id, (int) Configuration::get('PS_LANG_DEFAULT'));
// Foreach item
foreach ($products_pack as $product_pack) {
if ($product_pack->advanced_stock_management == 1) {
$manager->addProduct($product_pack->id, $product_pack->id_pack_product_attribute, new Warehouse($movement['id_warehouse']), $product_pack->pack_quantity * $quantity_to_reinject, null, $movement['price_te'], true);
}
}
}
if ($product->pack_stock_type == 0 || $product->pack_stock_type == 2 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 0 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)) {
$manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true);
}
} else {
$manager->addProduct($order_detail->product_id, $order_detail->product_attribute_id, new Warehouse($movement['id_warehouse']), $quantity_to_reinject, null, $movement['price_te'], true);
}
}
$id_product = $order_detail->product_id;
if ($delete) {
$order_detail->delete();
}
StockAvailable::synchronize($id_product);
} elseif ($order_detail->id_warehouse == 0) {
StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, $quantity_to_reinject, $order_detail->id_shop);
if ($delete) {
$order_detail->delete();
}
} else {
$this->errors[] = Tools::displayError('This product cannot be re-stocked.');
}
}
开发者ID:evgrishin,项目名称:mh16014,代码行数:49,代码来源:AdminOrdersController.php
示例6: getWsRealQuantity
/**
* Webservice : used to get the real quantity of a product
*/
public function getWsRealQuantity()
{
$manager = StockManagerFactory::getManager();
$quantity = $manager->getProductRealQuantities($this->id_product, $this->id_product_attribute, $this->id_warehouse, true);
return $quantity;
}
开发者ID:M03G,项目名称:PrestaShop,代码行数:9,代码来源:Stock.php
示例7: 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
示例8: postProcess
public function postProcess()
{
$this->adminControllerPostProcess();
// Checks access
if (Tools::isSubmit('addStock') && !($this->tabAccess['add'] === '1')) {
$this->errors[] = Tools::displayError('You do not have the required permission to add stock.');
}
if (Tools::isSubmit('removeStock') && !($this->tabAccess['delete'] === '1')) {
$this->errors[] = Tools::displayError('You do not have the required permission to delete stock');
}
if (Tools::isSubmit('transferStock') && !($this->tabAccess['edit'] === '1')) {
$this->errors[] = Tools::displayError('You do not have the required permission to transfer stock.');
}
if (count($this->errors)) {
return;
}
// Global checks when add / remove / transfer product
if ((Tools::isSubmit('addstock') || Tools::isSubmit('removestock') || Tools::isSubmit('transferstock')) && Tools::isSubmit('is_post')) {
// get product ID
$id_product = (int) Tools::getValue('id_product', 0);
if ($id_product <= 0) {
$this->errors[] = Tools::displayError('The selected product is not valid.');
}
// get product_attribute ID
$id_product_attribute = (int) Tools::getValue('id_product_attribute', 0);
// check the product hash
$check = Tools::getValue('check', '');
$check_valid = md5(_COOKIE_KEY_ . $id_product . $id_product_attribute);
if ($check != $check_valid) {
$this->errors[] = Tools::displayError('The selected product is not valid.');
}
// get quantity and check that the post value is really an integer
// If it's not, we have nothing to do
$quantity = Tools::getValue('quantity', 0);
$quantity = PP::normalizeProductQty($quantity, $id_product);
if (!is_numeric($quantity) || $quantity <= 0) {
$this->errors[] = Tools::displayError('The quantity value is not valid.');
}
//$quantity = (int)$quantity;
$token = Tools::getValue('token') ? Tools::getValue('token') : $this->token;
$redirect = self::$currentIndex . '&token=' . $token;
}
// Global checks when add / remove product
if ((Tools::isSubmit('addstock') || Tools::isSubmit('removestock')) && Tools::isSubmit('is_post')) {
// get warehouse id
$id_warehouse = (int) Tools::getValue('id_warehouse', 0);
if ($id_warehouse <= 0 || !Warehouse::exists($id_warehouse)) {
$this->errors[] = Tools::displayError('The selected warehouse is not valid.');
}
// get stock movement reason id
$id_stock_mvt_reason = (int) Tools::getValue('id_stock_mvt_reason', 0);
if ($id_stock_mvt_reason <= 0 || !StockMvtReason::exists($id_stock_mvt_reason)) {
$this->errors[] = Tools::displayError('The reason is not valid.');
}
// get usable flag
$usable = Tools::getValue('usable', null);
if (is_null($usable)) {
$this->errors[] = Tools::displayError('You have to specify whether the product quantity is usable for sale on shops or not.');
}
$usable = (bool) $usable;
}
if (Tools::isSubmit('addstock') && Tools::isSubmit('is_post')) {
// get product unit price
$price = str_replace(',', '.', Tools::getValue('price', 0));
if (!is_numeric($price)) {
$this->errors[] = Tools::displayError('The product price is not valid.');
}
$price = round((double) $price, 6);
// get product unit price currency id
$id_currency = (int) Tools::getValue('id_currency', 0);
if ($id_currency <= 0 || (!($result = Currency::getCurrency($id_currency)) || empty($result))) {
$this->errors[] = Tools::displayError('The selected currency is not valid.');
}
// if all is ok, add stock
if (count($this->errors) == 0) {
$warehouse = new Warehouse($id_warehouse);
// convert price to warehouse currency if needed
if ($id_currency != $warehouse->id_currency) {
// First convert price to the default currency
$price_converted_to_default_currency = Tools::convertPrice($price, $id_currency, false);
// Convert the new price from default currency to needed currency
$price = Tools::convertPrice($price_converted_to_default_currency, $warehouse->id_currency, true);
}
// add stock
$stock_manager = StockManagerFactory::getManager();
if ($stock_manager->addProduct($id_product, $id_product_attribute, $warehouse, $quantity, $id_stock_mvt_reason, $price, $usable)) {
// Create warehouse_product_location entry if we add stock to a new warehouse
$id_wpl = (int) WarehouseProductLocation::getIdByProductAndWarehouse($id_product, $id_product_attribute, $id_warehouse);
if (!$id_wpl) {
$wpl = new WarehouseProductLocation();
$wpl->id_product = (int) $id_product;
$wpl->id_product_attribute = (int) $id_product_attribute;
$wpl->id_warehouse = (int) $id_warehouse;
$wpl->save();
}
StockAvailable::synchronize($id_product);
if (Tools::isSubmit('addstockAndStay')) {
$redirect = self::$currentIndex . '&id_product=' . (int) $id_product;
if ($id_product_attribute) {
$redirect .= '&id_product_attribute=' . (int) $id_product_attribute;
//.........这里部分代码省略.........
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:101,代码来源:AdminStockManagementController.php
示例9: attributeImport
//.........这里部分代码省略.........
$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);
}
// This code allows us to set qty and disable depends on stock
if (isset($info['quantity']) && $info['depends_on_stock'] == 0) {
if (Shop::isFeatureActive()) {
foreach ($shops 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 (isset($info['quantity']) && $info['depends_on_stock'] == 1) {
// add stock
$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 ($stock_manager->addProduct((int) $product->id, $id_product_attribute, $warehouse, (int) $info['quantity'], 1, $price, true)) {
StockAvailable::synchronize((int) $product->id);
}
}
} else {
if (Shop::isFeatureActive()) {
foreach ($shops 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:gks-stage,项目名称:prestashop,代码行数:101,代码来源:AdminImportController.php
示例10: foreach
<th>' . $erpip->l('Quantity') . '</th>';
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
$message .= '<th>' . $erpip->l('Physical Stock') . '</th>
<th>' . $erpip->l('Usable Stock') . '</th>
<th>' . $erpip->l('Real Stock') . '</th>';
} else {
$message .= '<th>' . $erpip->l('Stock') . '</th>';
}
$message .= '</tr>';
foreach ($produits as &$prod) {
$objProd = new Product($prod['product_id']);
$message .= '<tr>';
/* If order neither sent nor cancelled nor current order */
$message .= '<td>' . $objProd->reference . '</td><td>' . $objProd->getProductName($prod['product_id'], $prod['product_attribute_id']) . '</td><td>' . $prod['product_quantity'] . '</td>';
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT')) {
$manager = StockManagerFactory::getManager();
$message .= '<td>' . $manager->getProductPhysicalQuantities($prod['product_id'], $prod['product_attribute_id']) . '</td>' . '<td>' . $manager->getProductPhysicalQuantities($prod['product_id'], $prod['product_attribute_id'], null, true) . '</td>' . '<td>' . $manager->getProductRealQuantities($prod['product_id'], $prod['product_attribute_id']) . '</td>';
} else {
$message .= '<td>' . StockAvailable::getQuantityAvailableByProduct($prod['product_id'], $prod['product_attribute_id']) . '</td>';
}
$message .= '</tr>';
}
$message .= '</table>';
print $message;
}
break;
case 'productSupplierPrice':
/* If we have called the script with a term to search */
if (Tools::isSubmit('id_product') && Tools::isSubmit('id_product_attribute')) {
$id_product = Tools::getValue('id_product');
$id_product_attribute = Tools::getValue('id_product_attribute');
开发者ID:prestamodule,项目名称:erpillicopresta,代码行数:31,代码来源:ajax.php
示例11: ajaxGetProductsForSupplyOrder
public function ajaxGetProductsForSupplyOrder()
{
require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/stock/ErpSupplyOrderClasses.php';
require_once _PS_MODULE_DIR_ . 'erpillicopresta/erpillicopresta.php';
/* manage advanced stock */
$stock_management_active = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT');
$sales_forecast_type = Configuration::get('ERP_SALES_FORECAST_CHOICE');
$id_supplier = (int) Tools::getValue('id_supplier', false);
$id_currency = (int) Tools::getValue('id_currency', false);
$id_categorie = (int) Tools::getValue('id_categorie', false);
$id_manufacturer = (int) Tools::getValue('id_manufacturer', false);
$id_warehouse = (int) Tools::getValue('id_warehouse', null);
$existing_ids = Tools::getValue('ids');
//$token_get_product = Tools::getValue('token');
$products = ErpSupplyOrderClasses::searchProduct($id_supplier, $id_categorie, $id_manufacturer, $id_currency);
if (!empty($products)) {
$advanced_stock_token = Tools::getAdminToken('AdminAdvancedStock' . (int) Tab::getIdFromClassName('AdminAdvancedStock') . (int) $this->context->employee->id);
foreach ($products as $product) {
// If product already in destination array, continue
if (strrpos($existing_ids, $product['id']) !== false) {
continue;
}
$ids = explode('_', $product['id']);
$id_product = $ids[0];
$id_product_attribute = $ids[1];
// If the advanced stock manager is activated
if ($stock_management_active == '1') {
// Get the physical and usable quantities
$query = new DbQuery();
$query->select('physical_quantity');
$query->select('usable_quantity');
$query->from('stock');
$query->where('id_product = ' . (int) $id_product . ' AND id_product_attribute = ' . (int) $id_product_attribute);
$res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
/* the two quantities */
$physical_quantity = (int) $res['physical_quantity'];
$usable_quantity = (int) $res['usable_quantity'];
// The real quantity depends of the warehouse
$manager = StockManagerFactory::getManager();
$product['stock'] = $real_quantity = (int) $manager->getProductRealQuantities($id_product, $id_product_attribute, $id_warehouse, true);
} else {
// get the free quantities
$product['stock'] = $usable_quantity = (int) Product::getQuantity($id_product, $id_product_attribute);
}
/* TAX */
/* Get the current tax */
$query = new DbQuery();
$query->select('rate');
$query->from('tax', 't');
$query->innerJoin('tax_rule', 'tr', 'tr.id_tax = t.id_tax');
$query->innerJoin('product', 'p', 'p.id_tax_rules_group = tr.id_tax_rules_group');
$query->where('p.id_product = ' . (int) $id_product);
$query->where('tr.id_country IN (SELECT id_country
FROM ' . _DB_PREFIX_ . 'address
WHERE id_supplier = ' . (int) $id_supplier . ')');
$product['tax_rate'] = round(Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query), 1);
$prices = ErpSupplyOrderClasses::getWholesalePrice((int) $id_product, (int) $id_product_attribute, (int) $id_supplier);
$product['unit_price_te'] = Tools::convertPriceFull($prices, new Currency((int) $id_currency));
// sales quantity for X rolling month
$quantity_sales = ErpSupplyOrderClasses::getQuantitySales((int) $id_product, (int) $id_product_attribute);
// if sale forecast is activ
if ($sales_forecast_type != 0) {
// if we use the 6 month rolling method
if ($sales_forecast_type == 1) {
$sales_forecasts = round(ErpSupplyOrderClasses::getProductSalesForecasts($id_product, $id_product_attribute), 1);
} else {
$sales_forecasts = round(ErpSupplyOrderClasses::getProductSalesForecastsByPeriod($id_product, $id_product_attribute), 1);
}
} else {
$sales_forecasts = 'NA';
}
// Sales gain
$sales_gains = ErpSupplyOrderClasses::getProductSalesGains($id_product, $id_product_attribute);
// Prepare the hidden json foreach line
$product['comment'] = '';
$product_json = Tools::jsonEncode($product);
echo '<tr>
<td class="product_json hide">' . $product_json . '</td>
<td><input type="checkbox" class="select_product" name="select_product"/></td>
<td>' . $product['supplier_reference'] . '</td>
<td>' . $product['reference'] . '</td>
<td>
<a href="#" class="cluetip-supply-price" title="' . $this->l('Supplier Price') . '"
rel="index.php?controller=AdminAdvancedStock&ajax=1&id_product=' . $id_product . '&id_product_attribute=' . $id_product_attribute . '&id_currency=' . $id_currency . '&task=getProductSupplierPrice&token=' . $advanced_stock_token . '" >
<img src="themes/default/img/icon-search.png">
</a>
' . $product['name'] . '
</td>';
if (Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedSupplyOrder'))) {
echo '<td align="center"> <p style="background-color:' . ErpSupplyOrderClasses::getStockLevelColor($real_quantity) . '; width:16px; height:16px"></p> </td>';
}
echo '<td align="center">' . $usable_quantity . '</td>
' . ($stock_management_active == '1' ? '
<td align="center">' . $physical_quantity . '</td>
<td align="center">' . $real_quantity . '</td>' : '') . '';
if (Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedSupplyOrder'))) {
echo '<td align="center">' . $quantity_sales . '</td>
<td align="center">' . $sales_gains . '</td>';
if (Configuration::get('ERP_SALES_FORECAST_CHOICE') != 0) {
echo '<td>' . $sales_forecasts . '</td>';
//.........这里部分代码省略.........
开发者ID:prestamodule,项目名称:erpillicopresta,代码行数:101,代码来源:AdminAdvancedSupplyOrder.php
示例12: getAllProductInStock
public static function getAllProductInStock($advanced_stock_management, $warehouse)
{
$query = new DbQuery();
// If Advanced Stock Management go through table p
|
请发表评论