Get Company Collection programmatically in Magento 2 B2B.

Magento Commerce has a native B2B feature. If you are using B2B feature for your store from Magento Commerce, You can get a list of the company for your store from Backend by Navigating to Customer -> Companies

When you store runs on B2B mechanism, You have many companies assigned to a store for your Business. Continue reading “Get Company Collection programmatically in Magento 2 B2B.”

How to change CrossSell product limit in Magento 2?

Magento 2, Cross-sell product will be display in Shopping Cart page. By Native Magento, Only four Cross-sell product will be display in cart page. If you want to increase or decrease the Cross-sell Product display limit in cart page you need to modify Core Crosssell.php file.

Native file location for CrossSell Product, Magento\Checkout\Block\Cart\Crosssell

You can check the hardcoded product limit by protected $_maxItemCount = 4; Continue reading “How to change CrossSell product limit in Magento 2?”

Get wishlist collection of a customer by customer id Magento 2.

You can get wishlist collection of a customer by customer id. You can show detail of Customer Wishlist item in a store. Get Wishlist collection by calling Magento\Wishlist\Model\Wishlist Model file.

I have created a Block file for define Wishlist collection and load collection in template file by iterating over a collection loop.

<?php
namespace Rbj\Wishlist\Block;

class Demo extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Wishlist\Model\Wishlist $wishlist,
        array $data = []
    ) {
        $this->wishlist = $wishlist;
        parent::__construct($context,$data);
    }
    /**
    * @param int $customerId
    */
    public function getWishlistByCustomerId($customerId)
    {
        $wishlist = $this->wishlist->loadByCustomerId($customerId)->getItemCollection();

        return $wishlist;
    }
}

Call function in a template file, If Customer has wishlist item available, display item info otherwise no item found message will be displayed.

<?php
$customerId = 2; //CUSTOMER_ID
$wishlistCollection = $block->getWishlistByCustomerId($customerId);
if(count($wishlistCollection)) {
    foreach ($wishlistCollection as $_item) {
        echo $_item->getProduct()->getName();echo "<br>";
        echo $_item->getProduct()->getId();echo "<br>";
    }
} else {
    echo __("No Item found in your wishlist");
}

The result will be your Item list from a Wishlist.