示例#1
0
 public static function getTotals()
 {
     $subTotal = self::getSubTotal();
     $taxes = StoreTax::getTaxes();
     $addedTaxTotal = 0;
     $includedTaxTotal = 0;
     $taxCalc = Config::get('vividstore.calculation');
     if ($taxes) {
         foreach ($taxes as $tax) {
             if ($taxCalc != 'extract') {
                 $addedTaxTotal += $tax['taxamount'];
             } else {
                 $includedTaxTotal += $tax['taxamount'];
             }
         }
     }
     $shippingTotal = self::getShippingTotal();
     $total = $subTotal + $addedTaxTotal + $shippingTotal;
     return array('subTotal' => $subTotal, 'taxes' => $taxes, 'taxTotal' => $addedTaxTotal + $includedTaxTotal, 'shippingTotal' => $shippingTotal, 'total' => $total);
 }
示例#2
0
 public function getTaxTotal()
 {
     echo json_encode(StoreTax::getTaxes(true));
 }
示例#3
0
 public static function getTotals()
 {
     $subTotal = self::getSubTotal();
     $taxes = StoreTax::getTaxes();
     $addedTaxTotal = 0;
     $includedTaxTotal = 0;
     $taxCalc = Config::get('vividstore.calculation');
     if ($taxes) {
         foreach ($taxes as $tax) {
             if ($taxCalc != 'extract') {
                 $addedTaxTotal += $tax['taxamount'];
             } else {
                 $includedTaxTotal += $tax['taxamount'];
             }
         }
     }
     $shippingTotal = self::getShippingTotal();
     $discountedSubtotal = $subTotal;
     $discounts = StoreCart::getDiscounts();
     foreach ($discounts as $discount) {
         if ($discount->drDeductFrom == 'subtotal') {
             if ($discount->drDeductType == 'value') {
                 $discountedSubtotal -= $discount->drValue;
             }
             if ($discount->drDeductType == 'percentage') {
                 $discountedSubtotal -= $discount->drPercentage / 100 * $discountedSubtotal;
             }
         }
     }
     $total = $discountedSubtotal + $addedTaxTotal + $shippingTotal;
     foreach ($discounts as $discount) {
         if ($discount->drDeductFrom == 'total') {
             if ($discount->drDeductType == 'value') {
                 $total -= $discount->drValue;
             }
             if ($discount->drDeductType == 'percentage') {
                 $total -= $discount->drPercentage / 100 * $total;
             }
         }
     }
     return array('subTotal' => $subTotal, 'taxes' => $taxes, 'taxTotal' => $addedTaxTotal + $includedTaxTotal, 'shippingTotal' => $shippingTotal, 'total' => $total);
 }
示例#4
0
 public function edit_class($tcID)
 {
     $this->set('task', t("Update"));
     $this->set('tc', StoreTaxClass::getByID($tcID));
     $this->set('taxRates', StoreTax::getTaxRates());
 }
示例#5
0
 public function addOrderItems($cart)
 {
     $taxCalc = Config::get('vividstore.calculation');
     foreach ($cart as $cartItem) {
         $taxes = StoreTax::getTaxForProduct($cartItem);
         $taxProductTotal = array();
         $taxProductIncludedTotal = array();
         $taxProductLabels = array();
         foreach ($taxes as $tax) {
             if ($taxCalc == 'extract') {
                 $taxProductIncludedTotal[] = $tax['taxamount'];
             } else {
                 $taxProductTotal[] = $tax['taxamount'];
             }
             $taxProductLabels[] = $tax['name'];
         }
         $taxProductTotal = implode(',', $taxProductTotal);
         $taxProductIncludedTotal = implode(',', $taxProductIncludedTotal);
         $taxProductLabels = implode(',', $taxProductLabels);
         $orderItem = StoreOrderItem::add($cartItem, $this->getOrderID(), $taxProductTotal, $taxProductIncludedTotal, $taxProductLabels);
         $this->orderItems->add($orderItem);
     }
 }
示例#6
0
 public function add($data, $pm, $status = null)
 {
     $db = Database::get();
     //get who ordered it
     $customer = new Customer();
     //what time is it?
     $dt = Core::make('helper/date');
     $now = $dt->getLocalDateTime();
     //get the price details
     $smID = \Session::get('smID');
     if ($smID > 0) {
         $sm = ShippingMethod::getByID($smID);
         $shippingMethodTypeName = $sm->getShippingMethodType()->getShippingMethodTypeName();
         $shippingMethodName = $sm->getName();
         $smName = $shippingMethodTypeName . ": " . $shippingMethodName;
     } else {
         $smName = "No Shipping Method";
     }
     $shipping = VividCart::getShippingTotal();
     $taxes = Tax::getTaxes();
     $totals = VividCart::getTotals();
     $total = $totals['total'];
     $taxCalc = Config::get('vividstore.calculation');
     $taxTotal = array();
     $taxIncludedTotal = array();
     $taxLabels = array();
     foreach ($taxes as $tax) {
         if ($taxCalc == 'extract') {
             $taxIncludedTotal[] = $tax['taxamount'];
         } else {
             $taxTotal[] = $tax['taxamount'];
         }
         $taxLabels[] = $tax['name'];
     }
     $taxTotal = implode(',', $taxTotal);
     $taxIncludedTotal = implode(',', $taxIncludedTotal);
     $taxLabels = implode(',', $taxLabels);
     //get payment method
     $pmName = $pm->getPaymentMethodName();
     //add the order
     $vals = array($customer->getUserID(), $now, $pmName, $smName, $shipping, $taxTotal, $taxIncludedTotal, $taxLabels, $total);
     $db->Execute("INSERT INTO VividStoreOrders(cID,oDate,pmName,smName,oShippingTotal,oTax,oTaxIncluded,oTaxName,oTotal) VALUES (?,?,?,?,?,?,?,?,?)", $vals);
     $oID = $db->lastInsertId();
     $order = Order::getByID($oID);
     if ($status) {
         $order->updateStatus($status);
     } else {
         $order->updateStatus(OrderStatus::getStartingStatus()->getHandle());
     }
     $email = $customer->getEmail();
     $billing_first_name = $customer->getValue("billing_first_name");
     $billing_last_name = $customer->getValue("billing_last_name");
     $billing_address = $customer->getValueArray("billing_address");
     $billing_phone = $customer->getValue("billing_phone");
     $shipping_first_name = $customer->getValue("shipping_first_name");
     $shipping_last_name = $customer->getValue("shipping_last_name");
     $shipping_address = $customer->getValueArray("shipping_address");
     $order->setAttribute("email", $email);
     $order->setAttribute("billing_first_name", $billing_first_name);
     $order->setAttribute("billing_last_name", $billing_last_name);
     $order->setAttribute("billing_address", $billing_address);
     $order->setAttribute("billing_phone", $billing_phone);
     if ($smID) {
         $order->setAttribute("shipping_first_name", $shipping_first_name);
         $order->setAttribute("shipping_last_name", $shipping_last_name);
         $order->setAttribute("shipping_address", $shipping_address);
     }
     $customer->setLastOrderID($oID);
     //add the order items
     $cart = VividCart::getCart();
     foreach ($cart as $cartItem) {
         $taxes = Tax::getTaxForProduct($cartItem);
         $taxProductTotal = array();
         $taxProductIncludedTotal = array();
         $taxProductLabels = array();
         foreach ($taxes as $tax) {
             if ($taxCalc == 'extract') {
                 $taxProductIncludedTotal[] = $tax['taxamount'];
             } else {
                 $taxProductTotal[] = $tax['taxamount'];
             }
             $taxProductLabels[] = $tax['name'];
         }
         $taxProductTotal = implode(',', $taxProductTotal);
         $taxProductIncludedTotal = implode(',', $taxProductIncludedTotal);
         $taxProductLabels = implode(',', $taxProductLabels);
         OrderItem::add($cartItem, $oID, $taxProductTotal, $taxProductIncludedTotal, $taxProductLabels);
     }
     $discounts = VividCart::getDiscounts();
     if ($discounts) {
         foreach ($discounts as $discount) {
             $order->addDiscount($discount, VividCart::getCode());
         }
     }
     //if the payment method is not external, go ahead and complete the order.
     if (!$pm->external) {
         $order->completeOrder();
     }
     return $order;
 }