private function getStates(DeliveryZone $zone, $country)
 {
     $localeInfo = $this->locale->info();
     $allCountries = $countries = $localeInfo->getAllCountries();
     $allStates = array();
     foreach (State::getStatesByCountry($country) as $stateID => $state) {
         $allStates[$stateID] = $localeInfo->getCountryName($country) . ": " . $state;
     }
     $selectedStates = array();
     foreach ($zone->getStates()->toArray() as $state) {
         $selectedStates[$state['State']['ID']] = $localeInfo->getCountryName($state['State']['countryID']) . ": " . $state['State']['name'];
         unset($allStates[$state['State']['ID']]);
     }
     return array('all' => $allStates, 'selected' => $selectedStates);
 }
Exemple #2
0
 public function editAddress()
 {
     $this->loadLanguageFile('backend/CustomerOrder');
     ClassLoader::import('application.controller.backend.CustomerOrderController');
     $shipment = Shipment::getInstanceByID('Shipment', $this->request->get('id'), true, array('CustomerOrder', 'User'));
     if (!$shipment->shippingAddress->get()) {
         $shipment->shippingAddress->set(UserAddress::getNewInstance());
         $shipment->shippingAddress->get()->save();
     }
     $shipment->shippingAddress->get()->load();
     $address = $shipment->shippingAddress->get()->toArray();
     $response = new ActionResponse();
     $controller = new CustomerOrderController($this->application);
     $response->set('form', $controller->createUserAddressForm($address, $response));
     $response->set('countries', $this->application->getEnabledCountries());
     $response->set('states', State::getStatesByCountry($address['countryID']));
     $response->set('shipmentID', $shipment->getID());
     $addressOptions = array('' => '');
     $addresses = array();
     foreach (array_merge($shipment->order->get()->user->get()->getShippingAddressArray(), $shipment->order->get()->user->get()->getBillingAddressArray()) as $address) {
         $addressOptions[$address['ID']] = $address['UserAddress']['compact'];
         $addresses[$address['ID']] = $address;
     }
     $response->set('existingUserAddressOptions', $addressOptions);
     $response->set('existingUserAddresses', $addresses);
     return $response;
 }
Exemple #3
0
 /**
  *  Return a list of states for the selected country
  *  @return JSONResponse
  */
 public function states()
 {
     $states = State::getStatesByCountry($this->request->get('country'));
     return new JSONResponse($states);
 }
Exemple #4
0
 protected function getStateList($country)
 {
     $states = State::getStatesByCountry($country);
     if ($states) {
         $states = array('' => '') + $states;
     }
     return $states;
 }
 public function info()
 {
     $this->loadLanguageFile('backend/Shipment');
     $order = CustomerOrder::getInstanceById((int) $this->request->get('id'), true, array('User', 'Currency'));
     $order->getSpecification();
     $order->loadAll();
     $this->removeEmptyShipments($order);
     $response = new ActionResponse();
     $this->assignStatuses($response);
     $response->set('countries', $this->application->getEnabledCountries());
     $orderArray = $order->toArray();
     if ($order->isFinalized->get()) {
         if ($billingAddress = $order->billingAddress->get()) {
             $billingAddress->load(true);
             $orderArray['BillingAddress'] = $billingAddress->toArray();
         }
         if ($shippingAddress = $order->shippingAddress->get()) {
             $shippingAddress->load(true);
             $orderArray['ShippingAddress'] = $shippingAddress->toArray();
         }
         if ($order->billingAddress->get()) {
             $billingStates = State::getStatesByCountry($order->billingAddress->get()->countryID->get());
             $billingStates[''] = '';
             asort($billingStates);
             $response->set('billingStates', $billingStates);
         }
         if ($order->shippingAddress->get()) {
             $shippingStates = State::getStatesByCountry($order->shippingAddress->get()->countryID->get());
             $shippingStates[''] = '';
             asort($shippingStates);
             $response->set('shippingStates', $shippingStates);
         }
     } elseif ($order->user->get()) {
         $order->user->get()->loadAddresses();
         if (!$order->shippingAddress->get() && $order->user->get()->defaultShippingAddress->get()) {
             $shippingStates = State::getStatesByCountry($order->user->get()->defaultShippingAddress->get()->userAddress->get()->countryID->get());
             $orderArray['ShippingAddress'] = $order->user->get()->defaultShippingAddress->get()->userAddress->get()->toArray();
         }
         $shippingStates[''] = '';
         if (!$order->billingAddress->get() && $order->user->get()->defaultBillingAddress->get()) {
             $billingStates = State::getStatesByCountry($order->user->get()->defaultBillingAddress->get()->userAddress->get()->countryID->get());
             $orderArray['BillingAddress'] = $order->user->get()->defaultBillingAddress->get()->userAddress->get()->toArray();
         }
         $billingStates[''] = '';
         $response->set('shippingStates', $shippingStates);
         $response->set('billingStates', $billingStates);
     }
     $response->set('order', $orderArray);
     $response->set('form', $this->createOrderForm($orderArray));
     $user = $order->user->get();
     $response->setStatusCode(200);
     if ($user) {
         $addressOptions = array('' => '');
         $addressOptions['optgroup_0'] = $this->translate('_billing_addresses');
         $addresses = array();
         foreach ($user->getBillingAddressArray() as $address) {
             $addressOptions[$address['ID']] = $this->createAddressString($address);
             $addresses[$address['ID']] = $address;
         }
         $addressOptions['optgroup_1'] = $this->translate('_shipping_addresses');
         foreach ($user->getShippingAddressArray() as $address) {
             $addressOptions[$address['ID']] = $this->createAddressString($address);
             $addresses[$address['ID']] = $address;
         }
         $response->set('existingUserAddressOptions', $addressOptions);
         $response->set('existingUserAddresses', $addresses);
     }
     foreach (array('ShippingAddress', 'BillingAddress') as $type) {
         $response->set('form' . $type, $this->createUserAddressForm(isset($orderArray[$type]) ? $orderArray[$type] : array(), $response));
     }
     $shipableShipmentsCount = 0;
     $hideShipped = 0;
     $hasDownloadable = false;
     foreach ($order->getShipments() as $shipment) {
         if ($shipment->isShipped()) {
             continue;
         }
         if (!$shipment->isShippable() && count($shipment->getItems()) > 0) {
             continue;
         }
         if ($shipment->status->get() != Shipment::STATUS_SHIPPED && $shipment->isShippable()) {
             $shipableShipmentsCount++;
         }
         $rate = unserialize($shipment->shippingServiceData->get());
         if (count($shipment->getItems()) == 0 || !is_object($rate) && !$shipment->shippingService->get()) {
             $hideShipped = 1;
             break;
         }
     }
     BackendToolbarItem::registerLastViewedOrder($order);
     //		$response->set('hideShipped', $shipableShipmentsCount > 0 ? $hideShipped : 1);
     $response->set('hideShipped', false);
     $response->set('type', $this->getOrderType($order));
     // custom fields
     $form = $this->createFieldsForm($order);
     $order->getSpecification()->setFormResponse($response, $form);
     $response->set('fieldsForm', $form);
     $this->appendCalendarForm($response);
     return $this->shipmentInfo($response);
 }