Magento 2 Object Manager

Magento 2 Object Manager is a PHP class responsible for creating and retrieving objects in Magento 2. It also manages to create factories and proxies. To get the object manager instance use the code: <?php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); Using the ObjectManager you can get a singleton object (method “get”) of PHP class or create a new…
Read More

How to use curl in Magento 2

We will be learning here, how one can use curl in Magento 2. At first, you need to create an instance of “\Magento\Framework\HTTP\Client\Curl” in the Constructor as shown below: /** * @var \Magento\Framework\HTTP\Client\Curl */ protected $_curl; /** * Data constructor. * * @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\HTTP\Client\Curl $curl */ public function…
Read More

How to get category by url key in Magento 2

  Here is the sample code to get category by category url key. <?php namespace Mageprince\Test\Model; class SampleClass { protected $filter; public function __construct( … \Magento\Catalog\Model\CategoryFactory $categoryFactory, … ) { $this–>categoryFactory = $categoryFactory; } public function getCategory($urlKey, $parentCatId) { $categories = $this–>categoryFactory->create()–>getCollection() –>addAttributeToFilter(‘url_key’, $urlKey) –>addAttributeToSelect([‘entity_id’]); return $categories; } } Now…
Read More