Monday, 5 August 2019

Sunday, 7 July 2019

Display product image in custom phtml file Magento2.

Use below code for display product image in custom template file.

$_imagehelper = $this->helper('\Magento\Catalog\Helper\Image');

 <img src=" <?= $_imagehelper->init($_product, 'product_page_image_small')->getUrl(); ?>" width="100" height="100" alt="product-image"/>

Tuesday, 2 July 2019

Update Category Attribute Programatically in Magento2 using csv

<?php
ini_set('display_errors', 1);
ini_set('memory_limit', '5G');
error_reporting(E_ALL);

use Magento\Framework\App\Bootstrap;

require 'app/bootstrap.php';

Monday, 1 July 2019

Category Name instead of category ids in category path magento2.

protected $_categoryFactory;

public function __construct(
        \Magento\Catalog\Model\CategoryFactory $categoryFactory
    ) {
        $this->_categoryFactory = $categoryFactory;
        parent::__construct($context);
    }

Thursday, 27 June 2019

Category Custom Attribute Value in magento2

1. Create Block file Attribute.php app/code/Category/CustomAttribute/Block/Attribute.php

<?php
/**
 * Ansar Husain
 * Category_CustomAttribute
 */

namespace Category\CustomAttribute\Block;

use Magento\Catalog\Api\CategoryRepositoryInterface;

/**
 * Class Attribute
 * @package  Category\CustomAttribute\Block
 */
class Attribute extends Template
{

Monday, 29 April 2019

Reorder of magento2 checkout fields like as postcode and company

Create file checkout_index_index.xml in Vendor\Module\view\frontend\layout


<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.root">
            <arguments>

Monday, 8 April 2019

Display admin user name who made order comment Magento2

1.Create file registration.php in app/code/Order/CommentsUser/registration.php

<?php
/**
 * Ansar Husain
 * Order_CommentsUser
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Order_CommentsUser',
    __DIR__
);

Monday, 4 March 2019

Create and install magento2 patch files

1. Go to magento2 vendor directory

2.run command inside vendor directory

   git init


3. run following commands now

   git add -A

   git commit -m " temp added "

Magento2 Google Translation

1.Create file registration.php in app/code/Google/Translator/registration.php

<?php
/**
 * Ansar Husain
 * Google_Translator
 */
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'Google_Translator',
    __DIR__
);