...
There are no admin settings. However, the free shipping bar is not enabled by default. Check the fronted section for more details.
Backend
Note |
---|
TODO - BE documentation and review of documentation is needed |
There is template with display free shiping bar
vendor/creativestyle/magesuite-shipping-addons/view/frontend/templates/cart/free-shipping-bar.phtml
Code Block |
---|
<script type="text/x-magento-init">
{
"[data-block='free-shipping-bar']": {
"Magento_Ui/js/core/app": <?php /* @escapeNotVerified */ echo $block->getJsLayout() ?>
},
"*": {
"Magento_Ui/js/block-loader": "<?= /* @escapeNotVerified */ $block->getViewFileUrl('images/loader-1.gif') ?>"
}
}
</script> |
We calculate freeShipingForm and priceFormat in plugin for getJsLayout method
For Cart Sidebar:
vendor/creativestyle/magesuite-shipping-addons/Plugin/Checkout/Block/Cart/Sidebar/AddFreeShippingBarVariables.php:40
Code Block |
---|
class AddFreeShippingBarVariables
{
public function afterGetJsLayout(\Magento\Checkout\Block\Cart\Sidebar $subject, $jsLayout)
{
$jsLayout = json_decode($jsLayout, true);
$freeShippingBarConfig = $this->arrayManager->get(self::FREE_SHIPPING_BAR_CONFIG_PATH, $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);
}
} |
or for Totals
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)
{
$jsLayout = json_decode($jsLayout, true);
$freeShippingBarConfig = $this->arrayManager->get(self::FREE_SHIPPING_BAR_CONFIG_PATH, $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);
}
} |
Calculating minimum amount
vendor/creativestyle/magesuite-shipping-addons/Helper/ShippingMethods.php:21
Code Block |
---|
class ShippingMethods extends \Magento\Framework\App\Helper\AbstractHelper
{
public function getMinimumFreeShippingAmount()
{
$minimumAmount = null;
foreach ($this->freeShippingMethodsProvider->getShippingMethodsWithFreeShipping() as $methodData) {
if (!$minimumAmount || (int) $methodData['value'] < $minimumAmount) {
$minimumAmount = (int) $methodData['value'];
}
}
return $minimumAmount;
}
} |
vendor/creativestyle/magesuite-shipping-addons/Service/FreeShippingMethodsProvider.php:37
Code Block |
---|
class FreeShippingMethodsProvider
{
public function getShippingMethodsWithFreeShipping()
{
$activeCarriers = $this->shippingConfig->getActiveCarriers();
$methods = [];
foreach ($activeCarriers as $code => $model) {
.....
$freeShippingSubtotal = $this->configuration->getFreeShippingSubtotal($code, $subtotalField);
$freeShippingTitle = $this->configuration->getFreeShippingTitle($code);
$methods[$code] = [
'title' => $freeShippingTitle,
'value' => $freeShippingSubtotal
];
}
return $methods;
}
} |
Frontend
Note |
---|
“Free shipping bar” component is disabled by default. In order to show the bar every child theme has to enable it in XML |
...
There are the following options that can be changed from the XML file:
name | default value |
---|---|
componentDisabled | true |
template | MageSuite_ShippingAddons/cart/free-shipping-bar |
fulfilledText | Free shipping applied |
displayThresholdValues | true |
shippingIconUrl | images/icons/shipping.svg |
Minicart free shipping bar:
...