Проверка, есть ли у дочерних продуктов настраиваемого продукта специальная цена?


В список добавлен следующий код.phtml, но он работает только для простых продуктов. Когда у них есть специальная цена с диапазоном дат, к изображению продукта на страницах категорий прикрепляется этикетка продажи. Это также отображает новую метку на продуктах, которые установлены как НОВЫЕ с диапазоном дат (новая метка работает для всех продуктов).

Я пытаюсь найти способ объединить специальную проверку цен, которая работает для простых продуктов и для настраиваемых продукты в том случае, если все дочерние продукты настраиваемого продукта имеют специальную цену.

<?php
$specialprice = $_product->getSpecialPrice();
$specialPriceFromDate = $_product->getSpecialFromDate();
$specialPriceToDate = $_product->getSpecialToDate();
$now = date("Y-m-d");
$newsFrom = substr($_product->getNewsFromDate(), 0, 10);
$newsTo = substr($_product->getNewsToDate(), 0, 10);
$today = time();
$class_has_new = "";
if ($newsTo != '' || $newsFrom != '') {
    if (($newsTo != '' && $newsFrom != '' && $now >= $newsFrom && $now <= $newsTo) || ($newsTo == '' && $now >= $newsFrom) || ($newsFrom == '' && $now <= $newsTo)) {
        $class_has_new = " has-new";
    }
}
if ($specialprice) {
    if ($today >= strtotime($specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime($specialPriceFromDate) && is_null($specialPriceToDate)) { ?>
        <div class="label-product label-sale<?php echo $class_has_new; ?>">
            <span class="sale-product-icon">
                <?php echo __('Sale'); ?>
            </span>
        </div>
<?php }
}
?>
<?php
if ($newsTo != '' || $newsFrom != '') {
    if (($newsTo != '' && $newsFrom != '' && $now >= $newsFrom && $now <= $newsTo) || ($newsTo == '' && $now >= $newsFrom) || ($newsFrom == '' && $now <= $newsTo)) { ?>
        <div class="label-product label-new">
            <span class="new-product-icon"><?php echo __('New'); ?></span>
        </div>
    <?php }
} ?>
Author: Empire402, 2020-10-13

1 answers

Это должно помочь вам:

<?php if ($_product->getTypeId() == 'bundle') {
    $finalPrice = $_product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();
    $orgPrice = $_product->getPriceInfo()->getPrice('regular_price')->getMinimalPrice()->getValue();
} elseif ($_product->getTypeId() == 'grouped') {
    $usedProds = $_product->getTypeInstance(true)->getAssociatedProducts($product);
    $finalPrice = 0;
    $orgPrice = 0;
    foreach ($usedProds as $child) {
        if ($child->getId() != $product->getId()) {
            $finalPrice += $child->getFinalPrice();
            $orgPrice += $child->getPrice();
        }
    }
} elseif ($_product->getTypeId() == 'configurable') {
    $finalPrice = $_product->getPriceInfo()->getPrice('final_price')->getMinimalPrice()->getValue();
    $orgPrice = $_product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue();
} else { //simple product
    $finalPrice = $_product->getFinalPrice();
    $orgPrice = $_product->getPrice();
}
?>

Теперь вы можете просто сравнить final price и org price.

 0
Author: Adarsh Khatri, 2020-10-15 01:03:35