public function testAddress() { $address = UserAddress::getNewInstance(); $address->loadRequestData($this->request); $zone = DeliveryZone::getZoneByAddress($address, $this->request->get('type')); return new JSONResponse($zone->toArray()); }
public function getDeliveryZone() { $address = $this->getShippingAddress(); $addressID = $address ? $address->getID() : 0; if (!isset($this->deliveryZones[$addressID])) { if ($address) { $this->deliveryZones[$addressID] = DeliveryZone::getZoneByAddress($address, DeliveryZone::SHIPPING_RATES); } else { $this->deliveryZones[$addressID] = DeliveryZone::getDefaultZoneInstance(); } $this->event('getDeliveryZone'); } return $this->deliveryZones[$addressID]; }
public function getDeliveryZone($forceReset = false) { ClassLoader::import("application.model.delivery.DeliveryZone"); if (!$this->deliveryZone || $forceReset) { if ($this->isShippingRequired() && $this->shippingAddress->get()) { $this->deliveryZone = DeliveryZone::getZoneByAddress($this->shippingAddress->get(), DeliveryZone::SHIPPING_RATES); } else { $this->deliveryZone = DeliveryZone::getDefaultZoneInstance(); } } return $this->deliveryZone; }
public function testFindZoneWithMasks() { $zone1 = DeliveryZone::getNewInstance(); $zone1->name->set('With ZIP'); $zone1->isEnabled->set(true); $zone1->save(); DeliveryZoneZipMask::getNewInstance($zone1, 'asd')->save(); DeliveryZoneCountry::getNewInstance($zone1, 'LT')->save(); $zone2 = DeliveryZone::getNewInstance(); $zone2->name->set('Without ZIP'); $zone2->isEnabled->set(true); $zone2->save(); DeliveryZoneCountry::getNewInstance($zone2, 'LT')->save(); $address = UserAddress::getNewInstance(); $address->countryID->set('LT'); $this->assertSame(DeliveryZone::getZoneByAddress($address), $zone2); $address->postalCode->set('asd'); $this->assertSame(DeliveryZone::getZoneByAddress($address), $zone1); }