public function getFields() { $this->loadLanguageFile('backend/CustomerOrder'); $this->loadLanguageFile('backend/Shipment'); $this->loadLanguageFile('backend/Product'); $controller = new CustomerOrderController($this->application); foreach ($controller->getAvailableColumns() as $key => $data) { $fields[$key] = $this->translate($data['name']); } unset($fields['CustomerOrder.taxAmount']); unset($fields['CustomerOrder.dateCreated']); unset($fields['User.fullName']); // Billing address foreach (array('BillingAddress.firstName', 'BillingAddress.lastName', 'BillingAddress.countryID', 'BillingAddress.stateName', 'BillingAddress.city', 'BillingAddress.address1', 'BillingAddress.postalCode', 'BillingAddress.phone') as $field) { $fields[$field] = $this->translate('ShippingAddress.' . array_pop(explode('.', $field))); } $fields['OrderedItem.sku'] = $this->translate('Product.sku'); $fields['OrderedItem.count'] = $this->translate('OrderedItem.count'); $fields['OrderedItem.price'] = $this->translate('OrderedItem.price'); $fields['OrderedItem.shipment'] = $this->translate('OrderedItem.shipment'); $fields['OrderedItem.products'] = $this->translate('OrderedItem.products'); $groupedFields = array(); foreach ($fields as $field => $fieldName) { list($class, $field) = explode('.', $field, 2); $groupedFields[$class][$class . '.' . $field] = $fieldName; } return $groupedFields; }
public function saveAddress() { $this->loadLanguageFile('backend/Shipment'); ClassLoader::import('application.controller.backend.CustomerOrderController'); $shipment = Shipment::getInstanceByID('Shipment', $this->request->get('id'), true, array('CustomerOrder', 'User')); $address = $shipment->shippingAddress->get(); if (!$address) { $address = UserAddress::getNewInstance(); $address->save(); $shipment->shippingAddress->set($address); $shipment->save(); } else { $address->load(); } $controller = new CustomerOrderController($this->application); $validator = $controller->createUserAddressFormValidator(); if ($validator->isValid()) { $address->loadRequestData($this->request); $address->save(); return new JSONResponse($shipment->shippingAddress->get()->toArray(), 'success', $this->translate('_shipment_address_changed')); } else { return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure'); } }