1

In the code below, I get the product price by identifier, but only the first product price is returned for different product id. Can help me ?

    public function getBundlePriceByid($product_id){
      $_store = 1;
      $this->emulation->startEnvironmentEmulation($_store, \Magento\Framework\App\Area::AREA_FRONTEND, true);
      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
      $product = $objectManager->get('Magento\Catalog\Model\Product')->load($product_id);
      $prices = $product->getPriceInfo()->getPrice('final_price')->getMaximalPrice()->getValue();
      $this->emulation->stopEnvironmentEmulation();
      return $prices;

   }
// 1 = 250$
// 7 = 260$
// 8 = 270$
 $prIds= array(1,7,8);
    foreach($prIds as $prId){
        echo $this->getBundlePriceByid($prId);
    }

returns only 250$

This code I call in Cron Job

1 Answer 1

1

Please try this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
if ($product->getTypeId() == 'bundle') {
      $regularPrice = $product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getValue();
      $specialPrice = $product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();            
}

Here product_id is your product Id.

2
  • This code work without cron, but in cron doesn't work
    – Robinio
    Nov 20, 2019 at 10:21
  • temper, sorry, it works fine , thank you very much, i replaced get to create
    – Robinio
    Nov 20, 2019 at 13:14

Your Answer

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

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