本文整理汇总了PHP中Discount::getIdByName方法的典型用法代码示例。如果您正苦于以下问题:PHP Discount::getIdByName方法的具体用法?PHP Discount::getIdByName怎么用?PHP Discount::getIdByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discount
的用法示例。
在下文中一共展示了Discount::getIdByName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processOrderStep
function processOrderStep($params)
{
global $errors, $cart, $smarty, $order_pages_hook_stay;
/* Manage discounts */
if (intval(Tools::getValue('addDiscount')) == 1) {
$discountName = Tools::getValue('discount_name');
if (!Validate::isDiscountName($discountName)) {
$errors[] = Tools::displayError('voucher name not valid');
} else {
$discount = new Discount(intval(Discount::getIdByName($discountName)));
if (is_object($discount) and $discount->id) {
if ($tmpError = $cart->checkDiscountValidity($discount, $cart->getDiscounts(), $cart->getOrderTotalLC(), $cart->getProducts(), true)) {
$errors[] = $tmpError;
}
} else {
$errors[] = Tools::displayError('voucher name not valid');
}
if (!sizeof($errors)) {
$cart->addDiscount(intval($discount->id));
}
}
// Why do we need a redirect here? Copied from
// original order.php source. Seems like
// otherwize the cart display doesn't get
// updated properly
Tools::redirect('order.php?step=' . $params['step']);
} elseif (intval(Tools::getValue('deleteDiscount')) == 1) {
if (Validate::isUnsignedId($_GET['deleteDiscount'])) {
$cart->deleteDiscount(intval($_GET['deleteDiscount']));
}
Tools::redirect('order.php?step=' . $params['step']);
}
}
示例2: findCode
function findCode($code)
{
if (version_compare(_PS_VERSION_, '1.5', '>=')) {
return CartRule::getIdByCode($code);
} else {
return Discount::getIdByName($code);
}
}
示例3: hookCart
public function hookCart($params)
{
if (isset($params['cookie']->voucherCode)) {
$vouchersInCart = $params['cart']->getDiscounts();
$vouchersInCartIds = array();
if (count($vouchersInCart) > 0) {
foreach ($vouchersInCart as $voucher) {
$vouchersInCartIds[] = $voucher['id_discount'];
}
}
$idDiscount = Discount::getIdByName($params['cookie']->voucherCode);
if (in_array($idDiscount, $vouchersInCartIds)) {
unset($params['cookie']->voucherCode);
} else {
$discountObj = new Discount($idDiscount);
$totalType = Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING;
if ($params['cart']->getOrderTotal(true, $totalType) >= Configuration::get(PS_PURCHASE_MINIMUM) && $params['cart']->getOrderTotal(true, $totalType) >= $discountObj->minimal) {
$params['cart']->addDiscount($idDiscount);
unset($params['cookie']->voucherCode);
}
}
}
}
示例4: preProcess
public function preProcess()
{
global $isVirtualCart;
parent::preProcess();
// Redirect to the good order process
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 and strpos($_SERVER['PHP_SELF'], 'order.php') === false) {
Tools::redirect('order.php');
}
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 and strpos($_SERVER['PHP_SELF'], 'order-opc.php') === false) {
if (isset($_GET['step']) and $_GET['step'] == 3) {
Tools::redirect('order-opc.php?isPaymentStep=true');
}
Tools::redirect('order-opc.php');
}
if (Configuration::get('PS_CATALOG_MODE')) {
$this->errors[] = Tools::displayError('This store has not accepted your new order.');
}
if (Tools::isSubmit('submitReorder') and $id_order = (int) Tools::getValue('id_order')) {
$oldCart = new Cart(Order::getCartIdStatic((int) $id_order, (int) self::$cookie->id_customer));
$duplication = $oldCart->duplicate();
if (!$duplication or !Validate::isLoadedObject($duplication['cart'])) {
$this->errors[] = Tools::displayError('Sorry, we cannot renew your order.');
} elseif (!$duplication['success']) {
$this->errors[] = Tools::displayError('Missing items - we are unable renew your order');
} else {
self::$cookie->id_cart = $duplication['cart']->id;
self::$cookie->write();
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) {
Tools::redirect('order-opc.php');
}
Tools::redirect('order.php');
}
}
if ($this->nbProducts) {
if (Tools::isSubmit('submitAddDiscount') and Tools::getValue('discount_name')) {
$discountName = Tools::getValue('discount_name');
if (!Validate::isDiscountName($discountName)) {
$this->errors[] = Tools::displayError('Voucher name invalid.');
} else {
$discount = new Discount((int) Discount::getIdByName($discountName));
if (Validate::isLoadedObject($discount)) {
if ($tmpError = self::$cart->checkDiscountValidity($discount, self::$cart->getDiscounts(), self::$cart->getOrderTotal(), self::$cart->getProducts(), true)) {
$this->errors[] = $tmpError;
}
} else {
$this->errors[] = Tools::displayError('Voucher name invalid.');
}
if (!sizeof($this->errors)) {
self::$cart->addDiscount((int) $discount->id);
Tools::redirect('order-opc.php');
}
}
self::$smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName)));
} elseif (isset($_GET['deleteDiscount']) and Validate::isUnsignedId($_GET['deleteDiscount'])) {
self::$cart->deleteDiscount((int) $_GET['deleteDiscount']);
Tools::redirect('order-opc.php');
}
/* Is there only virtual product in cart */
if ($isVirtualCart = self::$cart->isVirtualCart()) {
$this->_setNoCarrier();
}
}
self::$smarty->assign('back', Tools::safeOutput(Tools::getValue('back')));
}
示例5: preProcess
public function preProcess()
{
global $isVirtualCart, $cookie;
parent::preProcess();
// Redirect to the good order process
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 0 and (strpos($_SERVER['PHP_SELF'], 'order.php') === false and strpos($_SERVER['PHP_SELF'], 'cart-summary-large.php') === false)) {
Tools::redirect('order.php');
}
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1 and strpos($_SERVER['PHP_SELF'], 'order-opc.php') === false) {
if (isset($_GET['step']) and $_GET['step'] == 3) {
Tools::redirect('order-opc.php?isPaymentStep=true');
}
Tools::redirect('order-opc.php');
}
if (Configuration::get('PS_CATALOG_MODE')) {
$this->errors[] = Tools::displayError('This store has not accepted your new order.');
}
if (Tools::isSubmit('submitReorder') and $id_order = (int) Tools::getValue('id_order')) {
$oldCart = new Cart(Order::getCartIdStatic((int) $id_order, (int) self::$cookie->id_customer));
$duplication = $oldCart->duplicate();
if (!$duplication or !Validate::isLoadedObject($duplication['cart'])) {
$this->errors[] = Tools::displayError('Sorry, we cannot renew your order.');
} elseif (!$duplication['success']) {
$this->errors[] = Tools::displayError('Missing items - we are unable to renew your order');
} else {
self::$cookie->id_cart = $duplication['cart']->id;
self::$cookie->write();
if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) {
Tools::redirect('order-opc.php');
}
Tools::redirect('order.php');
}
}
if (Tools::isSubmit('submit_instructions')) {
$instructions = Tools::getValue('special_instructions');
self::$cart->gift_message = pSQL($instructions);
self::$cart->update();
Tools::redirect('order?step=3');
}
if ($this->nbProducts) {
/* check discount validity */
$cartDiscounts = self::$cart->getDiscounts();
$discountInvalid = false;
foreach ($cartDiscounts as $k => $cartDiscount) {
if ($error = self::$cart->checkDiscountValidity(new Discount((int) $cartDiscount['id_discount']), $cartDiscounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING), self::$cart->getProducts())) {
self::$cart->deleteDiscount((int) $cartDiscount['id_discount']);
$discountInvalid = true;
}
}
if ($discountInvalid) {
Tools::redirect('order-opc.php');
}
if (Tools::getValue('redeem_points')) {
$points = (int) Tools::getValue('redeem_points');
if ($points < 1) {
self::$smarty->assign('redeem_points', $points);
$this->errors[] = Tools::displayError('You can redeem minimum of 1 coin in an order.');
}
$orderTotal = self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$redemption_status = VBRewards::checkPointsValidity($cookie->id_customer, $points + self::$cart->getPoints(), $orderTotal);
if ($redemption_status === CAN_REDEEM_COINS) {
self::$cart->addPoints($points);
self::$smarty->assign('redeem_points', (int) self::$cart->getPoints());
} else {
if ($redemption_status === INSUFFICIENT_VALID_ORDERS) {
$this->errors[] = Tools::displayError('Coins can be redeemed from second purchase onwards.');
} else {
if ($redemption_status === MIN_CRITERIA_NOT_MET) {
$this->errors[] = Tools::displayError('Order value should be more than 100 USD to redeem coins');
}
}
}
$this->adjustPoints();
} elseif (Tools::getValue('deletePoints')) {
self::$cart->deletePoints();
}
if (Tools::isSubmit('submitAddDiscount') and Tools::getValue('discount_name')) {
$discountName = Tools::getValue('discount_name');
if (!Validate::isDiscountName($discountName)) {
$this->errors[] = Tools::displayError('Voucher name invalid.');
} else {
$discount = new Discount((int) Discount::getIdByName($discountName));
if (Validate::isLoadedObject($discount)) {
if ($tmpError = self::$cart->checkDiscountValidity($discount, self::$cart->getDiscounts(), self::$cart->getOrderTotal(), self::$cart->getProducts(), true)) {
$this->errors[] = $tmpError;
}
} else {
$this->errors[] = Tools::displayError('Voucher name invalid.');
}
if (!sizeof($this->errors)) {
self::$cart->addDiscount((int) $discount->id);
Tools::redirect('order-opc.php');
}
}
self::$smarty->assign(array('errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName)));
$this->adjustPoints();
} elseif (isset($_GET['deleteDiscount']) and Validate::isUnsignedId($_GET['deleteDiscount'])) {
self::$cart->deleteDiscount((int) $_GET['deleteDiscount']);
Tools::redirect('order-opc.php');
}
//.........这里部分代码省略.........
示例6: Discount
if ($orderTotalDefaultCurrency < $minimalPurchase) {
$step = 0;
$errors[] = Tools::displayError('A minimum purchase total of') . ' ' . Tools::displayPrice($minimalPurchase, Currency::getCurrency(intval($cart->id_currency))) . ' ' . Tools::displayError('is required in order to validate your order');
}
if (!$cookie->isLogged() and in_array($step, array(1, 2, 3))) {
Tools::redirect('authentication.php?back=order.php?step=' . $step);
}
$smarty->assign('back', Tools::safeOutput(Tools::getValue('back')));
if ($cart->nbProducts()) {
/* Manage discounts */
if ((Tools::isSubmit('submitDiscount') or Tools::isSubmit('submitDiscount')) and Tools::getValue('discount_name')) {
$discountName = Tools::getValue('discount_name');
if (!Validate::isDiscountName($discountName)) {
$errors[] = Tools::displayError('voucher name not valid');
} else {
$discount = new Discount(intval(Discount::getIdByName($discountName)));
if (is_object($discount) and $discount->id) {
if ($tmpError = $cart->checkDiscountValidity($discount, $cart->getDiscounts(), $cart->getOrderTotal(), $cart->getProducts(), true)) {
$errors[] = $tmpError;
}
} else {
$errors[] = Tools::displayError('voucher name not valid');
}
if (!sizeof($errors)) {
$cart->addDiscount(intval($discount->id));
Tools::redirect('order.php');
} else {
$smarty->assign(array('errors' => $errors, 'discount_name' => Tools::safeOutput($discountName)));
}
}
} elseif (isset($_GET['deleteDiscount']) and Validate::isUnsignedId($_GET['deleteDiscount'])) {