Commit a9de767e by dhn

购物车添加提示

parent 04229993
...@@ -691,6 +691,15 @@ class Cart extends DataObject implements CartInterface ...@@ -691,6 +691,15 @@ class Cart extends DataObject implements CartInterface
return $this->getQuote()->getItemsQty() * 1; return $this->getQuote()->getItemsQty() * 1;
} }
public function getSubtotal()
{
return $this->getQuote()->getSubtotal();
}
public function getGrandTotal()
{
return $this->getQuote()->getGrandTotal();
}
/** /**
* Update item in shopping cart (quote) * Update item in shopping cart (quote)
* $requestInfo - either qty (int) or buyRequest in form of array or \Magento\Framework\DataObject * $requestInfo - either qty (int) or buyRequest in form of array or \Magento\Framework\DataObject
......
...@@ -22,10 +22,106 @@ if (count($_items) > 0) { ...@@ -22,10 +22,106 @@ if (count($_items) > 0) {
$priceSum += $value->getPrice() * $value->getQty(); $priceSum += $value->getPrice() * $value->getQty();
} }
} }
$subtotal = $_cart->getSubtotal();
$_shipping = $objectManager->get('\Magento\Checkout\Block\Cart\Shipping');
$free_shipping_subtotal = $_shipping->getFreeShippingSubtotal();
$is_free_shipping = false;
$difference_price = 0;
if($subtotal >= $free_shipping_subtotal)
{
$is_free_shipping = true;
}
else
{
$difference_price = $free_shipping_subtotal - $subtotal;
}
?> ?>
<style>
.free_message{
margin-left: .7rem;
text-align: left;
}
.free_message.tddiv{
margin-left: 1.3rem;
}
.free-shipping-area .cart-icon{
float: left;
}
.free-shipping-area .content-wrap{
float: left;
}
.free-shipping-area{
width:100%!important;
order:-3;
padding: 15px;
background-color: #FFFFFF;
color:#000;
}
@media(min-width:768px){
.free-shipping-area{
padding: 10px 10px 10px 20px;
}
.area-blk-notitle{
display:none;
}
}
@media(max-width:768px){
.free-shipping-area{
padding: 0px;
}
.free-shipping-area .content-wrap{
padding: 10px 0px;background-color: #f2f2f2;
width:100%;
}
.area-blk{
display:none;
}
.area-fix {
position: fixed;
left: 0;
z-index: 1;
border-top: 1px solid #fff;
}
}
</style>
<?php $mergedCells = ($this->helper(Magento\Tax\Helper\Data::class)->displayCartBothPrices() ? 2 : 1); ?> <?php $mergedCells = ($this->helper(Magento\Tax\Helper\Data::class)->displayCartBothPrices() ? 2 : 1); ?>
<?= $block->getChildHtml('form_before') ?> <?= $block->getChildHtml('form_before') ?>
<?php if (!$is_free_shipping): ?>
<div class="free-shipping-area area-blk">
<img alt="" class="cart-icon" src="/media/wysiwyg/free-shipping-cart.svg">
<div class="content-wrap">
<div class="free_message">
<div class="msg-title">
<p style="font-weight: bold;">Shipping Fee</p>
</div>
<div class="msg-content">
Spend <span style="color:#EB001B;font-size: 16px;font-weight: bold;"><?= $block->escapeHtml(
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($difference_price),
['span']
) ?></span> more and get <span style="font-weight: bold;">FREE SHIPPING</span>!
</div>
</div>
</div>
</div>
<?php endif ?>
<?php if (!$is_free_shipping): ?>
<div class="free-shipping-area area-blk-notitle">
<div class="content-wrap">
<div class="free_message">
<div class="msg-content">
Spend <span style="color:#EB001B;font-size: 16px;"><?= $block->escapeHtml(
$this->helper(Magento\Checkout\Helper\Data::class)->formatPrice($difference_price),
['span']
) ?></span> more and get FREE SHIPPING!
</div>
</div>
</div>
</div>
<?php endif ?>
<form action="<?= $block->escapeUrl($block->getUrl('checkout/cart/updatePost')) ?>" <form action="<?= $block->escapeUrl($block->getUrl('checkout/cart/updatePost')) ?>"
method="post" method="post"
id="form-validate" id="form-validate"
...@@ -35,6 +131,7 @@ if (count($_items) > 0) { ...@@ -35,6 +131,7 @@ if (count($_items) > 0) {
}' }'
class="form form-cart"> class="form form-cart">
<?= $block->getBlockHtml('formkey') ?> <?= $block->getBlockHtml('formkey') ?>
<div class="cart table-wrapper<?= $mergedCells == 2 ? ' detailed' : '' ?>"> <div class="cart table-wrapper<?= $mergedCells == 2 ? ' detailed' : '' ?>">
<?php if ($block->getPagerHtml()): ?> <?php if ($block->getPagerHtml()): ?>
<div class="cart-products-toolbar cart-products-toolbar-top toolbar" <div class="cart-products-toolbar cart-products-toolbar-top toolbar"
...@@ -119,6 +216,41 @@ require(['jquery'], function ($) { ...@@ -119,6 +216,41 @@ require(['jquery'], function ($) {
return false; return false;
} }
}); });
var isMobile = window.matchMedia("(pointer:coarse)").matches;
if (isMobile) {
var fixHeight = $('.area-blk-notitle').height();
$(window).scroll(function () {
if(!$('#checkout-step-shipping').is(":visible")) {
$(window).scroll(function () {
var scrollTop = $(document).scrollTop();
var fixTop = $('.area-blk-notitle').offset().top;
var tableTop = $('#shopping-cart-table').offset().top;
var tableHeight = $('#shopping-cart-table').height();
var headerHeight = $('.page-header').height();
if(scrollTop >= fixTop - headerHeight)
{
if(scrollTop < tableTop + tableHeight - fixHeight)
{
$('.area-blk-notitle .content-wrap').addClass("area-fix");
$('.area-blk-notitle .content-wrap').css({ "top": headerHeight});
}
else
{
$('.area-blk-notitle .content-wrap').removeClass("area-fix");
}
}
else {
$('.area-blk-notitle .content-wrap').removeClass("area-fix");
}
});
}
});
}
}); });
</script> </script>
<script> <script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment