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();
 }
 public function testGetServiceRates()
 {
     $service = ShippingService::getNewInstance($this->deliveryZone, 'Test service 1', ShippingService::SUBTOTAL_BASED);
     $service->save();
     $rate1 = ShippingRate::getNewInstance($service, 1.1, 1.2);
     $rate1->save();
     $rate2 = ShippingRate::getNewInstance($service, 1.3, 1.4);
     $rate2->save();
     $rates = $service->getRates();
     $this->assertTrue($rate1 === $rates->get(0));
     $this->assertTrue($rate2 === $rates->get(1));
 }
 /**
  * @role update
  */
 public function create()
 {
     if (($deliveryZoneId = (int) $this->request->get('deliveryZoneID')) > 0) {
         $deliveryZone = DeliveryZone::getInstanceByID($deliveryZoneId, true);
     } else {
         $deliveryZone = null;
     }
     $shippingService = ShippingService::getNewInstance($deliveryZone, $this->request->get('name'), $this->request->get('rangeType'));
     return $this->save($shippingService);
 }
 public function setConfig()
 {
     if (!$this->buildConfigValidator()->isValid()) {
         return new ActionRedirectResponse('install', 'config');
     }
     Language::deleteCache();
     // site name
     $this->config->setValueByLang('STORE_NAME', $this->request->get('language'), $this->request->get('name'));
     $this->config->save();
     ClassLoader::import('application.model.Currency');
     // create currency
     if (ActiveRecord::objectExists('Currency', $this->request->get('curr'))) {
         $currency = Currency::getInstanceByID($this->request->get('curr'), Currency::LOAD_DATA);
     } else {
         $currency = ActiveRecord::getNewInstance('Currency');
         $currency->setID($this->request->get('curr'));
         $currency->isEnabled->set(true);
         $currency->isDefault->set(true);
         $currency->save(ActiveRecord::PERFORM_INSERT);
     }
     ClassLoader::import('application.model.system.Language');
     // create language
     if (ActiveRecord::objectExists('Language', $this->request->get('language'))) {
         $language = Language::getInstanceByID($this->request->get('language'), Language::LOAD_DATA);
     } else {
         $language = ActiveRecord::getNewInstance('Language');
         $language->setID($this->request->get('language'));
         $language->save(ActiveRecord::PERFORM_INSERT);
         $language->isEnabled->set(true);
         $language->isDefault->set(true);
         $language->save();
     }
     // set root category name to "LiveCart"
     ClassLoader::import('application.model.category.Category');
     $root = Category::getInstanceById(Category::ROOT_ID, Category::LOAD_DATA);
     $root->setValueByLang('name', $language->getID(), 'LiveCart');
     $root->save();
     // create a default shipping service
     ClassLoader::import('application.model.delivery.DeliveryZone');
     ClassLoader::import('application.model.delivery.ShippingService');
     ClassLoader::import('application.model.delivery.ShippingRate');
     $service = ShippingService::getNewInstance(DeliveryZone::getDefaultZoneInstance(), 'Default Service', ShippingService::SUBTOTAL_BASED);
     $service->save();
     $rate = ShippingRate::getNewInstance($service, 0, 100000);
     $rate->flatCharge->set(10);
     $rate->save();
     // create a couple of blank static pages
     ClassLoader::import('application.model.staticpage.StaticPage');
     $page = StaticPage::getNewInstance();
     $page->setValueByLang('title', $language->getID(), 'Contact Info');
     $page->setValueByLang('text', $language->getID(), 'Enter your contact information here');
     $page->menu->set(array('INFORMATION' => true));
     $page->save();
     $page = StaticPage::getNewInstance();
     $page->setValueByLang('title', $language->getID(), 'Shipping Policy');
     $page->setValueByLang('text', $language->getID(), 'Enter your shipping rate & policy information here');
     $page->menu->set(array('INFORMATION' => true));
     $page->save();
     // create an example site news post
     ClassLoader::import('application.model.sitenews.NewsPost');
     $news = ActiveRecordModel::getNewInstance('NewsPost');
     $news->setValueByLang('title', $language->getID(), 'Our store is open');
     $news->setValueByLang('text', $language->getID(), 'Powered by LiveCart software, we have gone live! Of course, we will have to go to <a href="../backend">the backend area</a> and add some categories and products first...');
     $news->setValueByLang('moreText', $language->getID(), 'Do not forget to delete this post when you actually go live :)');
     $news->isEnabled->set(true);
     $news->save();
     return new ActionRedirectResponse('install', 'finish');
 }
Exemple #5
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);
 }
Exemple #6
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();
 }
Exemple #7
0
 public function testGetZoneServices()
 {
     $zone = DeliveryZone::getNewInstance();
     $zone->name->set(':TEST_ZONE');
     $zone->save();
     $service1 = ShippingService::getNewInstance($zone, 'Test service 1', ShippingService::SUBTOTAL_BASED);
     $service1->save();
     $service2 = ShippingService::getNewInstance($zone, 'Test service 2', ShippingService::SUBTOTAL_BASED);
     $service2->save();
     $services = $zone->getShippingServices();
     $this->assertTrue($service1 === $services->get(0));
     $this->assertTrue($service2 === $services->get(1));
 }
Exemple #8
0
 /**
  *  Returns manually defined shipping rates for the particular shipment
  *
  *	@return ShippingRateSet
  */
 public function getDefinedShippingRates(Shipment $shipment)
 {
     $rates = new ShippingRateSet();
     foreach ($this->getShippingServices() as $service) {
         $rate = $service->getDeliveryRate($shipment);
         if ($rate) {
             $rates->add($rate);
         }
     }
     if (!$shipment->getChargeableItemCount($this)) {
         $app = self::getApplication();
         if ($app->getConfig()->get('FREE_SHIPPING_AUTO_RATE')) {
             $freeService = ShippingService::getNewInstance($this, $app->translate('_free_shipping'), ShippingService::WEIGHT_BASED);
             $freeRate = ShipmentDeliveryRate::getNewInstance($freeService, 0);
             $freeRate->setServiceID('FREE');
             $rates->add($freeRate);
         }
     }
     return $rates;
 }
Exemple #9
0
 public function testNetherlandsTax()
 {
     $tax = Tax::getNewInstance('VAT');
     $tax->save();
     // shipment delivery zone
     $zone = DeliveryZone::getDefaultZoneInstance();
     $taxRate = TaxRate::getNewInstance($zone, $tax, 21);
     $taxRate->save();
     $service = ShippingService::getNewInstance($zone, 'def', ShippingService::SUBTOTAL_BASED);
     $service->save();
     $shippingRate = ShippingRate::getNewInstance($service, 0, 10000000);
     $shippingRate->flatCharge->set(6);
     $shippingRate->save();
     $product = $this->products[0];
     $product->setPrice('USD', 24.7);
     $product->save();
     $this->order->addProduct($product, 4, 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->assertEquals($this->order->getTotal(), 104.8);
 }
 protected function getInstance($record, CsvImportProfile $profile)
 {
     $fields = $profile->getSortedFields();
     // get delivery zone
     if (isset($fields['DeliveryZone']['ID'])) {
         try {
             $zone = DeliveryZone::getInstanceByID($record[$fields['DeliveryZone']['ID']], true);
         } catch (ARNotFoundException $e) {
             $zone = DeliveryZone::getDefaultZoneInstance();
         }
     } else {
         $zone = DeliveryZone::getDefaultZoneInstance();
     }
     // get shipping service
     $f = select(new EqualsCond(MultiLingualObject::getLangSearchHandle(new ARFieldHandle('ShippingService', 'name'), $this->application->getDefaultLanguageCode()), $record[$fields['ShippingService']['name']]));
     if ($zone->isDefault()) {
         $f->mergeCondition(new IsNullCond(f('ShippingService.deliveryZoneID')));
     } else {
         $f->mergeCondition(eq(f('ShippingService.deliveryZoneID'), $zone->getID()));
     }
     $services = ActiveRecordModel::getRecordSet('ShippingService', $f);
     if ($services->get(0)) {
         $service = $services->get(0);
         // temporary
         $service->deleteRelatedRecordSet('ShippingRate');
     } else {
         $service = ShippingService::getNewInstance($zone, '', 0);
         $service->rangeType->set(ShippingService::SUBTOTAL_BASED);
     }
     $this->importInstance($record, $profile, $service);
     $this->setLastImportedRecordName($service->getValueByLang('name'));
     // get rate instance
     $rate = ShippingRate::getNewInstance($service, 0, 1000000);
     $rate->subtotalRangeStart->set(0);
     $rate->subtotalRangeEnd->set(1000000);
     return $rate;
 }