0

Magento2- How to get the product price without catalog price rule applied.

I want to add an additional price percentage to all the product before the catalog rule applied.

Basically what I want is :

Product price(without catalog rule applied)+10% of product price and after that catalog price rule should be applied.

1

use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollection;

class yourClass
{ /** * @var ProductCollection */ private $_productCollection;

public function __construct(
    ProductCollection $productCollection,

){ $this->_productCollection = $productCollection; }

public function UpdateProductPrice() {

$collection = $this->_productCollection->create();

 foreach ($collection as $product) {
 $initialPrice=$product->getPrice();
 $saticPrice=0.1*$initialPrice();
 $fianlPrice=$initialPrice+$staticPrice;
 $product->setPrice($finalPrice);
 $product->save()
 }

}

}

  • I don't want to save in database I just to show the price on frontend – MagentoDev Aug 5 at 6:33
  • In listing page or in category page – mohith Aug 5 at 6:37
  • every where in frontned : Listing , detail, catalog, checkout etc – MagentoDev Aug 5 at 6:46
  • if that's the case you need to over ride so many phtml files instead of that changing the price in the product level is better – mohith Aug 5 at 6:48
  • Is there not a common function for a price where I can change the price and it will reflect everywhere. – MagentoDev Aug 5 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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