예제 #1
0
 public function add_method()
 {
     $data = $this->post();
     $errors = $this->validate($data);
     $this->error = null;
     //clear errors
     $this->error = $errors;
     if (!$errors->has()) {
         if ($this->post('shippingMethodID')) {
             //update
             $shippingMethod = ShippingMethod::getByID($this->post('shippingMethodID'));
             $shippingMethodTypeMethod = $shippingMethod->getShippingMethodTypeMethod();
             $shippingMethodTypeMethod->update($this->post());
             $shippingMethod->update($this->post('methodName'), $this->post('methodEnabled'));
             $this->redirect('/dashboard/store/settings/shipping/updated');
         } else {
             //first we send the data to the shipping method type.
             $shippingMethodType = ShippingMethodType::getByID($this->post('shippingMethodTypeID'));
             $shippingMethodTypeMethod = $shippingMethodType->addMethod($this->post());
             //make a shipping method that correlates with it.
             ShippingMethod::add($shippingMethodTypeMethod, $shippingMethodType, $this->post('methodName'), true);
             $this->redirect('/dashboard/store/settings/shipping/success');
         }
     } else {
         $this->add($this->post('shippingMethodTypeID'));
         //$smt = ShippingMethodType::getByID($this->post('shippingMethodTypeID'));
         //$this->set('smt',$smt);
     }
 }
예제 #2
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;
 }
예제 #3
0
 public function getShippingTotal($smID = null)
 {
     if ($smID) {
         $shippingMethod = ShippingMethod::getByID($smID);
         Session::set('smID', $smID);
     } else {
         $sessionShippingMethodID = Session::get('smID');
         if (!empty($sessionShippingMethodID)) {
             $shippingMethod = ShippingMethod::getByID($sessionShippingMethodID);
         }
     }
     if (is_object($shippingMethod)) {
         $shippingTotal = $shippingMethod->getShippingMethodTypeMethod()->getRate();
         $discounts = self::getDiscounts();
         foreach ($discounts as $discount) {
             if ($discount->drDeductFrom == 'shipping') {
                 if ($discount->drDeductType == 'value') {
                     $shippingTotal -= $discount->drValue;
                 }
                 if ($discount->drDeductType == 'percentage') {
                     $shippingTotal -= $discount->drPercentage / 100 * $shippingTotal;
                 }
             }
         }
     }
     return $shippingTotal;
 }