Pratik
  • Member for 6 years, 9 months
  • Last seen this week
Magento 2: Replacement for Mage::log method?
Accepted answer
158 votes

protected $logger; public function __construct(\Psr\Log\LoggerInterface $logger) { $this->logger = $logger; } You use debug, exception, system for PSR Logger for example: $this->logger->...

View answer
Adding a jQuery Library to Magento 2
Accepted answer
20 votes

Create requirejs-config.js Companyname\Modulename\view\frontend\requirejs-config.js add var config = { map: { '*': { bannerslider: 'Companyname_Modulename/js/flexslider', ...

View answer
Magento 2: move the javascript to the end of the body
15 votes

First create new module: Create Module Company/DeferJS registration.php <?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE,...

View answer
Retrieve items on Order Magento 2
Accepted answer
15 votes

$order = $this->_objectManager->create('Magento\Sales\Model\Order')->load($orderId); $orderItems = $order->getAllItems(); You done it using objectManager

View answer
Magento 2 Display Sub Category of parent?
Accepted answer
7 votes

My code to get the category list for the main category is: public function __construct( Template\Context $context, \Magento\Catalog\Model\Layer\Resolver $layerResolver, \...

View answer
Magento 2 - setup primary key field without auto increment
6 votes

You need to write this code in your Resource model class $this->_isPkAutoIncrement = false; for example namespace Company\Module\Model\ResourceModel; class Module extends \Magento\Framework\...

View answer
Magento 2: How to Solve Defer parsing of JavaScript on CDN?
5 votes

In Observer method $response = $observer->getEvent()->getData('response'); if (!$response) return; $html = $response->getBody(); if ($html == '') ...

View answer
Magento 2 "toOptionArray()" function
4 votes

You create source model class RedPage implements \Magento\Framework\Option\ArrayInterface public function toOptionArray() { return [ [ 'value' => 0, ...

View answer
I am not able to use product name like 5" ABCD in Magento2
Accepted answer
3 votes

Please Read Following link for your solution. issues-14977 changes file 16594 changes file 15521

View answer
How to add Dynamic Rows Component to my custom module?
3 votes

I give you idea how you can do it not whole answer. You create DataProvider in your module this is sample code protected function getSelectTypeGridConfig($sortOrder) { return [ '...

View answer
This page isn’t working hotandbold.com redirected you too many times
2 votes

Here is solution Go to database find table core_config_data and search Path value "web/cookie/cookie_domain" remove this row and try.

View answer
Magento 2 - How to add a new sort options in category page
Accepted answer
2 votes

@Robert You need to create another plugin for this method afterGetAttributeUsedForSortByArray for Magento\Catalog\Model\Config example code is <type name="Magento\Catalog\Model\Config"> &...

View answer
Magento2: what is the best way to detect mobile device?
2 votes

You use this Library for Mobile Detect Link create custom module add library in module and create helper and put this function to global use. public function isMobile() { return $this->...

View answer
Magento 2 header custom block not cacheable for customer session
2 votes

In Your Helper protected $isCustomerLoggedIn; public function __construct( \Magento\Framework\App\Helper\Context $context, \Magento\Framework\App\Http\Context $httpContext ...

View answer
How to show image in custom grid in magento 2 backend?
2 votes

Check render function it't look like public function __construct( \Magento\Framework\UrlInterface $urlBuilder, \Magento\Store\Model\StoreManagerInterface $storeManager, $...

View answer
Reindexing option not available in magento 2.0
2 votes

Hello You use following command in cmd if you using windows php -f bin/magento indexer:reindex

View answer
How can i rewrite TierPrice Block in Magento2
2 votes

You can do like this <referenceBlock name='contactForm'> <action method='setTemplate'> <argument name='template' xsi:type='string'>Vendorname_Modulename::form_new.phtml&...

View answer
Magento 2.2.6 issue: php bin/magento catalog:image:resize
1 votes

Please Read https://devdocs.magento.com/guides/v2.2/release-notes/ReleaseNotes2.2.6CE.html The catalog:image:resize command execution time has been reduced by up to 90% in the release. However, this ...

View answer
How to get all visible out of stock products in magento 2
1 votes

Try this code In your collection $select = $collection->getSelect(); if (false === strpos($select->__toString(), 'cataloginventory_stock_status')) { $website = $this->...

View answer
Replacing the core module search using javascript in magento-2
Accepted answer
1 votes

I have develop module to replacing the core module search functionality. please check below link for more information. magento2-catalog-search-autocomplete

View answer
Magento 2 - How to add a new sort options in category page
1 votes

@Robert Yes it's working as per your query about Ascending/Descending arrow you manage using this plugin here is i write sample code for plugin you adjust logic as per your requirement /** * @param ...

View answer
magento2 decrypt problem not getting real value
1 votes

please try this code and check it's working or not $this->_encryptor->encrypt((int)$quote->getId()) also try this code $this->_dataSaveAllowed = false; $value = (int)$...

View answer
About Admin Side I have a template file in which I have a form submission
1 votes

write code in your block public function __construct( \Magento\Backend\Block\Template\Context $context array $data = array() ) { $this->formKey = $context->getFormKey(); ...

View answer
Magento 2 Programatically add product to cart with additional options
1 votes

You need to use Observer checkout_cart_product_add_after to add custom data in additional_options Here is full Example

View answer
Get to work reindexing in external code
1 votes

$indexer = $this->_objectManager->get('Magento\Framework\Indexer\IndexerRegistry')->get($indexerId); $indexer->reindexAll(); try this code and make sure $indexerId is your selected index ...

View answer
Displaying subcategories instead of products 2.1
1 votes

I have create small module for display sub category please check this link. https://github.com/pratikmage/magento2-subcategory

View answer
Magento ver. 2.1.0 - Index Management without SSH/Shell Access?
1 votes

Create deploy.sh file in your project root directory and past following content #!/bin/bash rm -rf /var/www/project/public_html/var/cache/ /var/www/project/public_html/var/page_cache/ /var/www/...

View answer
Magento 2 Simple Model Observer not working
1 votes

An example of how to get magento2 Observer working can be found in the following files inside the vendor folder magentofolder\vendor\magento\module-catalog\etc\frontend\events.xml magentofolder\...

View answer
Magento 2 - Get category id of products in shopping cart
Accepted answer
1 votes

/* $this->_productRepository = \Magento\Catalog\Api\ProductRepositoryInterface */ $product = $this->_productRepository->getById($pid); $cats = $product->getCategoryIds(); var_dump($cats); ...

View answer
Magento 2 create category attribute thumbnail and upload image using File Uploader Component
1 votes

Please check this issue on github category image attribute issue

View answer