Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

Magento2 如何获取所有产品类型的正常价格和最终价格

  1. 简单产品
$regularPrice = $product->getPriceInfo()->getPrice('regular_price')->getValue();
$specialPrice = $product->getPriceInfo()->getPrice('special_price')->getValue();
  1. 2可配置产品
if ($product->getTypeId() == 'configurable') {
      $basePrice = $product->getPriceInfo()->getPrice('regular_price');

      $regularPrice = $basePrice->getMinRegularAmount()->getValue();
      $specialPrice = $product->getFinalPrice();
}
  1. 3 Bundle product
if ($product->getTypeId() == 'bundle') {
      $regularPrice = $product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getValue();
      $specialPrice = $product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();            
}
  1. 4 Group product
if ($product->getTypeId() == 'grouped') {
      $usedProds = $product->getTypeInstance(true)->getAssociatedProducts($product);            
      foreach ($usedProds as $child) {
          if ($child->getId() != $product->getId()) {
                $regularPrice += $child->getPrice();
                $specialPrice += $child->getFinalPrice();
          }
      }
}

注意:在上面的示例中,$ product是当前产品。

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论