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

How to get filterable attributes in search result collection REST API magento 2

How do I get filterable attributes from the following collection??? $productcollection = $objectManager->create(‘Magento\Catalog\Model\ResourceModel\Product\Collection’) ->addStoreFilter($lang) ->addAttributeToSelect(‘*’) ->joinField(‘stock_item’, ‘cataloginventory_stock_item’, ‘is_in_stock’, ‘product_id=entity_id’, ‘is_in_stock=1’) ->addAttributeToFilter(array( array(‘attribute’ => ‘name’, ‘like’ => ‘%’ . $value . ‘%’), array(‘attribute’ => ‘sku’, ‘eq’ => $value), ),”,’left’ ) ->addAttributeToFilter(array( array(‘attribute’ => ‘status’, ‘eq’ => 1), ) )->setVisibility([3,4]);