/** * @role update */ public function sort() { foreach ($this->request->get($this->request->get('target'), array()) as $position => $key) { $shippingService = ShippingService::getInstanceByID((int) $key); $shippingService->position->set((int) $position); $shippingService->save(); } return new JSONResponse(false, 'success'); }
private function save(Shipment $shipment) { $validator = $this->createShipmentFormValidator(); if ($validator->isValid()) { if ($shippingServiceID = $this->request->get('shippingServiceID')) { $shippingService = ShippingService::getInstanceByID($shippingServiceID); $shipment->shippingService->set($shippingService); $shipment->setAvailableRates($shipment->getDeliveryZone()->getShippingRates($shipment)); $shipment->setRateId($shippingService->getID()); } if ($this->request->get('noStatus')) { $shipment->status->set($shipment->order->get()->status->get()); } else { if ($this->request->get('shippingServiceID') || (int) $this->request->get('status') < 3) { $shipment->status->set((int) $this->request->get('status')); } } $shipment->save(); return new JSONResponse(array('shipment' => array('ID' => $shipment->getID(), 'amount' => $shipment->amount->get(), 'shippingAmount' => $shipment->shippingAmount->get(), 'ShippingService' => array('ID' => $shipment->shippingService->get() ? $shipment->shippingService->get()->getID() : 0), 'taxAmount' => $shipment->taxAmount->get(), 'total' => $shipment->shippingAmount->get() + $shipment->amount->get() + (double) $shipment->taxAmount->get(), 'prefix' => $shipment->getCurrency()->pricePrefix->get(), 'status' => $shipment->status->get(), 'suffix' => $shipment->getCurrency()->priceSuffix->get())), 'success', $this->request->get('noStatus') ? false : $this->translate('_new_shipment_has_been_successfully_created')); } else { return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_error_creating_new_shipment')); } }
public function getShippingService() { if ($this->shippingService->get()) { return $this->shippingService->get(); } else { if ($this->shippingServiceData->get()) { $rate = unserialize($this->shippingServiceData->get()); return ShippingService::getInstanceByID($rate->getServiceID()); } else { return null; } } }