New answers tagged

0

You can load product by sku use below code: ... private $productRepository; ... public function __construct( ... \Magento\Catalog\Api\ProductRepositoryInterface $productRepository ... ) { ... $this->productRepository = $productRepository; ... } public function loadProductBySku($sku) { return $this->productRepository->...


0

You can do it using the interface below. Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface ... private $getProductTypeBySku; ... public function __construct( ... \Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface $getProductTypeBySku ... ) { ... $this->getProductTypeBySku = $getProductTypeBySku; .....


0

You can use below code so that it will give all details in array: $categories = $objectManager->create('Magento\Catalog\Model\ResourceModel\Category\Collection'); $categories->addAttributeToSelect('*'); echo "<pre>"; print_r($categories->toArray());


2

you can Following this way.. public function __construct( \Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory, ) { $this->orderCollectionFactory = $orderCollectionFactory; } public function getOrderCollection() { $orderCollecion = $this->orderCollectionFactory ->create() -...


0

You can try Like This $collection->addAttributeToSelect('*'); $collection->addFieldToFilter('group', ['finset'=> 5]); $collection->load(); Hope it Helps.Happy Coding!


3

$collection->getSelect()->where('e.entity_id NOT IN(?)', new \Zend_Db_Expr('(SELECT b.parent_id FROM cataloginventory_stock_item AS a JOIN catalog_product_relation AS b ON a.product_id = b.child_id WHERE a.qty <= 0)') );


3

Add this into your listing xml file Vendor/Module/view/adminhtml/ui_component vendor_manage_listing.xml <container name="listing_top"> ......................................................................... ......................................................................... .......................................................................


2

Add the below code in Vendor/Module/view/adminhtml/ui_component/seoreport_category_listing.xml file in the filters tab. <filterSelect name="value"> <argument name="optionsProvider" xsi:type="configurableObject"> <argument name="class" xsi:type="string">X247commerce\Seoreports\Model\Config\Source\Status</argument> </...


0

public function __construct( \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\Framework\Event\ManagerInterface $eventManager, \Vendor\Module\Helper\YourHelperClass $helper, \Magento\...


0

Inject your helper before below line \Magento\Framework\DB\Adapter\AdapterInterface $connection = null as below public function __construct( \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory, \Psr\Log\LoggerInterface $logger, \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, \Magento\...


3

Add this below code in your file : protected $_storeManager; protected $catCollFactory; public function __construct( ... \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $catCollFactory, ... ) { $this->_storeManager = $storeManager; $this->catCollFactory = ...


0

You can try below to resolved this issue: lib/internal/Magento/Framework/Data/Collection/AbstractDb.php public function getSize() { if ($this->_totalRecords === null) { $itemCount = count($this->_items); if ($this->_totalRecords === null || ($itemCount > 0 && $itemCount !== $this->_totalRecords)) { $sql = $this-...


0

You can add below line to end to sort by qty desc: $product_model->getSelect()->order('qty DESC');


1

var_dump($collection->getSelect()->__toString());


1

i hope you want to print query to identify the issue of getsize count wrong. whenever you use group by query then call getSize function means it will give first record data so it will give wrong count. for this before embed group by query. you should call getSize function. so it will set before execute group by query.


1

For (Q2), option (3) is correct, as even with multi shipping, once you place the order, magento creates separate order records, each having one single address.


2

Try below code. In my case attribute was - is_feature, change $attribute if needed. Featured attribute must be of Catalog Input Type Yes/No including few other below options. Use in Layered Navigation = Filter with Results Use in Search = Yes Use in Search Results Layered Navigation = Yes File - Custom/SortBy/etc/frontend/di.xml <type ...


1

First, you need to create di.xml file in Company\Module\etc\frontend folder. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <preference for="Magento\Catalog\Block\Product\ProductList\Toolbar" type=""Company\Module\Block\...


1

You can manipulate sorting by creating plugins for functions getAttributeUsedForSortByArray(\Magento\Catalog\Model\Config) and setCollection(\Magento\Catalog\Block\Product\ProductList\Toolbar).


0

I don't know if this help or not , but i used this way to show recently added 5 products $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product'); $productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\...


3

@Purushotam Sharma, If you want to setOrder to collection with two attributes or more then that then you can use the below code in your custom collection: $collection->getSelect()->order(new Zend_Db_Expr('featured DESC')); $collection->getSelect()->order(new Zend_Db_Expr('e.created_at DESC')); $collection->getSelect()->order(new ...


0

Update the code of /Block/Reviews.php with below and give a try. <?php namespace Training\Reviews\Block; use Training\Reviews\Model\ResourceModel\Reviews\Collection; use Magento\Framework\View\Element\Template; class Reviews extends \Magento\Framework\View\Element\Template { public function _prepareLayout() { $this->pageConfig-&...


0

The best solution would be as follows according to me Create attribute (which you have already done) Set Used for Sorting in Product Listing to Yes for this attribute Assign to attribute set Flush cache now Reindex Product Flat Go to Store -> config -> catalog -> catalog -> storefront -> Product Listing Sort by set your attribute as default sorting option. ...


-1

Update To display specific products by an attribute, you could create a static block. In that static block, you could create a widget of type catalog product list, give it a title, then go to conditions.There click on the plus icon and first choose the category that you want to display the featured products. Then choose the featured product attribute and ...


2

You have to do below 2 things in your system. keep that attribute properties "display on PLP => yes" in attribute management section. Create observe to change the original toolbar.php file to add custom sort order based on your featured_product attribute. Original File : Magento\Catalog\Block\Product\ProductList\Toolbar.php as MagentoToolbar Extend File ...


0

All products have a created_at attribute containing the date the product was added. You can enable this as a frontend sort option in two ways. If you have access to your database: Find the created_at product attribute in DB table eav_attribute set its column frontend_label to Created At(default is null). Find the created_at product attribute in DB table ...


0

Found the solution :) print_r helped a lot main.DEBUG: Magento\Framework\Api\SearchCriteria Object ( [_data:protected] => Array ( [filter_groups] => Array ( [0] => Magento\Framework\Api\Search\FilterGroup Object ( [_data:protected] => Array ( [filters] => Array ( ...


0

Just adding this here for others, also refer to Magento 2 : Custom grid keeps spinning and grid doesn't load if it's still not working.


Top 50 recent answers are included