我在这里看过很多关于此的帖子,但没有一个解决方案对我有用,所以我想我会问自己发布自己的代码。
我希望在客户访问购物车页面时选择默认送货方式.从阅读其他帖子我知道它没有被设置,因为用户尚未添加他们的传递地址。
有没有办法可以设置默认投放方式(统一费率),直到用户选择其他方法.这是.phtml文件,显示了可用的交付方法:
<?php $sub = Mage::helper('checkout/cart')->getQuote()->getSubtotal() ?>
<div class="shipping">
<div class="shipping-form">
<?php if (($_shippingRateGroups = $this->getEstimateRates())): ?>
<form id="co-shipping-method-form" action="<?php echo $this->getUrl('checkout/cart/estimateUpdatePost') ?>">
<?php $quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item){
$productId = $item->getProductId();
$product = Mage::getModel('catalog/product')->load($productId);
if($product->getData('direct_delivery_product')==1){?>
<div class="direct_message">
<?php echo 'You have direct delivery products in your shopping cart. This means it may take longer than the standard 2-5 working days to deliver.';?></div>
<?php
break;
}}?>
<div class="block block-login">
<div class="block-slider">
<ul class="slides">
<li>
<div class="block-title">
<h2><span style="font-size:16px; letter-spacing: normal;"><?php echo $this->__('Shipping Options') ?></span></h2>
</div>
<div class="block-content">
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php /* Extensions placeholder */ ?>
<?php echo $this->getChildHtml('customer.form.login.extra')?>
<?php $count = 0;?>
<form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
<ul>
<?php foreach ($_shippingRateGroups as $code => $_rates): ?>
<?php foreach ($_rates as $_rate): ?>
<li<?php if ($_rate->getErrorMessage()) echo ' class="error-msg"';?>>
<?php if ($_rate->getErrorMessage()): ?>
<?php echo $this->escapeHtml($_rate->getErrorMessage()) ?>
<?php else:?>
<input name="estimate_method" type="radio" value="<?php echo $this->escapeHtml($_rate->getCode()) ?>" id="s_method_<?php echo $_rate->getCode() ?>"<?php if($_rate->getCode()===$this->getAddressShippingMethod()) echo ' checked="checked"' ?> class="radio" />
<label for="s_method_<?php echo $_rate->getCode() ?>">
<?php if (($sub > 75 && $count < 1 ) ||(Mage::getSingleton('customer/session')->getCustomerGroupId()==5 && $count < 1 ))
{echo "Free Shipping";}
else{ echo $this->escapeHtml($_rate->getMethodTitle()); }?>
<?php if ($sub == 0 && $count == 0)
{ echo "£4.99";}
else{?>
<?php $_excl = $this->getShippingPrice($_rate->getPrice(), $this->helper('tax')->displayShippingPriceIncludingTax()); ?>
<?php $_incl = $this->getShippingPrice($_rate->getPrice(), true); ?>
<?php echo $_excl; }?>
</label>
<?php ++$count;?>
<?php endif ?>
<?php endforeach; ?>
<?php endforeach; ?>
</ul> <div class="buttons-set">
<button type="submit" title="<?php echo $this->__('Update Total') ?>" class="button" name="do" value="<?php echo $this->__('Update Total') ?>"><span><span><?php echo $this->__('Update Total') ?></span></span></button>
</div>
<a href="<?php echo $this->getForgotPasswordUrl() ?>" class="forgot-password" id="forgot-password"><?php echo $this->__('Click here if shipping internationally to get a quote') ?></a>
</form>
</div>
</li>
<li>
<div class="block-title">
<strong><span><?php echo $this->__('International Shipping') ?></span></strong>
</div>
<div class="block-content">
<form action="<?php echo $this->getUrl('checkout/cart/estimatePost') ?>" method="post" id="shipping-zip-form">
<p><?php echo $this->__('Enter your destination to get a shipping estimate.') ?></p>
<ul class="form-list">
<li>
<div class="input-box">
<?php echo Mage::getBlockSingleton('directory/data')->getCountryHtmlSelect($this->getEstimateCountryId()) ?>
</div>
</li>
</ul>
<div class="buttons-set">
<button type="button" title="<?php echo $this->__('Get a Quote') ?>" onclick="coShippingMethodForm.submit()" class="button"><span><span><?php echo $this->__('Get a Quote') ?></span></span></button>
<a href="<?php echo $this->getForgotPasswordUrl() ?>" class="forgot-password" id="back-login"><?php echo $this->__('Back to UK shipping prices'); ?></a>
</div>
</form>
</div>
</li>
</ul>
</div>
</div>
</div>
<?php endif; ?>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('login-form', true);
var dataForgetForm = new VarienForm('form-validate', true);
//]]>
</script>
<script type="text/javascript">
//<![CDATA[
var coShippingMethodForm = new VarienForm('shipping-zip-form');
var countriesWithOptionalZip = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
coShippingMethodForm.submit = function () {
var country = $F('country');
var optionalZip = true;
return VarienForm.prototype.submit.bind(coShippingMethodForm)();
}
//]]>
</script>
</div>
所以我想要的是默认情况下在我的购物车中选择统一费率,这样用户就不必选择价格然后点击更新,如果他们想要一个不同的送货方式,他们只需要这样做.
谢谢你能提供帮助。
最新回答
- 2019-12-51 #
- 2019-12-52 #
以前的答案似乎是正确的, 另外,我只是快速浏览一下这段代码,如果你想成为一名优秀的开发人员,首先, NEVER 这样做:
{echo "Free Shipping";}
echo'您的购物车中有直接送货产品.这意味着交付时间可能超过标准的2-5个工作日。';
请,让所有的字符串都可以翻译(你可以用:
$this->__('Free Shipping');
并尝试遵循Magento编码标准。 - 2019-12-53 #
在 checkout>cart>shipping.phtml的最后放置脚本 文件
<script type="text/javascript"> jQuery("#Id_Of_Your_Shipping_Method").attr("checked", true); </script>
第43行
正在检查复选框(
echo checked = "checked"
)如果条件$_rate->getCode()===$this->getAddressShippingMethod()
是真的.我建议在条件中添加一些内容,例如 -
([[existing condition]] || $rate->getCode()=="flatrate"
)有了这个,你可以在这个条件成立时检查它,即使原来的条件不是这样.
希望这能指出你正确的方向。