Categories
CMS Magento Mastering Development

REST API Get products info based on name Magento 1.9

I have created a custom module but unable to get products based on categories name, If I pass a single name it is working. app/etc/modules/Custom_Restapi.xml <?xml version=”1.0″?> <config> <modules> <Custom_Restapi> <active>true</active> <codePool>local</codePool> <depends> Mage_Api2 </depends> </Custom_Restapi> </modules> </config> app/code/local/Custom/Restapi/config.xml <config> <modules> <Custom_Restapi> <version>0.1.0</version> </Custom_Restapi> </modules> <global> <models> <custom_restapi> <class>Custom_Restapi_Model</class> </custom_restapi> </models> </global> </config> app/code/local/Custom/Restapi/api2.xml <?xml […]

Categories
CMS Magento Mastering Development

Product grid checkbox input at sales rule form Magento 2 not working

I’m using Magento 2.3.4 and want to add product grid with checkbox as an input for sales rule form (shopping cart price rule), i follow the instruction to add product grid input from here but when I print the $_POST value the input data does not exist. Here’s my code: app/code/Becom/Freegift/Block/Adminhtml/Products/Edit/Tab/Product.php namespace Becom\Freegift\Block\Adminhtml\Products\Edit\Tab; use Magento\Backend\Block\Widget\Grid; […]

Categories
CMS Magento Mastering Development

Product grid checkbox input at sales rule form Magento 2 not working

I’m using Magento 2.3.4 and want to add product grid with checkbox as an input for sales rule form (shopping cart price rule), i follow the instruction to add product grid input from here but when I print the $_POST value the input data does not exist. Here’s my code: app/code/Becom/Freegift/Block/Adminhtml/Products/Edit/Tab/Product.php namespace Becom\Freegift\Block\Adminhtml\Products\Edit\Tab; use Magento\Backend\Block\Widget\Grid; […]

Categories
CMS Development Magento

Get all visible products whose Quantity greater than 0 in Magento2

I have written a product collection to get all products whose quantity is greater than 0. Here is my code for the collection <?php $websiteId = $this->storeManager->getStore()->getWebsiteId(); $collection = $this->_productCollectionFactory->create(); $collection->setVisibility($this->_productVisibility->getVisibleInSiteIds()); $collection->addAttributeToSelect(‘*’); $collection->addAttributeToSelect(array(‘entity_id’,’sku’)); $collection->addWebsiteFilter($websiteId); $collection->addStoreFilter(); $collection->addAttributeToSelect(‘*’)->setFlag(‘has_stock_status_filter’, true); $collection->addAttributeToFilter(‘visibility’, \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH); $this->_stockFilter->addInStockFilterToCollection($collection); $collection = $collection ->joinField(‘qty’, ‘cataloginventory_stock_item’, ‘qty’, ‘product_id=entity_id’, ‘.stock_id=1’, ‘left’ ) ->addAttributeToSelect(‘stock_status’) ->addAttributeToSort ( ‘entity_id’, ‘DESC’ […]

Categories
CMS Development Magento

Use of sub query within collection in Magento

I am using a subquery in Magento collection, Here is my code. $websiteId = $this->storeManager->getStore()->getWebsiteId(); $collection = $this->_productCollectionFactory->create(); $collection->setVisibility($this->_productVisibility->getVisibleInSiteIds()); $collection->addAttributeToSelect(‘*’); $collection->addAttributeToSelect(array(‘entity_id’,’sku’)); $collection->addWebsiteFilter($websiteId); $collection->addStoreFilter(); $collection->addAttributeToFilter(‘visibility’, \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH); $this->_stockFilter->addInStockFilterToCollection($collection); $collection = $collection ->joinField(‘qty’, ‘cataloginventory_stock_item’, ‘qty’, ‘product_id=entity_id’, ‘.stock_id=1’, ‘left’ ) ->addAttributeToSelect(‘stock_status’) ->addAttributeToSort ( ‘entity_id’, ‘DESC’ ) ->addAttributeToFilter(‘status’,\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED); $collection->addAttributeToFilter(array( array( ‘attribute’ => ‘qty’, ‘gt’=>0), array( ‘attribute’ => ‘type_id’, ‘eq’ => […]

Categories
CMS Development Magento

Get all visible products whose Quantity greater than 0 in Magento2

I have written a product collection to get all products whose quantity is greater than 0. Here is my code $websiteId = $this->storeManager->getStore()->getWebsiteId(); $collection = $this->_productCollectionFactory->create(); $collection->setVisibility($this->_productVisibility->getVisibleInSiteIds()); $collection->addAttributeToSelect(‘*’); $collection->addAttributeToSelect(array(‘entity_id’,’sku’)); $collection->addWebsiteFilter($websiteId); $collection->addStoreFilter(); $collection->addAttributeToSelect(‘*’)->setFlag(‘has_stock_status_filter’, true); $collection->addAttributeToFilter(‘visibility’, \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH); $this->_stockFilter->addInStockFilterToCollection($collection); $collection = $collection ->joinField(‘qty’, ‘cataloginventory_stock_item’, ‘qty’, ‘product_id=entity_id’, ‘.stock_id=1’, ‘left’ ) ->addAttributeToSelect(‘stock_status’) ->addAttributeToSort ( ‘entity_id’, ‘DESC’ ) ->addAttributeToFilter(‘status’,\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED); ->addAttributeToFilter(‘qty’,[‘gt’=>0]) ->load(); […]

Categories
CMS Development Magento

Magento 2 joinField custom $bind?

Summary I joined a field with the joinField function like this: $_productCollection->joinField(‘qty_new’, ‘cataloginventory_stock_item’, ‘qty’, ‘product_id=entity_id’, ‘.stock_id=1’, ‘left’ ); now I have a problem if I want to use the next joinField with a custom $bind like below its gives an error. I know why because the $bind param splits the attributes and checks if they […]

Categories
CMS Development Magento

Magento, invalid model/method definition for start working cron

I want to start work my cron job, but i have error Mage_Core_Exception’ with message ‘Invalid model/method definition, expecting “model/class::method”, got “DaniilKrok_Backorder_Model_Observer::backorderInStockByPriceWhereQteq” my config.xml <?xml version=”1.0″ ?> <config> <modules> <DaniilKrok_Backorder> <version>0.1.0</version> </DaniilKrok_Backorder> </modules> <global> <helpers> <backorder_daniilkrok> <class>DaniilKrok_Backorder_Helper</class> </backorder_daniilkrok> </helpers> <blocks> <backorder> <class>DaniilKrok_Backorder_Block</class> </backorder> </blocks> <resources> <backorder_setup> <setup> <module>DaniilKrok_Backorder</module> </setup> </backorder_setup> </resources> <models> <backorder> <class>DaniilKrok_Backorder_Model</class> <resourceModel>backorder_resource</resourceModel> […]

Categories
CMS Development Magento

magento 1.9, how sort products by stock

i have this code $product_model = Mage::getModel(‘catalog/product’)->getCollection() ->setPageSize(5) ->setOrder(‘entity_id’, ‘DESC’) ->addAttributeToFilter(‘attribute_set_id’, array(‘in’ => array(‘4′, ’12’))) ->addAttributeToFilter(‘price’, array(‘gteq’=>80)) ->joinField( ‘qty’, ‘cataloginventory/stock_item’, ‘qty’, ‘product_id=entity_id’, ‘.stock_id=1’, ‘left’ ); $product_model->getSelect()->joinLeft( array(‘_inventory_table’ => $product_model->getTable(‘cataloginventory/stock_item’)), “_inventory_table.product_id = e.entity_id”, array(‘is_in_stock’, 0) ); I want to get all the products that out_of_stock How can this be done in my request? and how can […]