Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn Happy_Programming

Snippets for Magento 2 Developers

1 - Get ObjectManager Instance $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $customerCollection = $objectManager->create('Magento\Customer\Model\CollectionFactory')->getCollection(); 2 - Get BaseUrl //inject \Magento\Store\Model\StoreManagerInterface $storeManager in constructor $this->_storeManager = $storeManager; $url = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); //url in media directory 3 - Get Session Customer //inject \Magento\Customer\Model\Session $customerSession in constructor $this->_session = $customerSession; 4 - Get Featured Products Collection $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); //dirty way $productCollection = $objectManager->create('Magento\Catalog\Model\ProductFactory')->getCollection(); //filters $featuredProducts = $productCollection ->addAttributeToSelect('name') ...