Esempio n. 1
0
 public function testGetAllTaxes()
 {
     $allTaxesCount = Tax::getTaxes()->getTotalRecordCount();
     $taxEnabled = Tax::getNewInstance('testing');
     $taxEnabled->save();
     $taxDisabled = Tax::getNewInstance('testing');
     $taxDisabled->save();
     $this->assertEqual(Tax::getTaxes()->getTotalRecordCount(), $allTaxesCount + 2);
 }
Esempio n. 2
0
 /**
  * @role create
  */
 public function create()
 {
     $tax = Tax::getNewInstance($this->request->get('name'));
     $tax->position->set(1000);
     return $this->saveTax($tax);
 }
Esempio n. 3
0
 public function testTaxClassesWithDefaultZoneAndMultipleTaxes()
 {
     $order = CustomerOrder::getNewInstance($this->user);
     $zone = $order->getDeliveryZone();
     $this->assertTrue($zone->isDefault());
     // default tax level
     TaxRate::getNewInstance($zone, $this->tax, 10)->save();
     $newTax = Tax::getNewInstance('test');
     $newTax->save();
     // diferent tax rate for books
     $books = TaxClass::getNewInstance('Books');
     $books->save();
     $booksRate = TaxRate::getNewInstance($zone, $this->tax, 5);
     $booksRate->taxClass->set($books);
     $booksRate->save();
     $booksRate = TaxRate::getNewInstance($zone, $newTax, 20);
     $booksRate->taxClass->set($books);
     $booksRate->save();
     // price = 100
     $cd = $this->product;
     $book = Product::getNewInstance(Category::getRootNode());
     $book->setPrice('USD', 50);
     $book->isEnabled->set(true);
     $book->taxClass->set($books);
     $book->save();
     $order->addProduct($cd, 1, true);
     $order->addProduct($book, 1, true);
     $order->currency->set($this->currency);
     $order->save();
     $this->assertEqual($order->getTaxAmount(), 19.41);
     $this->assertEqual($order->getTotal(true), 150);
     $service = ShippingService::getNewInstance($order->getDeliveryZone(), 'def', ShippingService::SUBTOTAL_BASED);
     $service->save();
     $shippingRate = ShippingRate::getNewInstance($service, 0, 10000000);
     $shippingRate->flatCharge->set(100);
     $shippingRate->save();
     $shipment = $order->getShipments()->get(0);
     $rates = $order->getDeliveryZone()->getShippingRates($shipment);
     $shipment->setAvailableRates($rates);
     $shipment->setRateId($rates->get(0)->getServiceID());
     $shipment->save();
     $this->assertEqual($order->getTotal(true), 250);
     $this->assertEqual((string) $order->getTaxAmount(), (string) 28.5);
 }
Esempio n. 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();
 }
Esempio n. 5
0
 public function testGetTaxRates()
 {
     $zone = DeliveryZone::getNewInstance();
     $zone->name->set(':TEST_ZONE');
     $zone->save();
     $tax = Tax::getNewInstance('VAT');
     $tax->save();
     $taxRate = TaxRate::getNewInstance($zone, $tax, 15);
     $taxRate->save();
     $taxRates = $zone->getTaxRates();
     $this->assertEquals($taxRates->getTotalRecordCount(), 1);
     $this->assertTrue($taxRates->get(0) === $taxRate);
 }
Esempio n. 6
0
 public function testTaxRounding()
 {
     $tax = Tax::getNewInstance('VAT');
     $tax->save();
     TaxRate::getNewInstance(DeliveryZone::getDefaultZoneInstance(), $tax, 19)->save();
     foreach (array(2 => true, 1 => false) as $shipments => $isSeparate) {
         $this->initOrder();
         foreach (array(635.99, 228.69, 61.59) as $key => $price) {
             $this->products[$key]->setPrice('USD', $price);
             if (!$isSeparate) {
                 $this->products[$key]->isSeparateShipment->set(false);
             }
             $this->order->addProduct($this->products[$key], 1, false);
         }
         $this->order->save();
         $this->assertEquals(count($this->order->getShipments()), $shipments);
         $this->assertEquals($this->order->getTotal(), 926.27);
     }
 }