- 简单产品
$regularPrice = $product->getPriceInfo()->getPrice('regular_price')->getValue();
$specialPrice = $product->getPriceInfo()->getPrice('special_price')->getValue();
- 2可配置产品
if ($product->getTypeId() == 'configurable') {
$basePrice = $product->getPriceInfo()->getPrice('regular_price');
$regularPrice = $basePrice->getMinRegularAmount()->getValue();
$specialPrice = $product->getFinalPrice();
}
- 3 Bundle product
if ($product->getTypeId() == 'bundle') {
$regularPrice = $product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getValue();
$specialPrice = $product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();
}
- 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是当前产品。