:::: MENU ::::
Browsing posts in: Magento 2

Magento 2 Get Store Specific Product Name and Description

Today we’ll talk about how we can get store specific products name and descriptions. Like for example, my shop has six store views: DE, AT, IT, ES, FR, and GB. And each store view uses the same set of the product with appropriately translated but I would for example want to view a product in a specific view like DE.

We can do that just by following the instructions below:

protected $productFactory;  
public function __construct(\Magento\Catalog\Model\ProductFactory $productFactory) {      
 $this->productFactory = $productFactory;            
}

now you can use this like,

$product= $this->_productFactory->create()->setStoreId($storeId)->load($pid);

Where $storeIdis your store Id and
$pidis your product Id.

$productName=$product->getName();

Don’t forget to do

di:compile

by

php bin/magento setup:di:compile

and clearcache

php bin/magento c:f

Product Repository

protected $productRepository;
public function __construct(             \Magento\Catalog\Api\ProductRepositoryInterface $productRepository    )
{        
$this->productRepository = $productRepository;    
}

Now, you can use below

$product = $this->productRepository->getById($pid,false,$storeId);

$productName=$product->getName();

You can see It’s arguments invendor\magento\module-catalog\Api\ProductRepositoryInterface.phppublic function getById($productId, $editMode = false, $storeId = null, $forceReload =

Author: Qaisar Satti
Category: Magento 2
Last Modified: September 29, 2020


Codelobster IDE – a powerful multi-platform Magento IDE

Codelobster IDE – a powerful multi-platform Magento IDE

Magento is the World’s most flexible eCommerce platform.
It empowers thousands of retailers and brands with the framework to rapidly innovate and grow.
For each web developers is important the choice of tools to quickly and efficiently edit code on your site.

Specifically, in order to deal with Magento platform, We have choosen a very convenient development environment – Codelobster IDE .

    Let us consider some important possibilities and advantages of this program:

  • All code highlights depending on a type, the also mixed code is thus supported,
    so the area of HTML will be highlighted as HTML, PHP as PHP, and Javascript as Javascript in a the same file.
    Thre is possibility of choice from color schemes, including popular IDEs.
  • Powerful autocompletion for HTML, PHP, CSS and Javascript, including HTML5 and CSS3.
    For PHP the structure of project is fully recognized, and the complete list of methods falls out in the proper places.
  • HTML/CSS inspector on the type of Firebug, which allows easily to correlate the selected elements of
    page with a code and proper style.
  • Context help on all supported languages. By pressing F1 key the page with detailed description for current tag, attribute or function will be opened.
  • PHP debugger. PHP debugger allows to execute PHP scripts incrementally, watching the values of all
    variables in every line.
  • Support of FTP allows to work straight with a remote server and to do all necessary changes with files;
  • Support for Version Control Systems: SVN, Git etc.
  • The portable option allows to use editor without the preliminary installation.
  • Other useful utilities: collapsing, tooltips, pair highlighting, possibility of blocks selection, navigation on descriptions of functions and included files at withholding of the key of CTRL,
    viewing of structure of files and project, preview in a browser, book-marks, and all other standard possibilities for work with a code.

Codelobster IDE has the following abilities to work with Magento :

  • Ability to create projects automatically installing Magento platform
  • Autocomplete for Magento methods
  • Tooltips for Magento methods
  • Context and Dynamic help

Also Codelobster IDE supports Windows, Mac OS, Linux, Ubuntu, Mint, Fedora etc.
and has special plug-ins for working with: Drupal, Joomla, Twig, JQuery, CodeIgniter, CakePHP, Laravel, Node.js, AngularJS, BackoneJS, EmberJS, Phalcon, VueJS, Symfony, Magento, Yii and WordPress.

Developer Codelobster Software
Web Site http://www.codelobster.com/
Language English, , German, French, Italian, Spanish, Russian, Chinese,
Japanese, Portuguese, Hungarian, Czech, Slovak, Turkish,
Persian
Author: Qaisar Satti
Last Modified: September 17, 2020


magento 2 get current quote

Today we talk about how Magento 2 get current quote. You can get quote data from the checkout session. You can get data to manipulate the data in the cart. So let start with our example.

<div>::CODECOLORER_BLOCK_9::</div>

Now we call our function and get a quote data.

$allItems = $this->getQuotes()->getAllVisibleItems();
foreach ($allItems as $item) {
    echo $item->getProductId();
}
Author: Qaisar Satti
Category: Magento 2
Last Modified: September 29, 2020


magento 2 get all customers

Today we talk about how Magento 2 get all customers. Sometimes you need to list down all the customers for many reasons. For exporting the customer the data or show all customer listing. So let start with our example to list down all the customer.

namespace QaisarSatti/HelloWorld/Block;

use Magento\Backend\App\Action;


class Delete extends Action
{

    protected $customerCollection;

    public function __construct(
        \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollection
    )
    {
        $this->customerCollection = $customerCollection;
    }

    public function getAllCustomers()
    {
            return $this->customerCollection->create();

       
    }
}

Now we call the function and list down all the customer data.

$allCustomers = $this->getAllCustomers();
foreach ($allCustomers as $customer) {
    echo $customer->getEmail();
    echo $customer->getFirstname();
    echo $customer->getLastname();
}
Author: Qaisar Satti
Category: Magento 2
Last Modified: February 17, 2020


Magento 2 get customer address

Today we discuss how in Magento 2 get customer address. Which include the default shipping address and default billing address also the all customer address list too. There are two types of addresses related to customer shipping and billing. you can add the unlimited address as a customer. let start with our example.

Customer Default Billing Address

Get the customer defaut billing address.

namespace QaisarSatti/HelloWorld/Block;

use Magento\Backend\App\Action;

class Delete extends Action
{

    protected $customerFactory;
    protected $addressFactory;

    public function __construct(
        \Magento\Customer\Model\CustomerFactory $customerFactory,
        \Magento\Customer\Model\AddressFactory $addressFactory
    )
    {
        $this->customerFactory = $customerFactory;
        $this->addressFactory = $addressFactory;
    }

    public function getCustomerDefaultBillingAddress()
    {
        $customerObject = $this->customerFactory->create()->load(10);  
        $billingAddressId = $customerObject->getDefaultBilling();
        return $billingAddress = $this->addressFactory->create()->load($billingAddressId);
       
    }
}

Customer Default Shipping Address

Get the customer defaut billing address.

namespace QaisarSatti/HelloWorld/Block;

use Magento\Backend\App\Action;

class Delete extends Action
{

    protected $customerFactory;
    protected $addressFactory;

    public function __construct(
        \Magento\Customer\Model\CustomerFactory $customerFactory,
        \Magento\Customer\Model\AddressFactory $addressFactory
    )
    {
        $this->customerFactory = $customerFactory;
        $this->addressFactory = $addressFactory;
    }

    public function getCustomerDefaultBillingAddress()
    {
        $customerObject = $this->customerFactory->create()->load(10);  
        $shippingAddressId = $customerObject->getDefaultShipping();
        return $shippingAddress = $this->addressFactory->create()->load($shippingAddressId);
       
    }
}

Customer All Address

Get the customer all address.

namespace QaisarSatti/HelloWorld/Block;

use Magento\Backend\App\Action;

class Delete extends Action
{

    protected $customerFactory;
    protected $addressFactory;

    public function __construct(
        \Magento\Customer\Model\CustomerFactory $customerFactory,
        \Magento\Customer\Model\AddressFactory $addressFactory
    )
    {
        $this->customerFactory = $customerFactory;
        $this->addressFactory = $addressFactory;
    }

    public function getCustomerDefaultBillingAddress()
    {
        $customerObject = $this->customerFactory->create()->load(10);  
        return $customerObject->getAddresses();
       
    }
}
Author: Qaisar Satti
Category: Magento 2
Last Modified: February 17, 2020


Magento 2 current order

In this tutorial, we talk about how to get Magento 2 current order. Which includes order information current order id, Increment Id and other order-related data too like shipping information, billing information, and customer information. Now we start with our example.

You have to inject the checkout model session to get the latest order information.

protected $_checkoutSession;


public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,

) {

        $this->_checkoutSession = $checkoutSession;


    }

Now with $_checkoutSession obejct you can get order following information.

 $order = $this->_checkoutSession->getLastRealOrder();
 $orderId=$order->getEntityId();  // order id
 $order->getIncrementId();  // order increment id
 $order->getShippingMethod(); // shippingm ehtod
 $order->getPayment();   // payment method
 $order->getCustomerEmail(); // customer email
Author: Qaisar Satti
Category: Magento 2
Last Modified: February 4, 2020


Magento 2 order PayPal information

Today we talk about how in Magento 2 order PayPal information. In this tutorial, we focus on how to get order PayPal information which includes the PayPal express token and PayPal correlation id. So let start with our example.

First, we get payment additional information.

[cc lang="php" tab_size="2" lines="40"]
$paymentAdditionalInfo = $order->getPayment()->getAdditionalInformation();

With the heplp of addiotnal information obejct we get paypal expreess token.

// get PayPal express checkout token
$token = $paymentAdditionalInfo['paypal_express_checkout_token'];

With the heplp of addiotnal information obejct we get paypal correlation id.

// get PayPal correlation ID
$correlationId = $paymentAdditionalInfo['paypal_correlation_id'];
Author: Qaisar Satti
Category: Magento 2
Last Modified: February 4, 2020


Pages:1234567...21