Как узнать цену пакета продуктов по идентификатору продукта? Магенто2
В приведенном ниже коде я получаю цену продукта по идентификатору, но для другого идентификатора продукта возвращается только первая цена продукта. Можешь мне помочь?
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);
}
Возвращает только 250$
Этот код я вызываю в задании Cron
1
1 answers
Пожалуйста, попробуйте это:
$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();
}
Здесь product_id
- идентификатор вашего продукта.
1
Author: temper, 2019-11-20 10:08:36