public function testGetRatesByService() { $rate1 = ShippingRate::getNewInstance($this->shippingService, 1.1, 1.2); $rate1->save(); $rate2 = ShippingRate::getNewInstance($this->shippingService, 1.3, 1.4); $rate2->save(); $rates = ShippingRate::getRecordSetByService($this->shippingService); $this->assertTrue($rate1 === $rates->get(0)); $this->assertTrue($rate2 === $rates->get(1)); }
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)); }
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')); } }
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'); }
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); }
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(); }
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; }