Author: james

How to get and update stock status in Magento 2.3 MSI

The Old Way The old way of getting stock info from Magento 2 was using stockRegistry and it would output or input an array. $productRepository = $objectManager->get(‘\Magento\Catalog\Api\ProductRepositoryInterface’); $stockRegistry = $objectManager->create(‘\Magento\CatalogInventory\Api\StockRegistryInterface’); $sku=”STARTNET_ITEM_123″; $product=$productRepository->get($sku); $stockdata = $stockRegistry->getStockStatus($product->getId(), 1); // for store id

read more

Magento2 sorting collection order

Collections in Magento2 can be a real pain. Was having problems with sorting a category getProductCollection collection into position order! The products were just displaying in random order(or rather ID number order). $categoryId=891; $category = $this->_categoryFactory->create(); $category->load($categoryId); $products = $category->getProductCollection();$products->addAttributeToSelect(‘*’);$products->setOrder(“cat_index_position”,’ASC’);

read more

How to test Magento2 REST API with Postman

This assumes you’ve created a new Integration in Magento 2 by going to M2 Dashboard -> System -> Integrations. Create a new one, give it Resource Access to ALL and save. Then Authorise it, then it’ll create new consumer_key,consumer_secret,access_token,token_secret values

read more

Adding a sub-domain Website to Siteground

I found problems adding an already used domain as a website eg. if startnet.co.uk was already on Siteground it didn’t like me adding test.startnet.co.uk when creating a website. So found this solution: Login to Siteground. Add a new Website Pick

read more