0
購物車定價規則中的prestashop功能之一是可以在一次交易中綁定不同憑證。默認情況下,您可以在單個事務中綁定20個憑單。如何在Prestashop中限制每次交易的憑證綁定
問題是:我如何限制每筆交易的優惠券僅限10張優惠券?
我是否需要在後端自定義代碼或prestahop的管理面板中有一個選項?
希望能得到您的即時回覆。
感謝,
購物車定價規則中的prestashop功能之一是可以在一次交易中綁定不同憑證。默認情況下,您可以在單個事務中綁定20個憑單。如何在Prestashop中限制每次交易的憑證綁定
問題是:我如何限制每筆交易的優惠券僅限10張優惠券?
我是否需要在後端自定義代碼或prestahop的管理面板中有一個選項?
希望能得到您的即時回覆。
感謝,
你必須重寫ParentOrderController類,這種方式:
<?php
class ParentOrderController extends ParentOrderControllerCore {
public function init()
{
$this->isLogged = (bool)($this->context->customer->id && Customer::customerIdExistsStatic((int)$this->context->cookie->id_customer));
FrontController::init();
/* Disable some cache related bugs on the cart/order */
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
$this->nbProducts = $this->context->cart->nbProducts();
if (!$this->context->customer->isLogged(true) && $this->useMobileTheme() && Tools::getValue('step'))
Tools::redirect($this->context->link->getPageLink('authentication', true, (int)$this->context->language->id));
// Redirect to the good order process
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 && Dispatcher::getInstance()->getController() != 'order')
Tools::redirect('index.php?controller=order');
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 && Dispatcher::getInstance()->getController() != 'orderopc')
{
if (Tools::getIsset('step') && Tools::getValue('step') == 3)
Tools::redirect('index.php?controller=order-opc&isPaymentStep=true');
Tools::redirect('index.php?controller=order-opc');
}
if (Configuration::get('PS_CATALOG_MODE'))
$this->errors[] = Tools::displayError('This store has not accepted your new order.');
if (Tools::isSubmit('submitReorder') && $id_order = (int)Tools::getValue('id_order'))
{
$oldCart = new Cart(Order::getCartIdStatic($id_order, $this->context->customer->id));
$duplication = $oldCart->duplicate();
if (!$duplication || !Validate::isLoadedObject($duplication['cart']))
$this->errors[] = Tools::displayError('Sorry. We cannot renew your order.');
else if (!$duplication['success'])
$this->errors[] = Tools::displayError('Some items are no longer available, and we are unable to renew your order.');
else
{
$this->context->cookie->id_cart = $duplication['cart']->id;
$this->context->cookie->write();
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1)
Tools::redirect('index.php?controller=order-opc');
Tools::redirect('index.php?controller=order');
}
}
if ($this->nbProducts)
{
if (CartRule::isFeatureActive())
{
if (Tools::isSubmit('submitAddDiscount'))
{
$cart_rules = $this->context->cart->getCartRules();
if (!($code = trim(Tools::getValue('discount_name'))))
$this->errors[] = Tools::displayError('You must enter a voucher code.');
elseif (!Validate::isCleanHtml($code))
$this->errors[] = Tools::displayError('The voucher code is invalid.');
elseif(count($cart_rules)>=10)
$this->errors[] = Tools::displayError('You have reached the maximum number of coupons that can be used');
else
{
if (($cartRule = new CartRule(CartRule::getIdByCode($code))) && Validate::isLoadedObject($cartRule))
{
if ($error = $cartRule->checkValidity($this->context, false, true))
$this->errors[] = $error;
else
{
$this->context->cart->addCartRule($cartRule->id);
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1)
Tools::redirect('index.php?controller=order-opc&addingCartRule=1');
Tools::redirect('index.php?controller=order&addingCartRule=1');
}
}
else
$this->errors[] = Tools::displayError('This voucher does not exists.');
}
$this->context->smarty->assign(array(
'errors' => $this->errors,
'discount_name' => Tools::safeOutput($code)
));
}
elseif (($id_cart_rule = (int)Tools::getValue('deleteDiscount')) && Validate::isUnsignedId($id_cart_rule))
{
$this->context->cart->removeCartRule($id_cart_rule);
Tools::redirect('index.php?controller=order-opc');
}
}
/* Is there only virtual product in cart */
if ($isVirtualCart = $this->context->cart->isVirtualCart())
$this->setNoCarrier();
}
$this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue('back')));
}
}
這是所有的init()方法,我有充分粘貼,以避免錯誤或錯誤。
差異:
請注意,如果您升級您的ps版本,請記住您已覆蓋整個方法。
享受;)
太棒了!謝謝。 :) 有用。 – 2015-02-10 07:06:35