private function getCartPageResponse() { $this->addBreadCrumb($this->translate('_my_session'), $this->router->createUrlFromRoute($this->request->get('return'), true)); $this->order->setUser($this->user); $this->order->loadItemData(); $response = new ActionResponse(); if ($result = $this->order->updateToStock()) { $response->set('changes', $result); } $options = $this->getItemOptions(); $currency = Currency::getValidInstanceByID($this->request->get('currency', $this->application->getDefaultCurrencyCode()), Currency::LOAD_DATA); $form = $this->buildCartForm($this->order, $options); if ($this->isTosInCartPage()) { $form->set('tos', $this->session->get('tos')); } if ($this->config->get('ENABLE_SHIPPING_ESTIMATE')) { $this->loadLanguageFile('User'); if ($this->estimateShippingCost()) { //$this->order->getTotal(true); $response->set('isShippingEstimated', true); } $address = $this->order->shippingAddress->get(); foreach (array('countryID' => 'country', 'stateName' => 'state_text', 'postalCode' => 'postalCode', 'city' => 'city') as $addressKey => $formKey) { $form->set('estimate_' . $formKey, $address->{$addressKey}->get()); } if ($address->state->get() && $address->state->get()->getID()) { $form->set('estimate_state_select', $address->state->get()->getID()); } $response->set('countries', $this->getCountryList($form)); $response->set('states', $this->getStateList($form->get('estimate_country'))); $hideConf = (array) $this->config->get('SHIP_ESTIMATE_HIDE_ENTRY'); $hideForm = !empty($hideConf['UNREGISTERED']) && $this->user->isAnonymous() || !empty($hideConf['ALL_REGISTERED']) && !$this->user->isAnonymous() || !empty($hideConf['REGISTERED_WITH_ADDRESS']) && !$this->user->isAnonymous() && !$this->user->defaultBillingAddress->get() || !$this->order->isShippingRequired() || $this->order->isMultiAddress->get(); $response->set('hideShippingEstimationForm', $hideForm); } $orderArray = $this->order->toArray(); $itemsById = array(); foreach (array('cartItems', 'wishListItems') as $type) { if (!empty($orderArray[$type])) { foreach ($orderArray[$type] as &$item) { $itemsById[$item['ID']] =& $item; } } } $response->set('cart', $orderArray); $response->set('itemsById', $itemsById); $response->set('form', $form); $response->set('return', $this->request->get('return')); $response->set('currency', $currency->getID()); $response->set('options', $options['visible']); $response->set('moreOptions', $options['more']); $response->set('orderTotal', $currency->getFormattedPrice($this->order->getTotal())); $response->set('expressMethods', $this->application->getExpressPaymentHandlerList(true)); $response->set('isCouponCodes', DiscountCondition::isCouponCodes()); $response->set('isOnePageCheckout', $this->config->get('CHECKOUT_METHOD') == 'CHECKOUT_ONEPAGE' && !$this->order->isMultiAddress->get() && !$this->session->get('noJS')); $this->order->getSpecification()->setFormResponse($response, $form); SessionOrder::getOrder()->getShoppingCartItems(); return $response; }
/** * Determines if the necessary steps have been completed, so the order could be finalized * * @return RedirectResponse * @return ActionRedirectResponse * @return false */ protected function validateOrder(CustomerOrder $order, $step = 0) { if ($order->isFinalized->get()) { return false; } // no items in shopping cart if (!count($order->getShoppingCartItems())) { if ($this->request->isValueSet('return')) { return new RedirectResponse($this->router->createUrlFromRoute($this->request->get('return'))); } else { return new ActionRedirectResponse('index', 'index'); } } // order is not orderable (too few/many items, etc.) $isOrderable = $order->isOrderable(true, false); if (!$isOrderable || $isOrderable instanceof OrderException) { return new ActionRedirectResponse('order', 'index'); } $valStep = $this->config->get('CHECKOUT_CUSTOM_FIELDS'); $validateFields = 'CART_PAGE' == $valStep || 'BILLING_ADDRESS_STEP' == $valStep && self::STEP_ADDRESS <= $step || 'SHIPPING_ADDRESS_STEP' == $valStep && (self::STEP_ADDRESS == $step && 'shipping' == $this->request->get('step') || self::STEP_ADDRESS < $step) || 'SHIPPING_METHOD_STEP' == $valStep && self::STEP_SHIPPING < $step; $isOrderable = $order->isOrderable(true, $validateFields); // custom fields selected in cart page? if ('CART_PAGE' == $valStep && !$isOrderable) { return new ActionRedirectResponse('order', 'index'); } // shipping address selected if ($step >= self::STEP_SHIPPING) { if (!$order->shippingAddress->get() && $order->isShippingRequired() && !$order->isMultiAddress->get() || !$order->billingAddress->get() || !$isOrderable) { return new ActionRedirectResponse('checkout', 'selectAddress', $this->request->get('step') ? array('step' => $this->request->get('step')) : null); } } // shipping method selected if ($step >= self::STEP_PAYMENT && $order->isShippingRequired() || !$isOrderable) { foreach ($order->getShipments() as $shipment) { if (!$shipment->getSelectedRate() && $shipment->isShippable()) { return new ActionRedirectResponse('checkout', 'shipping'); } } } return false; }
protected function getCheckoutSteps(CustomerOrder $order) { $steps = array(1 => 'shippingAddress'); if ($order->isShippingRequired()) { $steps[] = 'shippingMethod'; } if ($this->isShippingRequired($order)) { $steps[] = 'billingAddress'; } $steps[] = 'payment'; return array_flip($steps); }
private function getShippingRates(CustomerOrder $order, $addresses) { if (!$order->isShippingRequired()) { return array(); } $shipment = $order->getShipments()->get(0); $rates = array(); foreach ($addresses as $id => $address) { $order->shippingAddress->set($address); $tax = $order->getTaxAmount(); $rates[$id] = $shipment->getShippingRates()->toArray(); foreach ($rates[$id] as &$rate) { $rate['orderTax'] = $tax; } } $order->shippingAddress->set(null); return $rates; }