Hot answers tagged

133

You can reset the indexer through command line with indexer:reset command. This will give the list of indexes name: php bin/magento indexer:info Output: design_config_grid Design Config Grid customer_grid Customer Grid catalog_category_product Category Products catalog_product_category ...


61

Solution:1 Create Helper file Stock.php in your module <?php namespace {VendorName}\{ModuleName}\Helper; class Stock extends \Magento\Framework\App\Helper\AbstractHelper { /** * @var Magento\CatalogInventory\Api\StockStateInterface */ protected $stockState; /** * Output constructor. * @param \Magento\Framework\App\...


23

First of all the values shouldn't even be important. Use in your code these constants Mage_Catalog_Model_Product_Status::STATUS_ENABLED and Mage_Catalog_Model_Product_Status::STATUS_DISABLED. The reason I found so far is that when you want to create a product, in most cases you want it to be enabled. If the value for status disabled was 0, then this will be ...


23

Like some comments have mentioned, you want to use dependency injection. Do not use the object manager; in other words, do not do what any of the other responses state. The following technique can be applied anywhere. For Blocks, set the class to your class in layout XML, which extends the original, and inject the right information. Inject the ...


19

It's working for me. $products = Mage::getModel('catalog/product')->getCollection(); foreach ($products as $_product) { $stock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product); echo $stock->getQty(); echo $stock->getMinQty(); echo $stock->getMinSaleQty(); }


18

Can you please try below code? It will save inventory data. $product->setStockData(['qty' => $stockData, 'is_in_stock' => $stockData]); $product->setQuantityAndStockStatus(['qty' => $stockData, 'is_in_stock' => $stockData]); $product->save();


14

When I faced this kind of situation I had to run the following SQL query directly into the database: UPDATE indexer_state SET status = 'valid'; I was not able to to find any option to force reindexing when an index has failed previously.


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(); $...


12

How to get stock quantity of each product in Magento 2 for controller or block inject \Magento\CatalogInventory\Api\StockStateInterface public function __construct( \Magento\CatalogInventory\Api\StockStateInterface $stockItem ) { $this->stockItem = $stockItem; } and then use getStockQty function to get qty $this->stockItem->...


11

The indexing process writes the values at first in the _idx table so it won't interfere with the read actions on the main table while its running. When all the values are inserted in the _idx table then all the values are copied to the main table. Take a look at how Mage_CatalogInventory_Model_Resource_Indexer_Stock::reindexAll looks like. Also see my ...


10

Well, this is a bug indeed, but I came up with a fix! The problem is that Mage_Core_Model_Translate translator isn't initialized by cron.php, since this script doesn't load() translate application area... The fix is to initialize the translator after emulation, on Mage_ProductAlert_Model_Email::send: $initialEnvironmentInfo = $appEmulation->...


10

You will need to join the table to get qty. See below code: $products = Mage::getModel('catalog/product') ->getCollection() //->addAttributeToSelect('*') ->addAttributeToSelect(array('name', 'thumbnail', 'weight' ,'price','description')) ->joinField( 'qty', 'cataloginventory/stock_item', 'qty', '...


10

isSaleable() is just an alias of isSalable() : /** * Alias for isSalable() * * @return bool */ public function isSaleable() { return $this->isSalable(); } The isSalable() method looks complex but it simply checks for the availability of the product via the isAvailable() method: /** * Check is product available for sale * * @return bool */ ...


10

The definition of salable quantity includes the quantity minQty. Nowadays MSI is the approach. So no other methods, shortcuts, objectmanagers or M1 flashback code. It all has to be an MSI approach that will be compatible with future versions of M2. So, let's get into it: $websiteCode = $this->storeManager->getWebsite()->getCode(); $stock =...


10

In our case the issue was related to a migration from Magento 1 to Magento 2 via migration data tool. The problem is that default value for the attribute 'links_exist' is 0 in Magento 1. However in Magento 2 default value for 'links_exist' is null. Because of that following validation fails File: vendor/magento/module-catalog/view/frontend/templates/product/...


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]/...


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

By changing the settings in System > Config > Inventory will only affect the defaults when you create new products, you still need to enable each product to allow backorders. Easiest way to do this is select all products you want to allow to be backordered, then select Update attributes from the actions drop down and click submit. Once the screen has ...


9

<?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $StockState = $objectManager->get('\Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku'); $qty = $StockState->execute($_product->getSku()); echo ($qty[0]['qty']); ?> You can get only the saleable quantity by the following above code.


8

On MySQL run: SET SQL_SAFE_UPDATES = 0; update indexer_state set status = 'invalid' where status != 'valid'; Then on your terminal run: php bin/magento indexer:reindex It normally happens when the memory limit is few, so increase on your .htaccess or NGINX config.


8

This is a bug. Basically those events are dispatched dynamically in Magento\Framework\Model\AbstractModel in the afterSave() method: public function afterSave() { $this->cleanModelCache(); $this->_eventManager->dispatch('model_save_after', ['object' => $this]); $this->_eventManager->dispatch('clean_cache_by_tags', ['object' =&...


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

Use following query : "SELECT cpe.sku, csi.qty FROM catalog_product_entity cpe RIGHT JOIN cataloginventory_stock_item csi ON cpe.entity_id = csi.item_id GROUP BY cpe.sku ORDER BY cpe.sku ASC"; You can check in stock or out of stock according to the returned quantity


6

Here is an example how to access the is salable state or the stock quantity of all associated child products. this first method is simply to fetch the child product ids from the bundled product. function getBundledProductChildIds(Mage_Catalog_Model_Product $product) { $childrenIds = []; if ($product->getTypeId() == Mage_Catalog_Model_Product_Type:...


6

It seems that they changed getUsedProducts method in Mage_Catalog_Model_Product_Type_Configurable class. Magento 1.9.0.1 $collection = $this->getUsedProductCollection($product) ->addAttributeToSelect('*') ->addFilterByRequiredOptions(); Magento 1.9.1.0 $collection = $this->getUsedProductCollection($product) ->...


6

Magento does have composite products (bundles and configurables), but does not do what you want out of the box, at least not in a way that would then make sense to the customer. You're actually getting into "resource planning" territory with this approach, something which Magento does not really do, as that tends to be more of an enterprise-level concern. ...


6

The below script will be helpful to get the product stock qty, min qty and stock details in magento2. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $productStockObj = $objectManager->get('Magento\CatalogInventory\Api\StockRegistryInterface')->getStockItem($productId); print_r($productStockObj->getData());


6

Adding stock information to product collections can be done with a single line: /* Mage_Catalog_Model_Resource_Product_Collection */ $products->setFlag('require_stock_items', true); This flag is used in catalog_product_collection_load_after observer: /** * Add information about producs stock status to collection * Used in for product collection after ...


6

the cataloginventory_stock_status is the one that is used for reading in the frontend. In order to not interfere with the table reads, when the stock index is running it is writing in the _tmp and/or _idx table and when it's done, the values are moved to the main table. The temporary table used is determined by this method \Magento\CatalogInventory\Model\...


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