Beispiel #1
0
 public function actionCoupon()
 {
     if ($_GET['remove'] && !empty($_GET['remove'])) {
         cart_discount::model()->deleteAllByAttributes(array('discount_ID' => $_GET['remove'], 'cart_ID' => Yii::app()->user->getState('cart_ID')));
         Yii::app()->user->setFlash('cart', "voucher has been removed");
         $this->redirect(array('index'));
         exit;
     }
     if ($_POST['token'] != md5(Yii::app()->user->getStateKeyPrefix())) {
         $this->redirect(array('index'));
         exit;
     }
     if (!$_POST['code'] or empty($_POST['code'])) {
         Yii::app()->user->setFlash('cart', "voucher name can't be blank");
         $this->redirect(array('index'));
         exit;
     }
     if (!($discount = discount_entity::model()->findByAttributes(array('discount_name' => $_POST['code'])))) {
         Yii::app()->user->setFlash('cart', "voucher name not valid");
         $this->redirect(array('index'));
         exit;
     }
     $cart = cart::model()->findByPk(Yii::app()->user->getState('cart_ID'));
     if ($msg = $cart->validateDiscount($_POST['total'], $discount->discount_ID, true)) {
         Yii::app()->user->setFlash('cart', $msg);
         $this->redirect(array('index'));
         exit;
     } else {
         $cartDiscount = new cart_discount();
         $cartDiscount->cart_ID = $cart->cart_ID;
         $cartDiscount->discount_ID = $discount->discount_ID;
         $cartDiscount->save();
     }
     $this->redirect(array('index'));
 }
Beispiel #2
0
 /**
  * This function returns the total cart amount
  *
  * type = 1 : only products
  * type = 2 : only discounts
  * type = 3 : both
  * type = 4 : both but without shipping
  * type = 5 : only shipping
  *
  *
  * @param integer $type Total type
  * @return float Order total
  */
 public function getOrderTotal($type = 3)
 {
     if (!$this->cart_ID) {
         return 0;
     }
     $type = intval($type);
     if (!in_array($type, array(1, 2, 3, 4, 5))) {
         return 0;
     }
     $shipping_fees = ($type != 4 and $type != 1) ? $this->getOrderShippingCost(NULL) : 0;
     $orderTotal = 0;
     foreach ($this->products as $product) {
         $quantity = $this->containProduct($product->product_ID);
         $price = $product->getInternalPrice(true, $quantity['quantity']);
         $subtotal = $price * $quantity['quantity'];
         $orderTotal += $subtotal;
     }
     $order_total_products = $orderTotal;
     if ($type == 2) {
         $orderTotal = 0;
     }
     if ($type != 1) {
         if (sizeof($discounts = cart_discount::items($this->cart_ID)) >= 1) {
             foreach ($discounts as $discount) {
                 if ($discount['discount_type'] == 3) {
                     if ($type == 2) {
                         $orderTotal -= $shipping_fees;
                     }
                     $shipping_fees = 0;
                     break;
                 } else {
                     if ($discount['discount_type'] == 2) {
                         $orderTotal -= floatval($discount['discount_value']);
                     } else {
                         if ($discounts['discount_type'] == 1) {
                             $orderTotal -= round($order_total_products * (1 - $discount['discount_value'] / 100), 2);
                         }
                     }
                 }
             }
         }
     }
     if ($type == 5) {
         return $shipping_fees;
     }
     if ($type == 3) {
         return round($orderTotal += $shipping_fees, 2);
     }
     if ($orderTotal < 0 and $type != 2) {
         return 0;
     }
     return round(floatval($orderTotal), 2);
 }
Beispiel #3
0
?>
" >
                            <input type="submit" size="20" value="Check" />

                        </p>
                    </form>

                    <strong class="t_c1">Total Products:<span class="red"><?php 
echo $currencySign . $productTotal;
?>
</span></strong>
                </div>
<?php 
$cart->checkDiscounts($cart->getOrderTotal(1));
//Coupon segment
$discounts = cart_discount::items($cart->cart_ID);
if (sizeof($discounts) >= 1) {
    echo "  \n                                 <table width='100%' class='table1'>\n                <thead>\n                    <tr>\n                        <th width='10%'>code</th>\n                        <th width='70%'>description</th>\n                         <th width='10%'>Discount Price</th>\n                        <th width='10%' class='thlast'>Action</th>\n                    </tr>\n                </thead>\n                <tbody>";
    foreach ($discounts as $row) {
        if ($row['discount_type'] == 3) {
            $value = 'Freeshipping';
        } else {
            if ($row['discount_type'] == 2) {
                $value = product_entity::decoratePrice($row['discount_value'], true);
            } else {
                if ($row['discount_type'] == 1) {
                    $value = $product_entity::decoratePrice($productTotal * (1 - $row['discount_value'] / 100), true);
                }
            }
        }
        echo <<<EOC
Beispiel #4
0
 public function validateOrder($cart_ID, $order_status, $amountPaid, $paymentMethod = 'Unknown', $message = NULL, $extraVars = array(), $currency_special = NULL, $dont_touch_amount = false)
 {
     $cart = cart::model()->findByPk(intval($cart_cart));
     if ($cart and !$cart->orderExists()) {
         $order = new order_entity();
         $customer = customer_entity::model()->findByPk($cart->cart_customer_ID);
         $currency = currency::model()->findByPK($cart->cart_currency_ID);
         $order->order_carrier_ID = intval($cart->cart_carrier_ID);
         $order->order_address_ID = intval($cart->cart_address_ID);
         $order->order_cart_ID = intval($cart->cart_ID);
         $order->order_currency_ID = intval($cart->cart_currency_ID);
         $order->order_customer_ID = intval($cart->cart_customer_ID);
         $order->order_salt = $customer->customer_salt;
         $order->order_payment_method = $paymentMethod;
         $amountPaid = !$dont_touch_amount ? round(floatval($amountPaid), 2) : $amountPaid;
         $order->order_total_paid = $amountPaid;
         $order->order_total_discount = product_entity::decoratePrice($cart->getOrderTotal(2));
         $order->order_total_products = product_entity::decoratePrice($cart->getOrderTotal(1));
         $order->order_total_shipping = product_entity::decoratePrice($cart->getOrderShippingCost());
         $order->order_grand = product_entity::decoratePrice($cart->getOrderTotal());
         $order->order_delivery_ID = 0;
         $order->order_payment_date = date('Y-m-d H:i:s');
         $order->order_delivery_date = '0000-00-00 00:00:00';
         if ($order->order_total_paid < $order->order_grand) {
             $order_status = order_entity::PaymentError;
         }
         $order->order_status = $order_status;
         $res = $order->save();
         if ($res and $order->order_ID) {
             //order detail
             foreach ($cart->products as $product) {
                 $quantity = $cart->containProduct($row->product_ID);
                 $orderDetail = new order_detail();
                 $orderDetail->detail_order_ID = $order->order_ID;
                 $orderDetail->detail_product_ID = $product->product_ID;
                 $orderDetail->detail_product_name = $product->product_name;
                 if ($quantity['quantity'] > 1) {
                     $discount_ID = discount_quantity::validateQuantityDiscount($product->product_ID, $quantity['quantity']);
                     if ($discount_ID) {
                         $discountQuantity = discount_quantity::model()->findByPk($discount_ID);
                         $orderDetail->detail_quantity_discount = $currency->convert($product->product_price - $discountQuantity->applyRule($product->product_price));
                         $orderDetail->detail_quantity_discount_applied = 1;
                         $orderDetail->detail_reducetion_percent = 0;
                         $orderDetail->detail_reducetion_amount = 0;
                         $orderDetail->detail_product_price = $currency->convert($product->product_price - $orderDetail->detail_quantity_discount);
                     }
                 } else {
                     if ($product->isReduction()) {
                         if ($product->product_reducetion_percent) {
                             $orderDetail->detail_reducetion_percent = $currency->convert(floatval($product->product_price) * floatval($product->product_reducetion_percent / 100), 2);
                             $orderDetail->detail_reducetion_amount = 0;
                             $orderDetail->detail_quantity_discount = 0;
                             $orderDetail->detail_quantity_discount_applied = 2;
                             $orderDetail->detail_product_price = $currency->convert($product->product_price - $orderDetail->detail_reducetion_percent);
                         } else {
                             $orderDetail->detail_reducetion_amount = $currency->convert($product->product_reducetion_amount);
                             $orderDetail->detail_reducetion_percent = 0;
                             $orderDetail->detail_quantity_discount = 0;
                             $orderDetail->detail_quantity_discount_applied = 2;
                             $orderDetail->detail_product_price = $currency->convert($product->product_price - $orderDetail->detail_reducetion_amount);
                         }
                     } else {
                         $orderDetail->detail_reducetion_amount = 0;
                         $orderDetail->detail_reducetion_percent = 0;
                         $orderDetail->detail_quantity_discount = 0;
                         $orderDetail->detail_quantity_discount_applied = 2;
                         $orderDetail->detail_product_price = $currency->convert($product->product_price);
                     }
                 }
                 $orderDetail->order_weight = floatval($product->product_weight);
                 $orderDetail->save();
                 //update product info
                 if ($order->order_status != order_entity::PaymentError and $order->order_status != order_entity::Canceled) {
                     $product->product_quantity -= $quantity['quantity'];
                     $product->save();
                 }
             }
             //order_discount
             if (sizeof($discounts = cart_discount::items($cart->cart_ID)) >= 1) {
                 foreach ($discounts as $discount) {
                     $orderDiscount = new order_discount();
                     $orderDiscount->order_ID = $order->order_ID;
                     $orderDiscount->discount_ID = $discount['discount_ID'];
                     $orderDiscount->discount_name = $discount['discount_name'];
                     if ($discount['discount_type'] == 3) {
                         $orderDiscount->discount_value = 0;
                     } else {
                         if ($discount['discount_type'] == 2) {
                             $orderDiscount->discount_value = $currency->convert($discount['discount_value']);
                         } else {
                             if ($discounts['discount_type'] == 1) {
                                 $orderDiscount->discount_value = $currency->convert($order->order_total_products * ($discount['discount_value'] / 100));
                             }
                         }
                     }
                 }
             }
             /**
              * To do list
              * 1.Email confirm
              * 2.Product sales
              * 3.Order message
              * 4.order History
              *
              */
         }
     }
 }