public function edit() { $this->loadLanguageFile('backend/Product'); $rpp = RecurringProductPeriod::getInstanceByID((int) $this->request->get('id'), ActiveRecord::LOAD_DATA); $rpp = $rpp->toArray(); $form = $this->createForm($rpp); $response = new ActionResponse(); $response->set('recurringProductPeriod', $rpp); $response->set('form', $form); $response->set('periodTypes', array_map(array($this, 'translate'), RecurringProductPeriod::getAllPeriodTypes(RecurringProductPeriod::PERIOD_TYPE_NAME_PLURAL))); $response->set('currencies', $this->application->getCurrencyArray(true)); return $response; }
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(); $recurringItemsByItem = array(); $hasRecurringItem = false; foreach (array('cartItems', 'wishListItems') as $type) { if (!empty($orderArray[$type])) { foreach ($orderArray[$type] as &$item) { $itemsById[$item['ID']] =& $item; if ($item['Product']['type'] == Product::TYPE_RECURRING) { $hasRecurringItem = true; $recurringProductPeriods = RecurringProductPeriod::getRecordSetByProduct($item['Product']['ID'])->toArray(); $recurringItemsByItem[$item['ID']] = $recurringProductPeriods; } } } } if ($hasRecurringItem) { $response->set('periodTypesPlural', RecurringProductPeriod::getAllPeriodTypes(RecurringProductPeriod::PERIOD_TYPE_NAME_PLURAL)); $response->set('periodTypesSingle', RecurringProductPeriod::getAllPeriodTypes(RecurringProductPeriod::PERIOD_TYPE_NAME_SINGLE)); $response->set('recurringItemsByItem', $recurringItemsByItem); } $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; }
/** * @role login */ public function viewOrder() { $id = $this->request->get('id'); if ($order = $this->user->getOrder($id)) { $this->addAccountBreadcrumb(); $this->addBreadCrumb($this->translate('_your_orders'), $this->router->createUrl(array('controller' => 'user', 'action' => 'orders'), true)); $this->addBreadCrumb($order->invoiceNumber->get(), ''); // mark all notes as read $notes = $order->getNotes(); foreach ($notes as $note) { if (!$note->isRead->get() && $note->isAdmin->get()) { $note->isRead->set(true); $note->save(); } } $response = null; $orderArray = $order->toArray(); if ($order->isRecurring->get() == true) { // find invoices $page = $this->request->get('page', 1); $perPage = $this->getOrdersPerPage(); $f = $this->getOrderListPaginateFilter($page, $perPage); $f->mergeCondition(new AndChainCondition(array(new EqualsCond(new ARFieldHandle('CustomerOrder', 'parentID'), $order->getID()), new EqualsCond(new ARFieldHandle('CustomerOrder', 'isRecurring'), 1)))); $f->setOrder(new ARFieldHandle('CustomerOrder', 'dateDue')); $response = $this->getOrdersListResponse($this->loadOrders($f), $page, $perPage); $recurringProductPeriods = array(); foreach ($order->getShipments() as $shipment) { foreach ($shipment->getItems() as $orderedItem) { $recurringProductPeriods[$orderedItem->getID()] = RecurringItem::getInstanceByOrderedItem($orderedItem)->toArray(); } } ClassLoader::import('application.model.product.RecurringProductPeriod'); ClassLoader::import('application.model.product.RecurringItem'); $response->set('nextRebillDate', $order->getNextRebillDate()); $response->set('periodTypesPlural', RecurringProductPeriod::getAllPeriodTypes(RecurringProductPeriod::PERIOD_TYPE_NAME_PLURAL)); $response->set('periodTypesSingle', RecurringProductPeriod::getAllPeriodTypes(RecurringProductPeriod::PERIOD_TYPE_NAME_SINGLE)); $response->set('recurringProductPeriodsByItemId', $recurringProductPeriods); $this->loadLanguageFile('Product'); } if (!$response) { $response = new ActionResponse(); } $response->set('subscriptionStatus', $order->getSubscriptionStatus()); $response->set('canCancelRebills', $order->canUserCancelRebills()); $response->set('order', $orderArray); $response->set('notes', $notes->toArray()); $response->set('user', $this->user->toArray()); $response->set('noteForm', $this->buildNoteForm()); return $response; } else { return new ActionRedirectResponse('user', 'index'); } }
/** * 4. Select shipping methods * @role login */ public function shipping() { $shipments = $this->order->getShipments(); $this->restoreShippingMethodSelection(); if ($redirect = $this->validateOrder($this->order, self::STEP_SHIPPING)) { return $redirect; } if (!$this->order->isShippingRequired()) { return new ActionRedirectResponse('checkout', 'pay'); } foreach ($shipments as $shipment) { if (count($shipment->getItems()) == 0) { $shipment->delete(); $shipments->removeRecord($shipment); } } $form = $this->buildShippingForm($shipments); $needSelecting = null; foreach ($shipments as $key => $shipment) { if (!$shipment->isShippable()) { $download = $shipment; $downloadIndex = $key; $needSelecting = false; continue; } $shipmentRates = $shipment->getAvailableRates(); if ($shipmentRates->size() > 1) { $needSelecting = true; } else { if (!$shipmentRates->size()) { $validator = $this->buildAddressSelectorValidator($this->order, 'shipping'); $validator->triggerError('selectedAddress', $this->translate('_err_no_rates_for_address')); $validator->saveState(); return new ActionRedirectResponse('checkout', 'selectAddress'); } else { $shipment->setRateId($shipmentRates->get(0)->getServiceId()); if ($this->order->isMultiAddress->get()) { $shipment->save(); } } } $rates[$key] = $shipmentRates; if ($shipment->getSelectedRate()) { $form->set('shipping_' . $key, $shipment->getSelectedRate()->getServiceID()); } } SessionOrder::save($this->order); // only one shipping method for each shipment, so we pre-select it automatically if (is_null($needSelecting) && $this->config->get('SKIP_SHIPPING') && $this->config->get('CHECKOUT_CUSTOM_FIELDS') != 'SHIPPING_METHOD_STEP') { $this->order->serializeShipments(); SessionOrder::save($this->order); return new ActionRedirectResponse('checkout', 'pay'); } $rateArray = array(); foreach ((array) $rates as $key => $rate) { $rateArray[$key] = $rate->toArray(); } $response = new ActionResponse(); $shipmentArray = $shipments->toArray(); if (isset($download)) { $response->set('download', $download->toArray()); unset($shipmentArray[$downloadIndex]); } $locale = self::getApplication()->getLocale(); foreach ($rateArray as &$rates) { foreach ($rates as $k => &$item) { if (!empty($item['ShippingService']['deliveryTimeMinDays'])) { $item['ShippingService']['formatted_deliveryTimeMinDays'] = $locale->getFormattedTime(strtotime('+' . $item['ShippingService']['deliveryTimeMinDays'] . ' days')); } if (!empty($item['ShippingService']['deliveryTimeMaxDays'])) { $item['ShippingService']['formatted_deliveryTimeMaxDays'] = $locale->getFormattedTime(strtotime('+' . $item['ShippingService']['deliveryTimeMaxDays'] . ' days')); } } } unset($item); $recurringIDs = array(); $recurringPlans = array(); foreach ($shipmentArray as $item) { foreach ($item['Order']['cartItems'] as $orderedItem) { if (isset($orderedItem['recurringID'])) { $recurringIDs[] = $orderedItem['recurringID']; } } } if (count($recurringIDs)) { $this->loadLanguageFile('Product'); // contains translations for recurring product pricing. ClassLoader::import('application.model.product.RecurringProductPeriod'); $recurringPlans = RecurringProductPeriod::getRecordSetArrayByIDs($recurringIDs); $response->set('periodTypesPlural', RecurringProductPeriod::getAllPeriodTypes(RecurringProductPeriod::PERIOD_TYPE_NAME_PLURAL)); $response->set('periodTypesSingle', RecurringProductPeriod::getAllPeriodTypes(RecurringProductPeriod::PERIOD_TYPE_NAME_SINGLE)); } $response->set('shipments', $shipmentArray); $response->set('rates', $rateArray); $response->set('recurringPlans', $recurringPlans); $response->set('currency', $this->getRequestCurrency()); $response->set('form', $form); $response->set('order', $this->order->toArray()); $this->order->getSpecification()->setFormResponse($response, $form); $this->order->setCheckoutStep(CustomerOrder::CHECKOUT_ADDRESS); return $response; }
public function recurringBlock() { $response = new BlockResponse(); if ($this->product->type->get() == Product::TYPE_RECURRING) { ClassLoader::import('application.model.product.RecurringProductPeriod'); ClassLoader::import('application.model.product.RecurringItem'); $response->set('isRecurring', true); $response->set('periodTypesPlural', RecurringProductPeriod::getAllPeriodTypes(RecurringProductPeriod::PERIOD_TYPE_NAME_PLURAL)); $response->set('periodTypesSingle', RecurringProductPeriod::getAllPeriodTypes(RecurringProductPeriod::PERIOD_TYPE_NAME_SINGLE)); $response->set('recurringProductPeriods', RecurringProductPeriod::getRecordSetByProduct($this->product)->toArray()); } return $response; }