Thursday 3 November 2016

Magento2 Skin url replaced in magento2


 Template files
in magento 1
$this->getSkinUrl()
 
Replace with in magento2
$this->getViewFileUrl()
 
CMS page or blocks

in magento 1
{{skin url=''}}
 
Replace with in magento2
{{view url=''}}

Magento2: getting Fatal error: Allowed memory size of error when tried to do mass status change action in magento from admin catalog grid


I was surprised to see core magento error in admin when i tried to attempt to change 100 products of the current status to other
ofcourse my catalog was aroung 7lakh items.
I and My team mate got the fix for this
Error is:
Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 24 bytes) in G:\xampp\htdocs\mage-ee206\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php on line 291


Fix we found here is 
vendor/magento/module-catalog/Controller/Adminhtml/Product/MassStatus.php

====
/**
     * Update product(s) status action
     *
     * @return \Magento\Backend\Model\View\Result\Redirect
     */
    public function execute()
    {
        $collection = $this->filter->getCollection($this->collectionFactory->create());
        $productIds = $collection->getAllIds();
        $storeId = (int) $this->getRequest()->getParam('store', 0);

        $status = (int) $this->getRequest()->getParam('status');

---------------
We changed to 
We extended the code module to our name space to extend core controller

/**
     * Update product(s) status action
     *
     * @return \Magento\Backend\Model\View\Result\Redirect
     */
    public function execute()
    {
    $productIds = $this->getRequest()->getPostValue("selected");
        $storeId = (int) $this->getRequest()->getParam('store', 0);
        $status = (int) $this->getRequest()->getParam('status');

==============
Now we could able to do Mass status change action without fail.

I hope it may help you.

Note: if you face the same error for Mass delete action also, you can try this. i have not tested that.
i will post once i tested it.

Cheers:)

Best way to loop/iterate the catalog collection in Magento2

When i was doing mass status change in magento
I was facing with memory allocation in my localshot xammp
Total products i have around 7lakh in the admin grid. i tried to change the status about to 100 products,

i got this error

Fatal error: Allowed memory size of 805306368 bytes exhausted (tried to allocate 24 bytes) in C:\xampp\htdocs\mage-ee206\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php on line 291

==============
After spending one day time i got the solution

In one of my third party i found a iteration of products using foreach.. when i changed foreach to while it worked fine for me
i have tested for 30,50,100,500,700 products to changes the status and it was fine for me

I hope this may help you
original code
  $Prods = $this->_productFactory->create()->getCollection()->addIdFilter(<prodids>);
            $Prods->addAttributeToSelect(['status','<status>']);          
         
            foreach ($Prods as $prod) {
           
            $prodid = $prod->getId();
            $prod_status = $prod->getData('status');
=======================
Changed to 

$Prods = $this->_productFactory->create()->getCollection()->addIdFilter(<prodids>);
            $Prods->addAttributeToSelect(['status','<status>']);
            
            while ($prod = $Prods->fetchItem()) {            
            $prodid = $prod->getId();
            $prod_status = $prod->getStatus();
============

Tuesday 1 November 2016

Magento2: after installation logo is not loading and admin is not loading in windows + xamppp

Lot of time i faced this issue
when tried load home page after installation magento2 i cant see the magento2 logo and admin is not loading properly
the quick fix is
find this
<item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Symlink</item>

replace with below and refresh the page, it should work now.

<item name="view_preprocessed" xsi:type="object">Magento\Framework\App\View\Asset\MaterializationStrategy\Copy</item>

Magento2 : getting store configured timezone date time

Hello Everyone here is the code to get store configured date time

$timezone = $this->_objectManager->create(
            '\Magento\Framework\Stdlib\DateTime\TimezoneInterface'
            );

strftime('%Y-%m-%d %H:%M:%S', $timezone->scopeTimeStamp())

Monday 31 October 2016

Magento2: how to remove the mini cart icon from the menu

using layout xml file we can remove the mini cart icon from the menu in magento2

here is code
<referenceBlock name="minicart" remove="true" />
use this is any default.xml file to remove in all pages.

Thursday 27 October 2016

Magento2: How remove a element from the template?

Hello Guys
Welcome to Magento2.. keep learning magento2

Today i found one thing
We can easily remove the element from the frontend templates with out touching phml files

go to layout file of page(module) then add this tag
<referenceBlock name="blockname" remove="true"/>

Example:
i would like remove sku, price from the product details page
I have done this
go to app\design\frontend\yournamespace\yourtheme\Magento_Catalog\layout\catalog_product_view.xml

i have added
<referenceBlock name="product.info.stock.sku" remove="true"/>
<referenceBlock name="product.info.price" remove="true"/>
under body tag.
sku and price are removed from the page.

if you dont have xml file in ur theme just copy from the base, place it in your theme.
you can get base file from vendor\magento\module-catalog\view\frontend\layout\catalog_product_view.xml

Please let me know if you need any help.

Thanks