0

I want to get product collection as per store vise.

Currently, I created 2 store

1) IN , 2) US.

In IN set INR and in US set USD. By default store is US.

When I change store and set IN then product price I get in USD in product collection.

How can i get product collection price in INR in product collection when store is IN?

1 Answer 1

0

First of that get product collection :-

<?php
namespace ABC\HelloWorld\Block;
class HelloWorld extends \Magento\Framework\View\Element\Template
{    
    protected $_productCollectionFactory;

    public function __construct(
        \Magento\Backend\Block\Template\Context $context,        
        \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,        
        array $data = []
    )
    {    
        $this->_productCollectionFactory = $productCollectionFactory;    
        parent::__construct($context, $data);
    }

    public function getProductCollection()
    {
        $collection = $this->_productCollectionFactory->create();
        $collection->addAttributeToSelect('*');
        $collection->setPageSize(3); // fetching only 3 products
        return $collection;
    }
}
?>

Then use this block in your phtml and get price as per store vise currency :

    $productCollection = $block->getProductCollection();
    foreach ($productCollection as $product) {
        $price=$objectManager->create('Magento\Framework\Pricing\Helper\Data')->currency(number_format($product->getPrice(),2));// store wise value can change with currency.
    }

Hope it is useful for other.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.