当前位置: 首页>>代码示例>>PHP>>正文


PHP Coupon::available方法代码示例

本文整理汇总了PHP中Coupon::available方法的典型用法代码示例。如果您正苦于以下问题:PHP Coupon::available方法的具体用法?PHP Coupon::available怎么用?PHP Coupon::available使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Coupon的用法示例。


在下文中一共展示了Coupon::available方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getSubstitutionArray


//.........这里部分代码省略.........
                 // Default to unlimited validity
                 // In case there are protected downloads in the cart,
                 // collect the group IDs
                 $arrUsergroupId = array();
                 if ($objProduct->distribution() == 'download') {
                     $usergroupIds = $objProduct->usergroup_ids();
                     if ($usergroupIds != '') {
                         $arrUsergroupId = explode(',', $usergroupIds);
                         $validity = $objProduct->weight();
                     }
                 }
                 // create an account that belongs to all collected
                 // user groups, if any.
                 if (count($arrUsergroupId) > 0) {
                     // The login names are created separately for
                     // each product instance
                     $username = self::usernamePrefix . "_{$order_id}_{$product_id}_{$instance}";
                     $userEmail = $username . '-' . $arrSubstitution['CUSTOMER_EMAIL'];
                     $userpass = \User::make_password();
                     $objUser = new \User();
                     $objUser->setUsername($username);
                     $objUser->setPassword($userpass);
                     $objUser->setEmail($userEmail);
                     $objUser->setAdminStatus(false);
                     $objUser->setActiveStatus(true);
                     $objUser->setGroups($arrUsergroupId);
                     $objUser->setValidityTimePeriod($validity);
                     $objUser->setFrontendLanguage(FRONTEND_LANG_ID);
                     $objUser->setBackendLanguage(FRONTEND_LANG_ID);
                     $objUser->setProfile(array('firstname' => array(0 => $arrSubstitution['CUSTOMER_FIRSTNAME']), 'lastname' => array(0 => $arrSubstitution['CUSTOMER_LASTNAME']), 'company' => array(0 => $arrSubstitution['CUSTOMER_COMPANY']), 'address' => array(0 => $arrSubstitution['CUSTOMER_ADDRESS']), 'zip' => array(0 => $arrSubstitution['CUSTOMER_ZIP']), 'city' => array(0 => $arrSubstitution['CUSTOMER_CITY']), 'country' => array(0 => $arrSubstitution['CUSTOMER_COUNTRY_ID']), 'phone_office' => array(0 => $arrSubstitution['CUSTOMER_PHONE']), 'phone_fax' => array(0 => $arrSubstitution['CUSTOMER_FAX'])));
                     if (!$objUser->store()) {
                         \Message::error(implode('<br />', $objUser->getErrorMsg()));
                         return false;
                     }
                     if (empty($arrProduct['USER_DATA'])) {
                         $arrProduct['USER_DATA'] = array();
                     }
                     $arrProduct['USER_DATA'][] = array('USER_NAME' => $username, 'USER_PASS' => $userpass);
                 }
                 //echo("Instance $instance");
                 if ($objProduct->distribution() == 'coupon') {
                     if (empty($arrProduct['COUPON_DATA'])) {
                         $arrProduct['COUPON_DATA'] = array();
                     }
                     //DBG::log("Orders::getSubstitutionArray(): Getting code");
                     $code = Coupon::getNewCode();
                     //DBG::log("Orders::getSubstitutionArray(): Got code: $code, calling Coupon::addCode($code, 0, 0, 0, $item_price)");
                     Coupon::storeCode($code, 0, 0, 0, $item_price, 0, 0, 10000000000.0, true);
                     $arrProduct['COUPON_DATA'][] = array('COUPON_CODE' => $code);
                 }
             }
             // Redeem the *product* Coupon, if possible for the Product
             if ($coupon_code) {
                 $objCoupon = Coupon::available($coupon_code, $item_price * $quantity, $customer_id, $product_id, $payment_id);
                 if ($objCoupon) {
                     $coupon_code = NULL;
                     $coupon_amount = $objCoupon->getDiscountAmount($item_price, $customer_id);
                     if ($create_accounts) {
                         $objCoupon->redeem($order_id, $customer_id, $item_price * $quantity);
                     }
                 }
                 //\DBG::log("Orders::getSubstitutionArray(): Got Product Coupon $coupon_code");
             }
         }
         if (empty($arrSubstitution['ORDER_ITEM'])) {
             $arrSubstitution['ORDER_ITEM'] = array();
         }
         $arrSubstitution['ORDER_ITEM'][] = $arrProduct;
     }
     $arrSubstitution['ORDER_ITEM_SUM'] = sprintf('% 9.2f', $total_item_price);
     $arrSubstitution['ORDER_ITEM_COUNT'] = sprintf('% 4u', $orderItemCount);
     // Redeem the *global* Coupon, if possible for the Order
     if ($coupon_code) {
         $objCoupon = Coupon::available($coupon_code, $total_item_price, $customer_id, null, $payment_id);
         if ($objCoupon) {
             $coupon_amount = $objCoupon->getDiscountAmount($total_item_price, $customer_id);
             if ($create_accounts) {
                 $objCoupon->redeem($order_id, $customer_id, $total_item_price);
             }
         }
     }
     \Message::restore();
     // Fill in the Coupon block with proper discount and amount
     if ($objCoupon) {
         $coupon_code = $objCoupon->code();
         //\DBG::log("Orders::getSubstitutionArray(): Coupon $coupon_code, amount $coupon_amount");
     }
     if ($coupon_amount) {
         //\DBG::log("Orders::getSubstitutionArray(): Got Order Coupon $coupon_code");
         $arrSubstitution['DISCOUNT_COUPON'][] = array('DISCOUNT_COUPON_CODE' => sprintf('%-40s', $coupon_code), 'DISCOUNT_COUPON_AMOUNT' => sprintf('% 9.2f', -$coupon_amount));
     } else {
         //\DBG::log("Orders::getSubstitutionArray(): No Coupon for Order ID $order_id");
     }
     Products::deactivate_soldout();
     if (Vat::isEnabled()) {
         //DBG::log("Orders::getSubstitutionArray(): VAT amount: ".$objOrder->vat_amount());
         $arrSubstitution['VAT'] = array(0 => array('VAT_TEXT' => sprintf('%-40s', Vat::isIncluded() ? $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_INCL'] : $_ARRAYLANG['TXT_SHOP_VAT_PREFIX_EXCL']), 'VAT_PRICE' => $objOrder->vat_amount()));
     }
     return $arrSubstitution;
 }
开发者ID:Niggu,项目名称:cloudrexx,代码行数:101,代码来源:Orders.class.php

示例2: process


//.........这里部分代码省略.........
         if (!$objProduct) {
             unset($_SESSION['shop']['order_id']);
             return \Message::error($_ARRAYLANG['TXT_ERROR_LOOKING_UP_ORDER']);
         }
         $product_id = $arrProduct['id'];
         $name = $objProduct->name();
         $priceOptions = !empty($arrProduct['optionPrice']) ? $arrProduct['optionPrice'] : 0;
         $quantity = $arrProduct['quantity'];
         $price = $objProduct->get_custom_price(self::$objCustomer, $priceOptions, $quantity);
         $item_total = $price * $quantity;
         $items_total += $item_total;
         $productVatId = $objProduct->vat_id();
         $vat_rate = $productVatId && Vat::getRate($productVatId) ? Vat::getRate($productVatId) : '0.00';
         // Test the distribution method for delivery
         $productDistribution = $objProduct->distribution();
         if ($productDistribution == 'delivery') {
             $_SESSION['shop']['isDelivery'] = true;
         }
         $weight = $productDistribution == 'delivery' ? $objProduct->weight() : 0;
         // grams
         if ($weight == '') {
             $weight = 0;
         }
         // Add to order items table
         $result = $objOrder->insertItem($order_id, $product_id, $name, $price, $quantity, $vat_rate, $weight, $arrProduct['options']);
         if (!$result) {
             unset($_SESSION['shop']['order_id']);
             // TODO: Verify error message set by Order::insertItem()
             return false;
         }
         // Store the Product Coupon, if applicable.
         // Note that it is not redeemed yet (uses=0)!
         if ($coupon_code) {
             $objCoupon = Coupon::available($coupon_code, $item_total, self::$objCustomer->id(), $product_id, $payment_id);
             if ($objCoupon) {
                 //\DBG::log("Shop::process(): Got Coupon for Product ID $product_id: ".var_export($objCoupon, true));
                 if (!$objCoupon->redeem($order_id, self::$objCustomer->id(), $price * $quantity, 0)) {
                     // TODO: Do something if the Coupon does not work
                     \DBG::log("Shop::process(): ERROR: Failed to store Coupon for Product ID {$product_id}");
                 }
                 $coupon_code = null;
             }
         }
     }
     // foreach product in cart
     // Store the Global Coupon, if applicable.
     // Note that it is not redeemed yet (uses=0)!
     //\DBG::log("Shop::process(): Looking for global Coupon $coupon_code");
     if ($coupon_code) {
         $objCoupon = Coupon::available($coupon_code, $items_total, self::$objCustomer->id(), null, $payment_id);
         if ($objCoupon) {
             //\DBG::log("Shop::process(): Got global Coupon: ".var_export($objCoupon, true));
             if (!$objCoupon->redeem($order_id, self::$objCustomer->id(), $items_total, 0)) {
                 \DBG::log("Shop::process(): ERROR: Failed to store global Coupon");
             }
         }
     }
     \Message::restore();
     $processor_id = Payment::getProperty($_SESSION['shop']['paymentId'], 'processor_id');
     $processor_name = PaymentProcessing::getPaymentProcessorName($processor_id);
     // other payment methods
     PaymentProcessing::initProcessor($processor_id);
     // TODO: These arguments are no longer valid.  Set them up later?
     //            Currency::getActiveCurrencyCode(),
     //            FWLanguage::getLanguageParameter(FRONTEND_LANG_ID, 'lang'));
     // if the processor is Internal_LSV, and there is account information,
开发者ID:nahakiole,项目名称:cloudrexx,代码行数:67,代码来源:Shop.class.php

示例3: update


//.........这里部分代码省略.........
                     }
                     if ($options_price != 0) {
                         $product['optionPrice'] = $options_price;
                     }
          */
         $quantity = $product['quantity'];
         $items += $quantity;
         $itemprice = $objProduct->get_custom_price($objCustomer, $options_price, $quantity);
         $price = $itemprice * $quantity;
         $handler = $objProduct->distribution();
         $itemweight = $handler == 'delivery' ? $objProduct->weight() : 0;
         // Requires shipment if the distribution type is 'delivery'
         if ($handler == 'delivery') {
             //DBG::log("Cart::update(): Product ID ".$objProduct->id()." needs delivery");
             $_SESSION['shop']['cart']['shipment'] = true;
         }
         $weight = $itemweight * $quantity;
         $vat_rate = Vat::getRate($objProduct->vat_id());
         $total_price += $price;
         $total_weight += $weight;
         self::$products[$cart_id] = array('id' => $objProduct->id(), 'product_id' => $objProduct->code(), 'cart_id' => $cart_id, 'title' => empty($_GET['remoteJs']) ? $objProduct->name() : htmlspecialchars(strtolower(CONTREXX_CHARSET) == 'utf-8' ? $objProduct->name() : utf8_encode($objProduct->name()), ENT_QUOTES, CONTREXX_CHARSET), 'options' => $product['options'], 'options_long' => $options_strings[0], 'options_cart' => $options_strings[1], 'price' => Currency::formatPrice($price), 'quantity' => $quantity, 'itemprice' => Currency::formatPrice($itemprice), 'vat_rate' => $vat_rate, 'itemweight' => $itemweight, 'weight' => $weight, 'group_id' => $objProduct->group_id(), 'article_id' => $objProduct->article_id(), 'product_images' => $objProduct->pictures(), 'minimum_order_quantity' => $objProduct->minimum_order_quantity());
         //DBG::log("Cart::update(): Loop 1: Product: ".var_export(self::$products[$cart_id], true));
     }
     $_SESSION['shop']['cart']['items'] = $products;
     // Loop 2: Calculate Coupon discounts and VAT
     $objCoupon = null;
     $hasCoupon = false;
     $discount_amount = 0;
     foreach (self::$products as $cart_id => &$product) {
         $discount_amount = 0;
         $product['discount_amount'] = 0;
         // Coupon:  Either the payment ID or the code are needed
         if ($payment_id || $coupon_code) {
             $objCoupon = Coupon::available($coupon_code, $total_price, $customer_id, $product['id'], $payment_id);
             if ($objCoupon) {
                 $hasCoupon = true;
                 //DBG::log("Cart::update(): PRODUCT; Coupon available: $coupon_code, Product ID {$product['id']}");
                 //DBG::log("Cart::update(): Loop 2: Product: ".var_export($product, true));
                 $discount_amount = $objCoupon->getDiscountAmount($product['price'], $customer_id);
                 if ($objCoupon->discount_amount() > 0 && $total_discount_amount + $discount_amount > $objCoupon->discount_amount()) {
                     //DBG::log("Cart::update(): COUPON prelimit: PRODUCT: price ".$product['price'].", coupon discount amount ".$objCoupon->discount_amount().", discount_amount $discount_amount, total discount amount $total_discount_amount");
                     $discount_amount = $objCoupon->discount_amount() - $total_discount_amount;
                     //DBG::log("Cart::update(): COUPON postlimit: PRODUCT: price ".$product['price'].", coupon discount amount ".$objCoupon->discount_amount().", discount_amount $discount_amount, total discount amount $total_discount_amount");
                 }
                 $total_discount_amount += $discount_amount;
                 //                    $product['price'] = Currency::formatPrice(
                 //                        $product['price'] - $discount_amount);
                 $product['discount_amount'] = $discount_amount;
                 // UNUSED
                 //                        $arrProduct['coupon_string'] =
                 //                            $objCoupon->getString($discount_amount);
                 //DBG::log("Cart::update(): PRODUCT: price ".$product['price'].", discount_amount $discount_amount, total discount $total_discount_amount");
             }
         }
         // Calculate the amount if it's excluded; we might add it later:
         // - If it's included, we don't care.
         // - If it's disabled, it's set to zero.
         $vat_amount = Vat::amount($product['vat_rate'], $product['price'] - $product['discount_amount']);
         if (!Vat::isIncluded()) {
             self::$products[$cart_id]['price'] += $vat_amount;
             self::$products[$cart_id]['price'] = Currency::formatPrice(self::$products[$cart_id]['price']);
         }
         $total_vat_amount += $vat_amount;
         self::$products[$cart_id]['vat_amount'] = Currency::formatPrice($vat_amount);
     }
     // Global Coupon:  Either the payment ID or the code are needed
开发者ID:Niggu,项目名称:cloudrexx,代码行数:67,代码来源:Cart.class.php


注:本文中的Coupon::available方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。