// StockAvailable: updated synchronize() and updated its usage within the different stock controllers when necessary

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10331 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
bMancone
2011-11-21 11:01:33 +00:00
parent 0ce1e22813
commit 276f493dd7
8 changed files with 165 additions and 124 deletions
+3 -3
View File
@@ -332,7 +332,7 @@ class ProductCore extends ObjectModel
}
// By default, the product quantity correspond to the available quantity to sell in the current shop
$this->quantity = StockAvailable::getStockAvailableForProduct($id_product, 0, Context::getContext()->shop->getID());
$this->quantity = StockAvailable::getQuantityAvailableByProduct($id_product, 0, Context::getContext()->shop->getID());
$this->out_of_stock = $this->getOutOfStock();
$this->depends_on_stock = $this->getDependsOnStock();
@@ -2260,7 +2260,7 @@ class ProductCore extends ObjectModel
return 0;
// @since 1.5.0
return (StockAvailable::getStockAvailableForProduct($id_product, $id_product_attribute, Context::getContext()->shop->getID()));
return (StockAvailable::getQuantityAvailableByProduct($id_product, $id_product_attribute, Context::getContext()->shop->getID()));
}
/**
@@ -2463,7 +2463,7 @@ class ProductCore extends ObjectModel
else
$id_product_attribute = 0;
return ($qty <= StockAvailable::getStockAvailableForProduct($this->id, $id_product_attribute, Context::getContext()->shop->getID()));
return ($qty <= StockAvailable::getQuantityAvailableByProduct($this->id, $id_product_attribute, Context::getContext()->shop->getID()));
}
/**
+64 -49
View File
@@ -89,7 +89,7 @@ class StockAvailableCore extends ObjectModel
}
/**
* For a given {id_product, id_product_attribute and id_shop}, gets the stock id associated
* For a given {id_product, id_product_attribute and id_shop}, gets the stock available id associated
*
* @param int $id_product
* @param int $id_product_attribute Optional
@@ -97,7 +97,7 @@ class StockAvailableCore extends ObjectModel
* @return int
*/
public static function getIdStockAvailableByProductId($id_product, $id_product_attribute = null, $id_shop = null)
public static function getStockAvailableIdByProductId($id_product, $id_product_attribute = null, $id_shop = null)
{
// if there is no $id_shop, gets the context one
if (is_null($id_shop))
@@ -121,60 +121,54 @@ class StockAvailableCore extends ObjectModel
*/
public static function synchronize($id_product)
{
// inits the list of warehouse ids and product ids
$ids_warehouse = array();
$ids_product_attribute = array();
// builds query to get every warehouses/shops
$query = new DbQuery();
$query->select('id_warehouse, id_shop');
$query->from('warehouse_shop');
$query->orderBy('id_shop');
// queries to get warehouse ids grouped by shops
foreach (Db::getInstance()->executeS($query) as $row)
$ids_warehouse[$row['id_shop']][] = $row['id_warehouse'];
// gets warehouse ids grouped by shops
$ids_warehouse = Warehouse::getWarehousesGroupedByShops();
// gets all product attributes ids
$ids_product_attribute = array();
foreach (Product::getProductAttributesIds($id_product) as $id_product_attribute)
$ids_product_attribute[] = $id_product_attribute['id_product_attribute'];
$manager = StockManagerFactory::getManager();
// loops on ids_warehouse to synchronize
// loops on $ids_warehouse to synchronize quantities
foreach ($ids_warehouse as $id_shop => $warehouses)
{
$total_quantity = 0;
// if there are no product attributes
if (empty($ids_product_attribute))
$total_quantity = $manager->getProductRealQuantities($id_product, null, $warehouses, true);
// else loops on id_product_attribute and to get $total_quantity
foreach ($ids_product_attribute as $id_product_attribute)
// first, checks if the product depends on stock for the given shop $id_shop
if (self::dependsOnStock($id_product, $id_shop))
{
$quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $warehouses, true);
// inits quantity
$product_quantity = 0;
// if it's a simple product
if (empty($ids_product_attribute))
$product_quantity = $manager->getProductRealQuantities($id_product, null, $warehouses, true);
// else this product has attributes, hence loops on $ids_product_attribute
foreach ($ids_product_attribute as $id_product_attribute)
{
$quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $warehouses, true);
$query = array(
'table' => _DB_PREFIX_.'stock_available',
'data' => array('quantity' => $quantity),
'type' => 'UPDATE',
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = '.(int)$id_product_attribute.' AND id_shop = '.(int)$id_shop
);
Db::getInstance()->autoExecute($query['table'], $query['data'], $query['type'], $query['where']);
$product_quantity += $quantity;
}
// updates
// if $id_product has attributes, it also updates the sum for all attributes
$query = array(
'table' => _DB_PREFIX_.'stock_available',
'data' => array('quantity' => $quantity),
'data' => array('quantity' => $product_quantity),
'type' => 'UPDATE',
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = '.(int)$id_product_attribute.' AND id_shop = '.(int)$id_shop
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = 0 AND id_shop = '.(int)$id_shop
);
Db::getInstance()->autoExecute($query['table'], $query['data'], $query['type'], $query['where']);
$total_quantity += $quantity;
}
$query = array(
'table' => _DB_PREFIX_.'stock_available',
'data' => array('quantity' => $total_quantity),
'type' => 'UPDATE',
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = 0 AND id_shop = '.(int)$id_shop
);
// saves quantities
Db::getInstance()->autoExecute($query['table'], $query['data'], $query['type'], $query['where']);
}
}
@@ -228,15 +222,15 @@ class StockAvailableCore extends ObjectModel
* @param int $id_product
* @param int $id_product_attribute Optional
* @param int $id_shop Optional : gets context by default
* @return int
* @return int Quantity
*/
public static function getStockAvailableForProduct($id_product, $id_product_attribute = null, $id_shop = null)
public static function getQuantityAvailableByProduct($id_product, $id_product_attribute = null, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true);
// if null, it's a product without attributes
if (!$id_product_attribute)
if (is_null($id_product_attribute))
$id_product_attribute = 0;
$query = new DbQuery();
@@ -256,7 +250,7 @@ class StockAvailableCore extends ObjectModel
{
if (!parent::add($autodate, $null_values))
return false;
$this->afterSave();
$this->postSave();
}
/**
@@ -267,7 +261,7 @@ class StockAvailableCore extends ObjectModel
{
if (!parent::update($null_values))
return false;
$this->afterSave();
$this->postSave();
}
/**
@@ -275,12 +269,12 @@ class StockAvailableCore extends ObjectModel
* @see StockAvailableCore::update()
* @see StockAvailableCore::add()
*/
public function afterSave()
public function postSave()
{
if ($this->id_product_attribute == 0)
return true;
$id_stock_available = StockAvailable::getIdStockAvailableByProductId($this->id_product, 0, $this->id_shop);
$id_stock_available = StockAvailable::getStockAvailableIdByProductId($this->id_product, 0, $this->id_shop);
$total_quantity = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT SUM(quantity)
@@ -303,11 +297,11 @@ class StockAvailableCore extends ObjectModel
}
/**
* For a given id_product and id_product_attribute update the quantity available
* For a given id_product and id_product_attribute updates the quantity available
*/
public static function updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_shop = null)
{
$id_stock = self::getIdStockAvailableByProductId($id_product, $id_product_attribute, $id_shop);
$id_stock = self::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop);
if (!$id_stock)
return false;
@@ -343,4 +337,25 @@ class StockAvailableCore extends ObjectModel
($id_product_attribute ? ' AND id_product_attribute = '.(int)$id_product_attribute : '').
($id_shop ? ' AND id_shop = '.(int)$id_shop : ''));
}
/**
* For a given product, tells if it depends on the physical (usable) stock
*
* @param int $id_product
* @param int $id_shop Optional : gets context if null @see Context::getContext()
* @return bool : depends on stock @see $depends_on_stock
*/
public static function dependsOnStock($id_product, $id_shop = null)
{
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true);
$query = new DbQuery();
$query->select('depends_on_stock');
$query->from('stock_available');
$query->where('id_product = '.(int)$id_product);
$query->where('id_shop = '.(int)$id_shop);
return (bool)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
}
+22 -2
View File
@@ -267,7 +267,7 @@ class WarehouseCore extends ObjectModel
return (Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query));
}
/**
* For a given {product, product attribute} gets warehouse list
*
@@ -280,7 +280,7 @@ class WarehouseCore extends ObjectModel
{
if (is_null($id_shop))
$id_shop = Context::getContext()->shop->getID(true);
$query = new DbQuery();
$query->select('wpl.id_warehouse');
$query->from('warehouse_product_location wpl');
@@ -317,6 +317,26 @@ class WarehouseCore extends ObjectModel
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
}
/**
* Gets ids of warehouses, grouped by ids of shops
*
* @return array
*/
public static function getWarehousesGroupedByShops()
{
$ids_warehouse = array();
$query = new DbQuery();
$query->select('id_warehouse, id_shop');
$query->from('warehouse_shop');
$query->orderBy('id_shop');
// queries to get warehouse ids grouped by shops
foreach (Db::getInstance()->executeS($query) as $row)
$ids_warehouse[$row['id_shop']][] = $row['id_warehouse'];
return $ids_warehouse;
}
/**
* Gets the number of products in the current warehouse
*
+59 -59
View File
@@ -46,59 +46,59 @@ class AdminCartsController extends AdminController
$this->fieldsDisplay = array(
'id_cart' => array(
'title' => $this->l('ID'),
'align' => 'center',
'title' => $this->l('ID'),
'align' => 'center',
'width' => 25
),
'id_order' => array(
'title' => $this->l('ID Order'),
'title' => $this->l('ID Order'),
'align' => 'center', 'width' => 25
),
'customer' => array(
'title' => $this->l('Customer'),
'width' => 80,
'title' => $this->l('Customer'),
'width' => 80,
'filter_key' => 'c!lastname'
),
'total' => array(
'title' => $this->l('Total'),
'callback' => 'getOrderTotalUsingTaxCalculationMethod',
'orderby' => false,
'search' => false,
'width' => 50,
'align' => 'right',
'prefix' => '<b>',
'suffix' => '</b>',
'title' => $this->l('Total'),
'callback' => 'getOrderTotalUsingTaxCalculationMethod',
'orderby' => false,
'search' => false,
'width' => 50,
'align' => 'right',
'prefix' => '<b>',
'suffix' => '</b>',
'currency' => true
),
'carrier' => array(
'title' => $this->l('Carrier'),
'width' => 25,
'align' => 'center',
'callback' => 'replaceZeroByShopName',
'title' => $this->l('Carrier'),
'width' => 25,
'align' => 'center',
'callback' => 'replaceZeroByShopName',
'filter_key' => 'ca!name'
),
'date_add' => array(
'title' => $this->l('Date'),
'width' => 90,
'align' => 'right',
'type' => 'datetime',
'title' => $this->l('Date'),
'width' => 90,
'align' => 'right',
'type' => 'datetime',
'filter_key' => 'a!date_add'
),
'id_guest' => array(
'title' => $this->l('Online'),
'width' => 25,
'align' => 'center',
'type' => 'bool',
'filter_key' => 'guest',
'tmpTableFilter' => true,
'title' => $this->l('Online'),
'width' => 25,
'align' => 'center',
'type' => 'bool',
'filter_key' => 'guest',
'tmpTableFilter' => true,
'icon' => array(0 => 'blank.gif', 1 => 'tab-customers.gif')
)
);
$this->shopLinkType = 'shop';
parent::__construct();
}
public function initView()
{
if (!($cart = $this->loadObject(true)))
@@ -120,7 +120,7 @@ class AdminCartsController extends AdminController
$total_discounts = $summary['total_discounts_tax_exc'];
$total_wrapping = $summary['total_wrapping_tax_exc'];
$total_price = $summary['total_price_without_tax'];$total_shipping = $summary['total_shipping_tax_exc'];
}
}
else
{
$total_products = $summary['total_products_wt'];
@@ -152,8 +152,8 @@ class AdminCartsController extends AdminController
WHERE id_product = '.(int)($product['id_product']).' AND cover = 1');
$productObj = new Product($product['id_product']);
$product['qty_in_stock'] = StockAvailable::getStockAvailableForProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int)$order->id_shop);
$product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct($product['id_product'], isset($product['id_product_attribute']) ? $product['id_product_attribute'] : null, (int)$order->id_shop);
$imageProduct = new Image($image['id_image']);
$product['image'] = (isset($image['id_image']) ? cacheImage(_PS_IMG_DIR_.'p/'.$imageProduct->getExistingImgPath().'.jpg', 'product_mini_'.(int)($product['id_product']).(isset($product['id_product_attribute']) ? '_'.(int)($product['id_product_attribute']) : '').'.jpg', 45, 'jpg') : '--');
}
@@ -175,7 +175,7 @@ class AdminCartsController extends AdminController
return parent::initView();
}
public function ajaxPreProcess()
{
$id_customer = (int)Tools::getValue('id_customer');
@@ -195,7 +195,7 @@ class AdminCartsController extends AdminController
$this->context->cart->id_lang = (($id_lang = (int)Tools::getValue('id_lang')) ? $id_lang : Configuration::get('PS_LANG_DEFAULT'));
if (!$this->context->cart->id_currency)
$this->context->cart->id_currency = (($id_currency = (int)Tools::getValue('id_currency')) ? $id_currency : Configuration::get('PS_CURRENCY_DEFAULT'));
$addresses = $customer->getAddresses((int)$this->context->cart->id_lang);
$id_address_delivery = (int)Tools::getValue('id_address_delivery');
$id_address_invoice = (int)Tools::getValue('id_address_delivery');
@@ -221,7 +221,7 @@ class AdminCartsController extends AdminController
$errors[] = Tools::displayError('Invalid product');
if (sizeof($errors))
die(Tools::jsonEncode($errors));
if ($this->context->cart->deleteProduct($id_product, $id_product_attribute))
echo Tools::jsonEncode($this->ajaxReturnVars());
}
@@ -238,11 +238,11 @@ class AdminCartsController extends AdminController
elseif (!$qty = Tools::getValue('qty') OR $qty == 0)
$errors[] = Tools::displayError('Invalid quantity');
if (($id_product_attribute = Tools::getValue('id_product_attribute')) != 0)
{
{
if(!Product::isAvailableWhenOutOfStock($product->out_of_stock) && !Attribute::checkAttributeQty((int)$id_product_attribute, (int)$qty))
$errors[] = Tools::displayError('There is not enough product in stock');
}
else
else
if(!$product->checkQty((int)$qty))
$errors[] = Tools::displayError('There is not enough product in stock');
if (!$id_customization = (int)Tools::getValue('id_customization', 0) AND !$product->hasAllRequiredCustomizableFields())
@@ -251,13 +251,13 @@ class AdminCartsController extends AdminController
if (!count($errors))
{
if (!($qty_upd = $this->context->cart->updateQty($qty, $id_product, (int)$id_product_attribute, (int)$id_customization, 'up')))
$errors[] = Tools::displayError('You already have the maximum quantity available for this product.');
$errors[] = Tools::displayError('You already have the maximum quantity available for this product.');
}
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
}
public function ajaxProcessUpdateCarrier()
{
if(Validate::isBool(($recyclable = (int)Tools::getValue('recyclable'))))
@@ -269,7 +269,7 @@ class AdminCartsController extends AdminController
$this->context->cart->save();
echo Tools::jsonEncode($this->ajaxReturnVars());
}
public function ajaxProcessUpdateCurrency()
{
$currency = new Currency((int)Tools::getValue('id_currency'));
@@ -306,20 +306,20 @@ class AdminCartsController extends AdminController
$this->context->cart = $new_cart['cart'];
echo Tools::jsonEncode($this->ajaxReturnVars());
}
}
public function ajaxProcessDeleteVoucher()
{
if ($this->context->cart->removeCartRule((int)Tools::getValue('id_cart_rule')))
echo Tools::jsonEncode($this->ajaxReturnVars());
}
public function ajaxProcessAddVoucher()
{
$errors = array();
$customer = new Customer((int)$this->context->cart->id_customer);
if (!$id_cart_rule = Tools::getValue('id_cart_rule') OR !$cartRule = new CartRule((int)$id_cart_rule))
$errors[] = Tools::displayError('Invalid voucher');
elseif ($err = $cartRule->checkValidity($this->context))
@@ -329,16 +329,16 @@ class AdminCartsController extends AdminController
$errors[] = Tools::displayError('Can\'t add the voucher');
echo Tools::jsonEncode(array_merge($this->ajaxReturnVars(), array('errors' => $errors)));
}
public function ajaxProcessUpdateAddresses()
{
if (($id_address_delivery = (int)Tools::getValue('id_address_delivery')) && $address_delivery = new Address((int)$id_address_delivery) && $address_delivery->id_customer = $this->context->cart->id_customer)
$this->context->cart->id_address_delivery = (int)$address_delivery->id;
if (($id_address_invoice = (int)Tools::getValue('id_address_invoice')) && $address_invoice = new Address((int)$id_address_invoice) && $address_invoice->id_customer = $this->context->cart->id_customer)
$this->context->cart->id_address_invoice = (int)$address_invoice->id;
$this->context->cart->save();
echo Tools::jsonEncode($this->ajaxReturnVars());
}
@@ -364,23 +364,23 @@ class AdminCartsController extends AdminController
$summary['total_tax'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($summary['total_tax'], $currency), $currency));
$summary['total_price_without_tax'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($summary['total_price_without_tax'], $currency), $currency));
$summary['total_price'] = str_replace($currency->sign, '', Tools::displayPrice(Tools::convertPrice($summary['total_price'], $currency), $currency));
return $summary;
}
protected function getAvailableCarriers()
{
$customer = new Customer((int)$this->context->cart->id_customer);
return Carrier::getCarriersForOrder(Address::getZoneById($this->context->cart->id_address_delivery), $customer->getGroups());
}
public function displayAjaxSearchCarts()
{
$id_customer = (int)Tools::getValue('id_customer');
$carts = Cart::getCustomerCarts((int)$id_customer);
$orders = Order::getCustomerOrders((int)$id_customer);
$customer = new Customer((int)$id_customer);
if (count($carts))
foreach ($carts AS $key => &$cart)
{
@@ -394,7 +394,7 @@ class AdminCartsController extends AdminController
foreach ($orders AS &$order)
$order['total_paid_real'] = Tools::displayPrice(Tools::convertPrice($order['total_paid_real'], $currency), $currency);
if ($orders || $carts)
$to_return = array_merge($this->ajaxReturnVars(),
$to_return = array_merge($this->ajaxReturnVars(),
array('carts' => $carts,
'orders' => $orders,
'found' => true));
@@ -403,7 +403,7 @@ class AdminCartsController extends AdminController
echo Tools::jsonEncode($to_return);
}
public function ajaxReturnVars()
{
@@ -416,22 +416,22 @@ class AdminCartsController extends AdminController
'id_cart' => $id_cart,
'link_order' => $this->context->link->getPageLink('order', false, (int)$this->context->cart->id_lang, 'step=3&recover_cart='.$id_cart.'&token_cart='.md5(_COOKIE_KEY_.'recover_cart_'.$id_cart)));
}
public function displayAjaxGetSummary()
{
echo Tools::jsonEncode($this->ajaxReturnVars());
}
public function ajaxProcessUpdateProductPrice()
{
}
public static function getOrderTotalUsingTaxCalculationMethod($id_cart)
{
return Cart::getTotalCart($id_cart, true);
}
public static function replaceZeroByShopName($echo, $tr)
{
return ($echo == '0' ? Configuration::get('PS_SHOP_NAME') : $echo);
+2 -2
View File
@@ -575,7 +575,7 @@ class AdminOrdersControllerCore extends AdminController
$productObj = new Product((int)$product['id_product'], false, (int)$this->context->language->id);
$combinations = array();
$attributes = $productObj->getAttributesGroups((int)$this->context->language->id);
$product['qty_in_stock'] = StockAvailable::getStockAvailableForProduct((int)$product['id_product'], 0, (int)$this->context->shop->getID());
$product['qty_in_stock'] = StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], 0, (int)$this->context->shop->getID());
foreach($attributes AS $attribute)
{
if (!isset($combinations[$attribute['id_product_attribute']]['attributes']))
@@ -586,7 +586,7 @@ class AdminOrdersControllerCore extends AdminController
if (!isset($combinations[$attribute['id_product_attribute']]['price']))
$combinations[$attribute['id_product_attribute']]['price'] = Tools::displayPrice(Tools::convertPrice(Product::getPriceStatic((int)$product['id_product'], true, $attribute['id_product_attribute']), $currency), $currency);
if (!isset($combinations[$attribute['id_product_attribute']]['qty_in_stock']))
$combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getStockAvailableForProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID());
$combinations[$attribute['id_product_attribute']]['qty_in_stock']= StockAvailable::getQuantityAvailableByProduct((int)$product['id_product'], $attribute['id_product_attribute'], (int)$this->context->shop->getID());
}
foreach ($combinations AS &$combination)
@@ -59,7 +59,7 @@ class AdminProductsControllerCore extends AdminController
$this->imageType = 'jpg';
$this->context = Context::getContext();
$this->_defaultOrderBy = 'position';
$this->fieldsDisplay = array(
'id_product' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 20),
'image' => array('title' => $this->l('Photo'), 'align' => 'center', 'image' => 'p',
@@ -2435,7 +2435,7 @@ class AdminProductsControllerCore extends AdminController
public function initFormInformations($product, $languages, $defaultLanguage)
{
$data = $this->context->smarty->createData();
// autoload rich text editor (tiny mce)
$iso = $this->context->language->iso_code;
$this->tpl_form_vars['iso'] = file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso.'.js') ? $iso : 'en';
@@ -2444,7 +2444,7 @@ class AdminProductsControllerCore extends AdminController
$this->addJS(_PS_JS_DIR_.'tiny_mce/tiny_mce.js');
$this->addJS(_PS_JS_DIR_.'tinymce.inc.js');
$currency = $this->context->currency;
$data->assign('languages',$languages);
@@ -3048,10 +3048,8 @@ class AdminProductsControllerCore extends AdminController
$total_quantity += $physical_quantity[$attribute['id_product_attribute']];
// Get available quantity for the current product attribute in the current shop
$available_quantity[$attribute['id_product_attribute']] = StockAvailable::getStockAvailableForProduct(
(int)$obj->id,
$attribute['id_product_attribute']
);
$available_quantity[$attribute['id_product_attribute']] = StockAvailable::getQuantityAvailableByProduct((int)$obj->id,
$attribute['id_product_attribute']);
// Get all product designation
$product_designation[$attribute['id_product_attribute']] = rtrim($obj->name[$this->context->language->id].' - '.$attribute['attribute_designation'], ' - ');
@@ -3216,7 +3214,7 @@ class AdminProductsControllerCore extends AdminController
if (Tools::getValue('id_product_attribute') === false)
return Tools::jsonEncode(array('error' => 'Undefined id product attribute'));
// @todo : Product class should handle that
$stock_available = new StockAvailable(StockAvailable::getIdStockAvailableByProductId($product->id, (int)Tools::getValue('id_product_attribute')));
$stock_available = new StockAvailable(StockAvailable::getStockAvailableIdByProductId($product->id, (int)Tools::getValue('id_product_attribute')));
if (!$stock_available->id)
{
$stock_available->id_product = $product->id;
@@ -3262,7 +3260,7 @@ class AdminProductsControllerCore extends AdminController
</tr>';
$json = array(
'status' => 'ok',
'id'=>$image_obj->id,
'id'=>$image_obj->id,
'path' => _THEME_PROD_DIR_.$img_path.'.jpg',
'path_small' => _THEME_PROD_DIR_.$img_path.'-small.jpg',
'position' => $image['position'],
@@ -618,7 +618,10 @@ class AdminStockManagementControllerCore extends AdminController
$stock_manager = StockManagerFactory::getManager();
if ($stock_manager->addProduct($id_product, $id_product_attribute, $warehouse, $quantity, $id_stock_mvt_reason, $price, $usable))
{
StockAvailable::synchronize($id_product);
Tools::redirectAdmin($redirect.'&conf=1');
}
else
$this->_errors[] = Tools::displayError('An error occured. No stock was added.');
}
@@ -636,7 +639,10 @@ class AdminStockManagementControllerCore extends AdminController
$removed_products = $stock_manager->removeProduct($id_product, $id_product_attribute, $warehouse, $quantity, $id_stock_mvt_reason, $usable);
if (count($removed_products) > 0)
{
StockAvailable::synchronize($id_product);
Tools::redirectAdmin($redirect.'&conf=2');
}
else
$this->_errors[] = Tools::displayError('It is not possible to remove the specified quantity or an error occured. No stock was removed.');
}
@@ -1271,6 +1271,8 @@ class AdminSupplyOrdersControllerCore extends AdminController
$supplier_receipt_history->add();
$supply_order_detail->save();
$supply_order->save();
// synchronizes
StockAvailable::synchronize($id_product);
}
else
$this->_errors[] = Tools::displayError($this->l('Something went wrong when adding products in warehouse'));