Esempio n. 1
0
 public function execute()
 {
     if ($this->state->get('children', false) && count($this->state->get('children', 0) > 1)) {
         foreach ($this->state->get('children') as $child_id) {
             $cartItemData['child_id'] = $child_id;
             $cartItemData['start_date'] = $this->state->get('startdates.' . $child_id);
             $cartItemData['dates'] = $this->state->get('dates.' . $child_id);
             $cartItemData['product_id'] = $this->state->get('product_id', false);
             $cartApp = Sp4kAppsCartApp::getInstance(new Registry($cartItemData));
             /** @var Registry $cartItem */
             $cartItem = new Registry($cartApp->getItem());
             $cartItems[$cartItem->get('cart_key')] = $cartItem;
         }
     } else {
         $cartApp = Sp4kAppsCartApp::getInstance($this->state);
         $cartItem = $cartApp->getItem();
         $cartItems[$cartItem->cartkey] = $cartItem;
     }
     /** @var JSession $cartSession */
     $cartSession = JFactory::getSession();
     $cartSessionData = $cartSession->get('cart', [], 'Sp4k');
     foreach ($cartItems as $cartKey => $cartItem) {
         $cartSessionData['items'][$cartKey] = $cartItem->toObject();
     }
     //$cartItemData['totals'] = $this->getCartTotals($cart);
     $cartSession->set('cart', $cartSessionData, 'Sp4k');
 }
Esempio n. 2
0
 public function execute()
 {
     $cartSession = JFactory::getSession();
     $cart = ($cart = $cartSession->get('sp4k_cart')) ? $cart : [];
     if (count($cart) > 0) {
         //foreach cart item build the line item for display;
         $cartApp = Sp4kAppsCartApp::getInstance(new Registry($cart));
         $this->items = $cartApp->getItems();
     }
 }
Esempio n. 3
0
 public function execute()
 {
     $cartSession = JFactory::getSession();
     $cart = ($cart = $cartSession->get('sp4k_cart')) ? $cart : [];
     $cartTotal = 0;
     if (count($cart) > 0) {
         //foreach cart item build the line item for display;
         $cartApp = Sp4kAppsCartApp::getInstance(new Registry($cart));
         $cart_items = $cartApp->getItems();
         foreach ($cart_items as $item) {
             $cartTotal += $item->total;
         }
     }
     $orderData = new stdClass();
     $orderData->total = 0;
     $orderData->created = time();
     $orderData->createdby = JFactory::getUser()->id;
     foreach ($cart_items as $type => $cart_item) {
         $orderItem = new stdClass();
         $orderItem->type = $type;
         $orderItem->mainline = $cart_item->mainline;
         $orderItem->sublines = $cart_item->sublines;
         $orderItem->total = $cart_item->total;
         $orderData->total += $orderItem->total;
         $orderData->cart[$type][] = $orderItem;
     }
     $orderData->cart = json_encode($orderData->cart);
     $order = Sp4kAppsOrderApp::getInstance(new Registry($orderData))->getItem()->update();
     $this->state->set('order_id', $order->id);
     $paymentData = new stdClass();
     $paymentData->amount = $cartTotal;
     /** @var Sp4kAppsPaymentItem $payment */
     $payment = Sp4kAppsPaymentApp::getInstance(new Registry($this->state->toObject()))->getItem()->charge();
     if ($this->error = $payment->getError()) {
         $order->status = 0;
     } else {
         $order->status = '1';
         $order->payment_id = $payment->id;
     }
     $order->update();
     return $this;
 }