35

This works for me: $item = ['qty' => 11]; // For example $product->setStockData(['qty' => $item['qty'], 'is_in_stock' => $item['qty'] > 0]); $product->save(); Edit: This is no longer the correct way to handle this, because $product->save() is deprecated since Magento 2.1. The correct way to do this is by using the ...


27

It has been some time ago that I build something for this, I had to listen to multiple observers because they where not all handled by the save of the cataloginventory, I have to following code: <events> <cataloginventory_stock_item_save_commit_after> <observers> <genmato_stockupdate> ...


19

Check your value for use_config_manage_stock, it could be defaulting to that default value, so you'll want to set use_config_manage_stock to 0 as well as manage_stock to 0 too, depending on your settings. $_product->setStockData(array( 'use_config_manage_stock' => 0, 'is_in_stock' => 1, 'qty' => 9999, ...


18

If you are using the @giel-berkers solution, you may need to set isInStock also, because it will not be automatically sets. So, the following code was useful for me: public function __construct( \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry ) { $this->stockRegistry = $stockRegistry; parent::__construct(); } public ...


14

This is actually a feature of Magento. Setting Display out of stock products to No only hides them from the category list pages and the search results page. The product page is actually still available. Starting with CE 1.9.1 there is even a message under the config setting Display out of stock products saying Products will still be shown by direct product ...


13

Try this instead: $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product); and then set and save your changes as before.


12

Warning, using setSkipSaleableCheck(true) appears to have an additional effect of showing disabled products in the dropdown. The function which is affected by this setting is in Mage_Catalog_Block_Product_View_Type_Configurable: public function getAllowProducts() { if (!$this->hasAllowProducts()) { $products = array(); $...


11

The order that events are dispatched in is dependent on the order in which the modules are loaded. Since you are needing to be sure that the CatalogInventory module's observers fire before yours does, what you need to do is simply configure your module to depend on the Mage_CatalogInventory module. You can do this by adding a depends node to the code in your ...


9

There are at least two ways to implement a multi warehouse in Magento; we discussed about this topic during a Magento U course. The first is that of exploiting the fact that Magento is virtually ready to use multiple inventories as you higlighted. This is the most complex way because you should implement indexing logic. The second way is that of ...


9

The "code" solution: Create your own module, and in the config.xml file of the module add these 2 events inside the <frontend> tag: <events> <controller_action_layout_render_before_catalog_product_view> <observers> <[namespace]_[module]> <class>[module]/...


8

Aside from the built-in RSS feed, there are two ways to actually send yourself an email - the actual answer to your actual question: Purchase an extension: I have no experience with this extension, but was mentioned on a StackOverflow: http://www.magentocommerce.com/magento-connect/irzoo-lowstockreport-1278.html Do it yourself: Create an observer for ...


8

Try the following. you shouldn't have to load a new stock object $product->setStockData( array( 'is_in_stock' => 0, 'qty' => 0, 'manage_stock' => 1, 'use_config_notify_stock_qty' => 1 ) ); And the just save the product as you did in your script


8

I struggled with this same issue. While debugging I found that the product data has a quantity_and_stock_status array, so I tried setting it with: $product->setQuantityAndStockStatus(['qty' => $quantity, 'is_in_stock' => 1]); and it started working for me. I still am setting the $product->setStockData too if you edit a product and inspect element ...


8

One thing the other answers missed is that if you setQty($qty), it will apply the exact value you provide. But if a sale was made for that product a moment before your save, the original qty could have changed. So what you really want to do is tell Magento the difference you want to apply to the qty. Fortunately, Magento 2 provides a nice mechanism for this....


7

The order in which events are dispatched cannot be easily guaranteed. They're dependent on the order in which modules are loaded. Typically all core event observers will be called prior to community and local code pool observers. There is a method to force magento observers to fire after a custom one by "faking" a dependency of a core module to a local or ...


7

Having a look at this table's indexes it does seem to function completely as a standalone addition to the database, for the time being. If you look at the assignProduct() method around line 263 of app/code/core/Mage/CatalogInventory/Model/Stock/Item.php you'll notice that it references the method itself: Mage::getSingleton('cataloginventory/stock_status')...


7

It looks to me like qty in cataloginventory_stock_item is the source of truth, and qty in cataloginventory_stock_status is the cached/indexed value. Rebuilding the Stock Status index appears to always copy the value from cataloginventory_stock_item into cataloginventory_stock_status. If there are multiple websites, there will also be a record for each ...


7

Check inventory_reservation: https://github.com/magento-engcom/msi/wiki/Salable-Quantity-Calculation-and-Mechanism-of-Reservations If you don't wan't to use MSI (and stick to CatalogInventory_* from 2.2.7)- turn the Inventory_* modules off: https://devdocs.magento.com/guides/v2.3/comp-mgr/install-extensions/inventory-management-installation.html#disable-...


6

If you're not deep into MySQL queries or if you don't have a direct access to database, you can do the same in the Magento back-office. Go to Catalog -> Manage product, in the product table header on the left click on "select all" and then in the same bar at right "updated attribute" and "submit". You can do that operation filtering only the product ...


6

If possible go with Magento's native API (with extensive documentation). This won't be able to push but you can pull data out. Make sure you don't request the API to much as this will slow down the Magento installation. For example; updating products will set off the flat product data indexers which can be pretty heavy on the system. If the API is too ...


6

check your stock setting in admin panel Advance Inventory->manage stock set to yes if you want to reduce quantity


6

Check below settings. Admin > Store > Configuration > Catalog > Inventory > Stock option > Decrease Stock When Order is Placed Set it to yes. If you have a multi-website or multi-store then change the same setting for all store.


5

I think I'd go with configurable products. Create the event as a configurable product. Each slot/price level (I'll call it ticket category for my explanation) is a simple product which isn't visible individually. (I hope I understood what you want to do. I imagine something like a concert or sports game with tickets for seats in different categories, e.g. ...


5

A general answer Observers are executed by area first, then by module loading order That means, all observers registered in <global> are executed before all observers registered in <frontend> or <adminhtml>. Within an area, observers are executed in the order they appear in the merged config XML tree, which means technically in the order ...


5

I would not delete the order but just cancel them and with a cronjob (either a script or Magento extension) you can do this. Run it daily to clean up the orders. Results are logged to var/logs/cancelorders.log for reference. $collection = Mage::getModel('sales/order')->getCollection() ->addFieldToFilter('updated_at', Mage::getModel('core/date')-&...


5

The information about the return to stock is not kept in the database. When a credit memo is created the method Mage_CatalogInventory_Model_Observer::refundOrderInventory() is called. In there an array is built with the qtys that need to return to stock based on the fact that the creditmemo item was previously marked with setBackToStock(true) or if the ...


5

You cannot use any event related to the stock item model, because Magento uses an optimized SQL query to decrease stock for all ordered items at once, bypassing the model. I solved this with a rewrite of Mage_CatalogInventory_Model_Stock where I added an additional event: <?php /** * Add events to observe stock qty change * * @author Fabian ...


5

The inventory is kept in the table cataloginventory_stock_item. The column you are looking for is qty. Run this query: UPDATE `cataloginventory_stock_item` SET `qty` = 1; But make sure you backup first and rebuild the indexes when you are done.


5

You can try the following code public function __construct( \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry ) { $this->stockRegistry = $stockRegistry; } // you can pass $product object to the function public function getStockStatus($product) { return $this->stockRegistry->getStockItem($product->getId()); } You ...


5

If you are using the only simple products at your system then using Stock Status field check then Product status is Ok. But when you have configurable or bundle or group product then it is not a good idea to use Stock Status field to check stock status. Because of these types of products stock status, is depends on its child Products status. That is ...


Only top voted, non community-wiki answers of a minimum length are eligible