/** * @role update */ public function save() { $taxes = Tax::getAllTaxes(); $classes = TaxClass::getAllClasses(); if (($zoneID = (int) $this->request->get('id')) <= 0) { $taxRates = TaxRate::getRecordSetByDeliveryZone(null); $deliveryZone = DeliveryZone::getDefaultZoneInstance(); } else { $deliveryZone = DeliveryZone::getInstanceByID($zoneID, true); $taxRates = $deliveryZone->getTaxRates(); } ActiveRecord::beginTransaction(); // delete all rates foreach ($taxRates as $rate) { $rate->delete(); } foreach ($taxes as $tax) { $this->saveRate($deliveryZone, $tax, null); foreach ($classes as $class) { $this->saveRate($deliveryZone, $tax, $class); } } ActiveRecord::commit(); return new JSONResponse(false, 'success', $this->translate('_tax_rates_have_been_successfully_saved')); }
/** * @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); }
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; }
/** * @role update */ public function saveAddressMask() { if (($errors = $this->isValidMask()) === true) { $maskValue = $this->request->get('mask'); if ($id = (int) $this->getId()) { $mask = DeliveryZoneAddressMask::getInstanceByID($id); $mask->mask->set($maskValue); } else { $zone = DeliveryZone::getInstanceByID((int) $this->request->get('zoneID')); $mask = DeliveryZoneAddressMask::getNewInstance($zone, $maskValue); } $mask->save(); return new JSONResponse(array('ID' => $mask->getID()), 'success'); } else { return new JSONResponse(array('errors' => $errors), 'failure', $this->translate('_could_not_save_mask')); } }