Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
composer require "creativestyle/magesuite-cmscart-searchbonus" ^1.0.0

User manual

3.3. Cart Bonus

...

Free shipping rule is set as a cart bonus with a hidden label. The label is visible when a user passes the threshold.

...

Backend

Template

app/design/frontend/creativestyle/theme-creativeshop/MageSuite_CartBonus/templates/status.phtml
Code Block
<?php /** @var $block \Creativestyle\CartBonusExtension\Block\Status */
$status = $block->getBonusesStatus();

$progressToNextBonusPercentage = $status->getProgressPercentage();
$amountToNextLevel = $status->getRemainingAmountForNextBonusWithCurrency();
$awardedBonusesCount = $status->getAwardedBonusesCount();
$allBonusesCount = $status->getBonusesCount();
$isFirstNotAwarded = true;
$tooltipLeftLimit = $this->getTooltipLeftLimit();
$tooltipRightLimit = $this->getTooltipRightLimit();

.........

Block

vendor/creativestyle/magesuite-cart-bonus/Block/Status.php:32
Code Block
class Status extends \Magento\Framework\View\Element\Template
{
    public function getBonusesStatus()
    {
        $totals = $this->cart->getQuote()->getTotals();
        $currentCartValue = $totals['subtotal']['value'];

        return $this->statusBuilder->build($currentCartValue);
    }
}

Service

vendor/creativestyle/magesuite-cart-bonus/Service/StatusBuilder.php:51
Code Block
class StatusBuilder
{
    public function build($cartValue)
    {
        $status = $this->statusFactory->create();

        $rules = $this->getBonusCartRules();

        $bonuses = [];
        .....
        usort($bonuses, function ($bonus1, $bonus2) {
            return $bonus1->getMinimumCartValue() <=> $bonus2->getMinimumCartValue();
        });

        $status->setBonuses($bonuses);
        $this->calculateCurrentProgress($status, $cartValue);

        return $status;
    }
}

Model

vendor/creativestyle/magesuite-cart-bonus/Model/Bonus/Status.php:34
Code Block
class Status
{
    public function getAwardedBonusesCount() {
        $awardedBonuses = 0;

        foreach($this->bonuses as $bonus) {
            if(!$bonus->wasAwarded()) {
                continue;
            }

            $awardedBonuses++;
        }

        return $awardedBonuses;
    }
}

Plugin

vendor/creativestyle/magesuite-shipping-addons/Plugin/Checkout/Block/Cart/Totals/AddFreeShippingBarVariables.php:40
Code Block
class AddFreeShippingBarVariables
{
    public function afterGetJsLayout(\Magento\Checkout\Block\Cart\Totals $subject, $jsLayout)
    {
        .....
        if (!empty($freeShippingBarConfig)) {
            $freeShippingBarConfig['freeShippingFrom'] = $this->shippingMethodsHelper->getMinimumFreeShippingAmount();
            $freeShippingBarConfig['priceFormat'] = $this->taxHelper->getPriceFormat($this->storeManager->getStore()->getId());

            $jsLayout = $this->arrayManager->set(self::FREE_SHIPPING_BAR_CONFIG_PATH, $jsLayout, $freeShippingBarConfig);
        }

        return json_encode($jsLayout);
    }
}

Frontend

Each bonus is displayed as a section of a bar. After cart page is loaded the progress bar is animated.

...

...

PHTML template

The phtml PHTML template is placed in theme-creativeshop/src/MageSuite_CartBonus/templates/status.phtml

...