Exemple #1
0
 public function setUp()
 {
     parent::setUp();
     $this->deliveryZone = DeliveryZone::getNewInstance();
     $this->deliveryZone->name->set('test zone');
     $this->deliveryZone->save();
     $this->shippingService = ShippingService::getNewInstance($this->deliveryZone, 'test category', ShippingService::SUBTOTAL_BASED);
     $this->shippingService->save();
 }
 private function save(ShippingService $shippingService)
 {
     $ratesData = $this->getRatesFromRequest();
     $rates = array();
     if (!($errors = $this->isNotValid($this->request->get('name'), $ratesData))) {
         $shippingService->loadRequestData($this->request);
         $shippingService->setValueArrayByLang(array('name'), $this->application->getDefaultLanguageCode(), $this->application->getLanguageArray(true, false), $this->request);
         $shippingService->isFinal->set($this->request->get('isFinal'));
         $shippingService->setValueArrayByLang(array('description'), $this->application->getDefaultLanguageCode(), $this->application->getLanguageArray(true, false), $this->request);
         $shippingService->deliveryTimeMinDays->set($this->request->get('deliveryTimeMinDays'));
         $shippingService->deliveryTimeMaxDays->set($this->request->get('deliveryTimeMaxDays'));
         $shippingService->save();
         $shippingService->deleteShippingRates();
         $shippingServiceArray = $shippingService->toArray();
         $shippingServiceArray['newRates'] = array();
         foreach ($ratesData as $id => $data) {
             if (!$id) {
                 continue;
             }
             if ($shippingService->rangeType->get() == ShippingService::WEIGHT_BASED) {
                 $rangeStart = $data['weightRangeStart'];
                 $rangeEnd = $data['weightRangeEnd'];
             } else {
                 if ($shippingService->rangeType->get() == ShippingService::SUBTOTAL_BASED) {
                     $rangeStart = $data['subtotalRangeStart'];
                     $rangeEnd = $data['subtotalRangeEnd'];
                 }
             }
             $rate = ShippingRate::getNewInstance($shippingService, $rangeStart, $rangeEnd);
             foreach ($data as $var => $value) {
                 $rate->{$var}->set($value);
             }
             $rate->save();
             $shippingServiceArray['newRates'][$id] = $rate->getID();
         }
         return new JSONResponse(array('service' => $shippingServiceArray), 'success');
     } else {
         return new JSONResponse(array('errors' => $errors), 'failure', $this->translate('_could_note_save_shipping_service'));
     }
 }