Skip to main content

Magento 2 Get Product collection using custom attributes of Best Seller

Get Product collection using custom attributes of Best Seller

 <?php  
 use Magento\Framework\App\Action\Action;  
 $_objectManager = \Magento\Framework\App\ObjectManager::getInstance();  
 $_helper = $this->helper('Magento\Catalog\Helper\Output');  
 $productCollection = $_objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');  
 $collection = $productCollection->create()->addAttributeToSelect('*')->addAttributeToFilter('home_best_seller', '1')->setPageSize(10)->setOrder('sort_order', 'DESC')->load();  
 $imagewidth = 400;  
 $imageheight = 400;  
 $imageHelper = $_objectManager->get('\Magento\Catalog\Helper\Image');  
 $i = 0;  
 foreach ($collection as $product) {  
   echo $product->getName();  
 }  
 ?>  

Comments

Popular posts from this blog

Magento 2 get category collection using specific controllers and category level using object manager

Magento 2 get category collection using object manager <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $category = $objectManager->get('Magento\Framework\Registry') ->registry('current_category'); //get current category $requestInterface = $objectManager->get('Magento\Framework\App\RequestInterface'); //echo $routeName = $requestInterface->getRouteName(); //echo $moduleName = $requestInterface->getModuleName(); $controllerName = $requestInterface->getControllerName(); //echo $actionName = $requestInterface->getActionName(); $parcatId = $category->getId(); // current Category ID $parcategory = $objectManager->create('Magento\Catalog\Model\Category') ->load($parcatId); $parent_category = $parcategory->getParentCategory(); $subcatId = $parent_category->getId(); $subcategory = $objectManager->create('Magento\Catalog\Model\Category...

Magento 2: How to use redirect URl in Router.php

Module name - **Aks_CustomUrlRouter** You have to create below listed files 1. Registration.php :: app/code/Aks/CustomUrlRouter/registration.php <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Aks_CustomUrlRouter', __DIR__ ); ?> 2. Module.xml :: app/code/Aks/CustomUrlRouter/etc/module.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd"> <module name="Aks_CustomUrlRouter" setup_version="2.0.0"></module> </config> 3. di.xml :: app/code/Aks/CustomUrlRouter/etc/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> ...

Magento 2 check category attribute values in database using mysql query

Magento 2 check category attribute in database using mysql quer SELECT * FROM `catalog_category_entity_text` where store_id = 1; SELECT * FROM `catalog_category_entity_datetime` where store_id = 1; SELECT * FROM `catalog_category_entity_decimal` where store_id = 1; SELECT * FROM `catalog_category_entity_int` where store_id = 1; SELECT * FROM `catalog_category_entity_varchar` where store_id = 1; Note : In above SQL query store_id 1 is ID of store. kindly you need to check store Id for all store-views in admin and run the above code for each store-views separately.