public function testCreateNewDeliveryZoneCountry()
 {
     $deliveryCountry = DeliveryZoneCountry::getNewInstance($this->zone, 'LT');
     $deliveryCountry->save();
     $deliveryCountry->reload();
     $this->assertEquals($deliveryCountry->deliveryZone->get(), $this->zone);
     $this->assertEquals($deliveryCountry->countryCode->get(), 'LT');
 }
示例#2
0
 /**
  * @role update
  */
 public function saveCountries()
 {
     $zone = DeliveryZone::getInstanceByID((int) $this->getId());
     DeliveryZoneCountry::removeByZone($zone);
     foreach ((array) $this->request->get('active') as $countryCode) {
         $deliveryZoneState = DeliveryZoneCountry::getNewInstance($zone, $countryCode);
         $deliveryZoneState->save();
     }
     return new JSONResponse(false, 'success', $this->translate('_countries_list_was_successfully_updated'));
 }
示例#3
0
 public function testDefaultZoneVATWithAnotherZone()
 {
     TaxRate::getNewInstance(DeliveryZone::getDefaultZoneInstance(), $this->tax, 10)->save();
     TaxRate::getNewInstance($this->deliveryZone, $this->tax, 10)->save();
     DeliveryZoneCountry::getNewInstance($this->deliveryZone, 'US')->save();
     $order = CustomerOrder::getNewInstance($this->user);
     $order->addProduct($this->product, 1, true);
     $order->currency->set($this->currency);
     $order->shippingAddress->set($this->address);
     $order->save();
     $this->assertEqual($order->getTotal($this->currency), 100);
     $order->finalize();
     $this->assertDefaultZoneOrder($order, $this->currency);
     ActiveRecord::clearPool();
     $reloaded = CustomerOrder::getInstanceById($order->getID(), true);
     $this->assertDefaultZoneOrder($reloaded, $this->currency);
 }
示例#4
0
 private function createOrderWithZone(DeliveryZone $zone = null)
 {
     if (is_null($zone)) {
         $zone = DeliveryZone::getNewInstance();
     }
     $zone->name->set('Latvia');
     $zone->isEnabled->set(true);
     $zone->save();
     $this->newZone = $zone;
     $country = DeliveryZoneCountry::getNewInstance($zone, 'LV');
     $country->save();
     $tax = Tax::getNewInstance('VAT');
     $tax->save();
     $taxRate = TaxRate::getNewInstance($zone, $tax, 20);
     $taxRate->save();
     $service = ShippingService::getNewInstance($zone, 'def', ShippingService::SUBTOTAL_BASED);
     $service->save();
     $this->newService = $service;
     $shippingRate = ShippingRate::getNewInstance($service, 0, 10000000);
     $shippingRate->flatCharge->set(100);
     $shippingRate->save();
     $this->newRate = $shippingRate;
     // user address
     $address = UserAddress::getNewInstance();
     $address->countryID->set('LV');
     $billingAddress = BillingAddress::getNewInstance($this->user, $address);
     $billingAddress->save();
     // set up order
     $this->order->user->set($this->user);
     $this->order->billingAddress->set($address);
     $this->order->shippingAddress->set($address);
     $this->order->save();
 }
示例#5
0
 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);
 }
示例#6
0
 /**
  * @return ARSet
  */
 public function getCountries($loadReferencedRecords = false)
 {
     return DeliveryZoneCountry::getRecordSetByZone($this, $loadReferencedRecords);
 }
示例#7
0
 public function testQuebecToUSATaxes()
 {
     $gst = Tax::getNewInstance('GST');
     $gst->save();
     $pst = Tax::getNewInstance('PST');
     $pst->save();
     // shipment delivery zone
     $zone = DeliveryZone::getNewInstance();
     $zone->name->set('Quebec');
     $zone->isEnabled->set(true);
     $zone->save();
     // two taxes are applied to delivery charge
     TaxRate::getNewInstance($zone, $gst, 5)->save();
     TaxRate::getNewInstance($zone, $pst, 7.5)->save();
     $delZone = $zone;
     $this->config->setRuntime('DELIVERY_TAX', $zone->getID());
     // shipping amount zone
     $zone = DeliveryZone::getNewInstance();
     $zone->name->set('Canada');
     $zone->isEnabled->set(true);
     $zone->save();
     $service = ShippingService::getNewInstance($zone, 'def', ShippingService::SUBTOTAL_BASED);
     $service->save();
     DeliveryZoneCountry::getNewInstance($zone, 'US')->save();
     $shippingRate = ShippingRate::getNewInstance($service, 0, 10000000);
     $shippingRate->flatCharge->set(16.95);
     $shippingRate->save();
     $product = $this->products[0];
     $product->setPrice('USD', 50);
     $this->order->addProduct($product, 1, false);
     $this->order->save();
     // set shipping rate
     $shipment = $this->order->getShipments()->get(0);
     $rates = $this->order->getDeliveryZone()->getShippingRates($shipment);
     $shipment->setAvailableRates($rates);
     $shipment->setRateId($rates->get(0)->getServiceID());
     $shipment->save();
     $this->order->finalize();
     $this->assertSame($this->order->getDeliveryZone(), $zone);
     $this->assertEquals($this->order->getTotal(), 69.13);
 }