/** * @role update */ public function delete() { if ($id = (int) $this->request->get('id')) { ShippingRate::getInstanceByID($id)->delete(); } return new JSONResponse(false, 'success'); }
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)); }
include "../../../classes/Connection.php"; include_once "../../../includes/bootstrap.php"; include "../../../classes/Cart.php"; include "../../../classes/Products.php"; include "../../../classes/Client.php"; include "../../../classes/Coupon.php"; include "../../../classes/Shipping.php"; include "../../../classes/Billing.php"; include "../../../classes/ShippingRate.php"; include "../../../classes/AdminAction.php"; include "../../../includes/security.funcs.inc"; include_once "../../../includes/Pagination.php"; $myCart = Cart::findCartByOrderID($_REQUEST['id']); $clients = Client::findClient($myCart->fldCartClientID); $shipping = Shipping::findShippingClient($clients->fldClientID); $shippingRate = ShippingRate::findShippingRateByOrderCode($_REQUEST['id']); $billing = Billing::findBillingClient($clients->fldClientID); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" lang="en-us"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo $ROOT_URL; ?> _admin/_assets/css/core3.css" /> <link rel="stylesheet" type="text/css" media="screen" href="<?php echo $ROOT_URL; ?> _admin/_assets/css/modules.css" />
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'); }
/** * Get active record set from current service * * @param boolean $loadReferencedRecords * @return ARSet */ public function getRates($loadReferencedRecords = false) { return ShippingRate::getRecordSetByService($this, $loadReferencedRecords); }
$pagination = new Pagination(); //for display $pg = $pagination->page_pagination(20, $count_record, $page, 20); //$result_prod = mysql_query($query_Recordset2.$pg[1]); $cart = Cart::findAll($pg[1]); ?> <? if($count_record == 0) { ?> <tr> <td colspan="6" align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#F00; font-weight:bold">No Orders Found</td> </tr> <? } else { foreach($cart as $carts) { $clients = Client::findClient($carts->fldCartClientID); $countItem = Cart::counCartByOrderNo($carts->fldCartOrderNo); $getTotal = Cart::getTotalCartByOrderNo($carts->fldCartOrderNo); $shippingRate = ShippingRate::findShippingRateByOrderCode($carts->fldCartOrderNo); $shipping = Shipping::findShippingClient($clients->fldClientID); $billing = Billing::findBillingClient($clients->fldClientID); if($carts->fldCartCoupon != '') { $coupon = Coupon::findCouponByCode($carts->fldCartCoupon); if($coupon->fldCouponPrice != '') { $discAmount = $coupon->fldCouponPrice; unset($_SESSION['FreeShipping']); } else if($coupon->fldCouponPercent != '') { $percent = $coupon->fldCouponPercent / 100; $discAmount = $getTotal->totalPrice * $percent; unset($_SESSION['FreeShipping']); } else { $_SESSION['FreeShipping'] = 1; $discAmount = 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); }
$myCart->fldCartProductPrice = $carts->fldTempCartProductPrice; $myCart->fldCartQuantity =$carts->fldTempCartQuantity; $myCart->fldCartOrderNo = $order_code; $myCart->fldCartCoupon = $_SESSION['coupon_code']; $myCart->fldCartStatus = $status; //save to cart Cart::addCart($myCart); //SAVE THE SHIPPING RATE $_POST = sanitize($_POST); $shipping = $_POST; settype($shipping,'object'); $shipping->order_no = $order_code; $shipping->shipping_name = $ship_name; $shipping->shipping_amount = $quote; ShippingRate::addShippingRate($shipping); } //remove order from tempcart Tempcart::deleteTempCartByCondition($condition); $client = Client::findClient($client_id); $shipping = Shipping::findShippingClient($client_id); if(isset($_SESSION['coupon_code'])) { unset($_SESSION['coupon_code']); } ?> <FORM action="https://secure.authorize.net/gateway/transact.dll" method="POST" name="form1"> <?
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(); }
$trans_id = $_POST['trans_id']; $amount = $_POST['amount']; //update the order id Cart::updateCartStatus($order_id,$trans_id); $myOrder = Cart::findCartByOrderID($order_id); //$clients = Client::findClient($myOrder->fldCartClientID); $shipping = Shipping::findShippingClient($clients->fldClientID); $shippingRate = ShippingRate::findShippingRateByOrderCode($order_id); $clients = Billing::findBillingClient($myOrder->fldCartClientID); $message = "<table width=100% border=0 cellpadding=1 cellspacing=1 bgcolor=#333300>"; $message .= "<tr>"; $message .= "<td height=25 align=center> </td>"; $message .= "<td height=25 align=center><font face=Arial, Helvetica, sans-serif size=2 color=#FFFFFF><b>Product Name</b></font></td>"; $message .= "<td height=25 align=center><font face=Arial, Helvetica, sans-serif size=2 color=#FFFFFF><b>Amount</b></font></td>"; $message .= "<td height=25 align=center><font face=Arial, Helvetica, sans-serif size=2 color=#FFFFFF><b>Quantity</b></font></td>"; $message .= "<td height=25 align=center><font face=Arial, Helvetica, sans-serif size=2 color=#FFFFFF><b>Total Amount</b></font></td>"; $message .= "</tr>"; //display the shopping cart $date = date('Y-m-d');
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; }