:::: MENU ::::

Magento 2 Update product attribute value

This article is about Magento 2 – Update product attribute value . Updating product attribute value can be tricky sometimes. In this tutorial i will try to explain it swiftly and in a simple way. There can be various conditions in this matter. Like if someone wants to update the attribute values one by one or as a whole. Here, we are looking t update only one attribute value.

We can set all the values into one object (also we can use set for each attribute) & using set method we can save the product attribute with the help of productRepository or product model.

Furthermore When we use this method, there is a chance to get delays while updating the values like it may take 40 to 50 sec approx for one product . In our case we want to update only one attribute value. To render entire collection & updating the value might will take some ms delay.
So to update only one attribute value, we can do so by using the following code.

Consider the example here.

$item->setWidth(10);

$item->save();

We can use “updateAttributes” method to update Specific Attribute for product instead of updating all the update.

Here we have to pass 3 parameters.

Ex: $productIds , $attrData, $storeId
$objectManager->get(‘Magento\Catalog\Model\Product\Action’)

->updateAttributes( [$item],[‘width’ => 10],  $YourStoreID );

Similarly

$this->action->updateAttributes([$productObj->getId()], [‘Yourattribute_code’ => ‘Yourvalue’], $StoreId);

I am also providing the path for reference, it may vary depending upon your settings.

Magento\Catalog\Model\Product\Action

That’s it from this tutorial. I strongly believe there is always room for improvement.So i am open for any suggestion and feed back. Please feel free to leave hat you are thinking in the comments section below. Cheers.

Author: Qaisar Satti
Category: Magento 2
Last Modified: January 11, 2019


Magento 2 Change theme

This tutorial is about Magento 2 Change theme .i.e how to Change theme and switch your store to default theme in magento 2. I assume your question is,is it possible? the answer is, Yes. It is possible. And in this tutorial i will try to explain it briefly and in a simple way.

So this is quite simple i would say.There is not much of a rocket science in here. Lets see how can we do it. I will try to break it in steps so that it would remain simple and easy to learn.

Above all The default theme in Magento 2 is called Magento Blank. To activate it, follow these steps:

1. Login into your admin panel and navigate to Stores->Settings ->Configuration section .
2. In the General tab press Design.
3. Select Magento Blank among the list of available themes in Design Theme option, press the Save Config button in the top right.
4.Refresh the Magento cache.
5.Check how the new theme appears on the site frontend.

That’s it from this tutorial. I hope it serves the purpose.Since these are learning tutorials,please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Author: Qaisar Satti
Category: Magento
Last Modified: January 11, 2019


Use js mixins magento 2

In this tutorial we will discuss Use js mixins magento 2 .i.e how to use js mixins in magento 2.And in this tutorial i will try to explain it briefly and also make it convenient.

Suppose your code does some task before any js script’s function run or you want to extend a function or to modify some data without overwriting js. And you want to know how to do it.Then this tutorial will help you learn and overcome all these problems easily.

First of all you will need to create requirejs-config.js under app/code/QaisarSatti/HelloWorld/view/frontend, like below:

var config = {
    config: {
        mixins: {
            'Magento_Checkout/js/action/set-shipping-information': {
                'QaisarSatti_HelloWorld/js/action/set-shipping-information-mixin': true
            }
        } // this is how js mixin is defined
    }
};
// Here i am extending "Magento_Checkout/js/action/set-shipping-information" this js with our custom js "QaisarSatti_HelloWorld/js/action/set-shipping-information-mixin".

Furthermore create set-shipping-information-mixin.js file under app/code/QaisarSatti/HelloWorld/view/frontend/web/js/action to extend original function. So here i am just using dummy data to shipping address only , Below is the code:

/*jshint browser:true jquery:true*/
/*global alert*/
define([
    'jquery',
    'mage/utils/wrapper',
    'Magento_Checkout/js/model/quote'
], function ($, wrapper, quote) {
    'use strict';
 
    return function (setShippingInformationAction) {
 
        return wrapper.wrap(setShippingInformationAction, function (originalAction) {
            var shippingAddress = quote.shippingAddress();
 
            if (shippingAddress['extension_attributes'] === undefined) {
                shippingAddress['extension_attributes'] = {'customvar':"value1"};
            }
            // you can write here your code according to your requirement
            return originalAction(); // it is returning the flow to original action
        });
    };
});

Now console thequote.shippingAddress() in js to you should see the result:

That’s it from this tutorial. I hope it serves the purpose.Furthermore please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Author: Qaisar Satti
Category: Magento 2
Last Modified: January 11, 2019


Magento 2 introduction

This tutorial is about magento 2 introduction.This Magento 2 tutorial cover back-end and front-end development, as well as administration guides to help you get up and running with Magento 2. Magento 2 is the technological continuation of the Magento platform. After a several years of development, Magento 2 shows an impressive advancement in the e-commerce field by bringing some key features and making more efficient resource use of the current generation of Servers. We should look at some benefits and improvements that Magento 2 brings. 

Key improvements and features

  • Increased Speed
  • Increased Security
  • Improved Scaling Potential
  • Simpler and Faster Checkout Process

Since magento has the same architecture.That is magento 2 has the same architecture as of magento.Furthermore for you can have a detail view here: Magento tutorial

Furthermore magento makes improvements time to time to improve the functionality and scalability of magento platorm.And in the process it releases different versions over time.Below is the detail of versions and latest version.

Magento 2 versions and latest version

Magento CE 2.0.0
November 18, 2015
Transformation of Magento Platform. Flexible architecture supporting innovation and fast time to market and enterprise-level scalability and performance

Magento CE 2.0.1
January 20, 2016
Several important functional updates, including official support for PHP 7.0.2

Magento CE 2.0.2

January 29, 2016
Resolved issues of upgrading from Magento 2.0.0 to Magento 2.0.1

Magento CE 2.0.3
March 31, 2016
This version was replaced by version 2.0.4, which was released the next day

Magento CE 2.0.4
April 1, 2016
All of the security enhancements and performance improvements of Magento 2.0.3, in improved packaging

Magento CE 2.0.5
April 28, 2016
Miscellaneous functional fixes

Magento CE 2.0.6

May 17, 2016
Security enhancements as well as several functional fixes and enhancements

Magento CE 2.0.7
May 24, 2016
One functional fix in payment gateway

Magento CE 2.0.8
July 19, 2016
Several functional fixes

Magento CE 2.0.9
August 11, 2016
Several functional fixes

Magento CE 2.0.10
October, 2016
Multiple security and functional enhancements as well as enhancements to the Sales API

Magento CE 2.0.11
December, 2016
Over 70 bug fixes and enhancements

Magento CE 2.0.12
February, 2017
Over 20 functional fixes and enhancements, and one security enhancement

Magento CE 2.0.13
April 17, 2017
Several functional fixes

Magento CE 2.0.14
May 31, 2017
Critical enhancements to the security of your Magento software

Magento CE 2.0.15
June 21, 2017
Support for changes in PayPal’s Instant Payment Notification (IPN) service

Magento CE 2.1.0
June 23, 2016
Numerous functional fixes and enhancements

Magento CE 2.1.1
August 30, 2016
Several functional fixes and enhancements to the deployment of static assets

Magento CE 2.1.2
October 12, 2016
Release includes security enhancements and several functional fixes

Magento CE 2.1.3
December 14, 2016
Release includes many functional enhancements and fixes

Magento CE 2.1.4

February 7, 2016
Numerous functional fixes and enhancements

Magento CE 2.1.5
February 21, 2017
Several functional fixes

Magento CE 2.1.6
April 28, 2017
Performance enhancements, especially for operations that involve the category page and image resizing

Magento CE 2.1.7

May 31, 2017
Release includes critical enhancements to the security

Magento CE 2.2.0 – RC
August 4, 2017
Magento Community Edition 2.2.0 Release Candidate includes significant new features as well as many bug fixes

Magento Open Source 2.1.8
August 9, 2017
Magento Open Source (formerly Community Edition). Includes enhancements to Magento software.

Magento has now released magento 2.3 version. Certainly,it does have some improvements and will equip your store with great new features along with the the improvements for developers as well. Furthermore you can read all the details here : Magento 2.3 features

That’s it from this tutorial. I hope it serves the purpose.Furthermore please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Author: Qaisar Satti
Category: Magento 2
Last Modified: January 1, 2019


Magento introduction

Since this blog mainly focuses on Magento. Lets get you familiar with magento introduction in this tutorial. i.e introduction to magento.Lets discuss What is Magento? Magento is the most powerful online e-commerce platform and is changing the face of e-commerce forever. 🙂
Introduction:
Magento is a feature-rich, professional open source e-commerce web application that was launched on March 31, 2008. Magento offers merchants complete flexibility and control over the look, content and functionality of their online store. Magento’s intuitive administration interface contains content management, powerful marketing and merchandising tools to give merchants the ability to create sites that are fully fit their unique business needs, putting no constraints on business processes and flow.
Of course, you already know that. What you may not realize is Magento’s also an object-oriented PHP Framework that can be used to develop modern, dynamic web applications that tap into Magento’s powerful e-commerce features.
This is more of an introductory tutorial however I will try to briefly explain all the important features and aspects of magento.

Why to Use Magento?

  • Magento is an open source E-commerce software.
  • Magento is scalable and offers small organizations to build business.
  • Magento enables searching and sorting of products in several ways.
  • Magento easily integrates with many of the third-party sites which are needed to run effective E-commerce website.

Features

  • Magento provides different payment methods such as credit cards, PayPal, cheques, money order, Google checkouts, etc.
  • Magento enables shipping of products in one order to multiple addresses.
  • Magento helps to manage the orders easily by using the admin panel.
  • Magento provides order of product status and history of product. It also supports e-mail and RSS feeds.
  • Magento supports multiple languages, different currencies and tax rates.
  • Magento filters the products and displays in grid or list format.
  • Magento makes it easy to browse the products. It has features such as image zoom-in and checking of stock availability.
  • Magento has built-in SEO (Search Engine Optimization.

Advantages

  • Magento is user friendly E-commerce software.
  • Magento is compatible with smartphones, tablets and other mobile devices.
  • Magento provides multiple payment options, so every visitor can make payment based on their preferred payment gateway.
  • Magento has many extensions which support the development of an online store.

Disadvantages

  • Magento uses larger disk space and memory.
  • Magento takes longer time to build the customized functionality.
  • Magento is very slow compared to other E-commerce sites.
  • Magento needs proper hosting environment. If the hosting environment is improper, the user can face many problems.

Furthermore lets discuss step-by-step procedure for Magento installation. Before installing Magento, you require the following system requirements.

system requirements

    Database − MySQL 5.1 +
    Web Server −
    Apache 2.x
    Nginx 1.7.x
    Operating System − Cross-platform
    Browser Support − IE (Internet Explorer 7), Firefox, Google chrome
    SSL (Secure Socket Layer) − A valid security certificate is required for HTTPS
    PHP Compatibility − PHP 5.4+

Architecture

Likewise we are going to discuss the architectural style of Magento, for implementing user interfaces.

The Magento architecture comes with Models, Views and Controllers.
User Request − The user sends a request to a server in the form of request message where web browsers, search engines, etc. act like clients.
View − View represents the data in particular format. It is the user interface which is responsible for displaying the response for user request. It specifies an idea behind the presentation of the model’s data to the user. Views are used to reflect “how your data should look like”.
Controller − The controller is responsible for responding to user input and perform interactions on the data model objects. It uses models to process the data and send responses back to the view.
Model − The model is responsible for managing the data of the application. It contains logic of the data and represents basic data object in the framework. It responds to request from the view and to the instructions from the controller to update itself.
Database − Database contains the information which is requested from the user. When the user requests data, view sends requests to the controller, the controller requests from the model and the model fetches the required information from the database and responds to the user.
WSDL − WSDL stands for Web Services Description Language. It is used for describing web services and how to access them.

Now magento 2 is the core e-commercep latofrm for development. So, i am not discussing here the versions of magento(magento 1). Futhermore, in other tutorials i will discuss the latest versions.

That’s it from this tutorial. I hope it serves the purpose.Furthermore please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.

Author: Qaisar Satti
Category: Magento
Last Modified: January 1, 2019


Magento 2 multi-select in system configuration

This article is about Magento 2 multi-select in system configuration . Getting all available categories and display them in a system config multi-select field list can be tricky sometimes. In this tutorial i will try to explain it swiftly and in a simple way that how can you do it in magento 2. There can be various ways of doing it.We will discuss one or two efficient ways of doing so here.

Let’s start our tutorial, here we will discuss different ways of doing it. I hope you are familiar with magento 2 and if yes, you will be able to move along nicely.

First of all modify

QaisarSatti/HelloWorld/etc/adminhtml/system.xml

and paste the following code

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <section id="module_section" translate="label" type="text"
                 sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Module</label>
            <tab>tab_name</tab>
            <resource>QaisarSatti_HelloWorld::config</resource>
            <group id="module_section_page" translate="label" type="text"
                   sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Module page settings</label>
                <field id="latest_category" translate="label" type="multiselect" sortOrder="12" showInDefault="1" showInWebsite="1" showInStore="1">
                    <label>New Product Category</label>
                    <source_model>QaisarSatti\HelloWorld\Model\Config\Source\Categorylist</source_model>
                </field>
            </group>
        </section>
    </system>
</config>

Now

QaisarSatti/HelloWorld/etc/acl.xml

add Acl

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/acl.xsd">
    <acl>
        <resources>
            <resource id="Magento_Backend::admin">
                <resource id="Magento_Backend::stores">
                    <resource id="Magento_Backend::stores_settings">
                        <resource id="Magento_Config::config">
                            <resource id="QaisarSatti_HelloWorld::config" title="Module Section" />
                        </resource>
                    </resource>
                </resource>
            </resource>
        </resources>
    </acl>
</config>

Now add

QaisarSatti/HelloWorld/Model/Config/Source/Categorylist.php

<?php

namespace QaisarSatti\HelloWorld\Model\Config\Source;

use Magento\Framework\Option\ArrayInterface;

class Categorylist implements ArrayInterface
{
    protected $_categoryFactory;
    protected $_categoryCollectionFactory;

    public function __construct(
        \Magento\Catalog\Model\CategoryFactory $categoryFactory,
        \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory
    )
    {
        $this->_categoryFactory = $categoryFactory;
        $this->_categoryCollectionFactory = $categoryCollectionFactory;
    }

    public function getCategoryCollection($isActive = true, $level = false, $sortBy = false, $pageSize = false)
    {
        $collection = $this->_categoryCollectionFactory->create();
        $collection->addAttributeToSelect('*');

        // select only active categories
        if ($isActive) {
            $collection->addIsActiveFilter();
        }

        // select categories of certain level
        if ($level) {
            $collection->addLevelFilter($level);
        }

        // sort categories by some value
        if ($sortBy) {
            $collection->addOrderField($sortBy);
        }

        // select certain number of categories
        if ($pageSize) {
            $collection->setPageSize($pageSize);
        }

        return $collection;
    }

    public function toOptionArray()
    {
        $arr = $this->_toArray();
        $ret = [];

        foreach ($arr as $key => $value)
        {
            $ret[] = [
                'value' => $key,
                'label' => $value
            ];
        }

        return $ret;
    }

    private function _toArray()
    {
        $categories = $this->getCategoryCollection(true, false, false, false);

        $catagoryList = array();
        foreach ($categories as $category)
        {
            $catagoryList[$category->getEntityId()] = __($this->_getParentName($category->getPath()) . $category->getName());
        }

        return $catagoryList;
    }

    private function _getParentName($path = '')
    {
        $parentName = '';
        $rootCats = array(1,2);

        $catTree = explode("/", $path);
        // Deleting category itself
        array_pop($catTree);

        if($catTree && (count($catTree) > count($rootCats)))
        {
            foreach ($catTree as $catId)
            {
                if(!in_array($catId, $rootCats))
                {
                    $category = $this->_categoryFactory->create()->load($catId);
                    $categoryName = $category->getName();
                    $parentName .= $categoryName . ' -> ';
                }
            }
        }

        return $parentName;
    }
}

Furthermore, let’s discuss another way of doing so. Here In system.xml file field for multi select of category is like:

<group id="helloworld_setting" translate="label" type="text" delault="1" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">
    <label>Setting</label>
    <field id="cateogry" translate="label" type="multiselect" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
        <label>Select Category</label>
        <source_model>QaisarSatti\HelloWorld\Model\Config\Source\Categorylist</source_model>
    </field>
</group>

Now create a file Categorylist.php in QaisarSatti\HelloWorld\Model\Config\Source

namespace QaisarSatti\HelloWorld\Model\Config\Source;

use Magento\Framework\Option\ArrayInterface;

class Categorylist implements ArrayInterface
{
    protected $_categoryHelper;

    public function __construct(\Magento\Catalog\Helper\Category $catalogCategory)
    {
        $this->_categoryHelper = $catalogCategory;
    }

    /*
     * Return categories helper
     */


    public function getStoreCategories($sorted = false, $asCollection = false, $toLoad = true)
    {
        return $this->_categoryHelper->getStoreCategories($sorted , $asCollection, $toLoad);
    }

    /*  
     * Option getter
     * @return array
     */

    public function toOptionArray()
    {


        $arr = $this->toArray();
        $ret = [];

        foreach ($arr as $key => $value)
        {

            $ret[] = [
                'value' => $key,
                'label' => $value
            ];
        }

        return $ret;
    }

    /*
     * Get options in "key-value" format
     * @return array
     */

    public function toArray()
    {

        $categories = $this->getStoreCategories(true,false,true);

        $catagoryList = array();
        foreach ($categories as $category){

            $catagoryList[$category->getEntityId()] = '__'.($category->getName());
        }

        return $catagoryList;
    }

}

But in this case you’ll get first level only and categories included in menu.

That’s it from this tutorial. I strongly believe there is always room for improvement.So i am open for any suggestion and feed back. Please feel free to leave hat you are thinking in the comments section below. Cheers.

Author: Qaisar Satti
Category: Magento 2
Last Modified: January 1, 2019


Pages:1234567...20