public function getFields() { $allTaxClassesArray = array(); foreach (TaxClass::getAllClasses()->toArray() as $instanceArray) { $allTaxClassesArray[$instanceArray['ID']] = $instanceArray['name_lang']; } return array(array('type' => 'select', 'label' => '_tax_class', 'name' => 'taxClassID', 'options' => $allTaxClassesArray)); }
public static function getAllTaxClassesIdAndName() { $results = array(); $sql = 'select `id`,`name` from ecomm_category'; $allTaxClasses = TaxClass::getAll(false); foreach ($allTaxClasses as $taxClass) { $results[$taxClass->getId()] = $taxClass->getName(); } return $results; }
public function actionCreate() { $model = new TaxClass(); $description = new TaxClassDescription(); $this->performAjaxValidation(array($model, $description), 'tax-class-form'); if (isset($_POST[$this->modelName])) { $model->setAttributes($_POST[$this->modelName]); $description->setAttributes($_POST[$this->modelName . 'Description']); $suc = Yii::t('info', 'TaxClass was successfully created'); $err = Yii::t('info', 'Could not update TaxClass'); $description->tax_class_id = 0; $description->locale_code = Yii::app()->getLanguage(); if ($model->validate() && $description->validate()) { if ($model->save()) { $description->tax_class_id = $model->id; $description->save(); Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc); if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_view', array('model' => $model, 'description' => $description), false, true); Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->id)); } } else { Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err); } } else { $description->validate(); } } if (Yii::app()->getRequest()->getIsAjaxRequest()) { $this->renderPartial('_form', array('model' => $model, 'description' => $description), false, true); Yii::app()->end(); } $this->render('create', array('model' => $model, 'description' => $description)); }
public function test_apply_tax() { $zone_Attica = Zone::whereName("Attica")->first(); $zone_Islands = Zone::whereName("Islands")->first(); $tax_class_Taxable = TaxClass::whereName("Taxable products")->first(); $tax_class_NonTaxable = TaxClass::whereName("Non Taxable products")->first(); //$geoZoneWithFPA23=GeoZone::whereName("Geo Zone with FPA 23%")->first(); //$geoZoneWithFPA8=GeoZone::whereName("Geo Zone with FPA 8%")->first(); $taxes = $this->service->calculateTaxes(100, $zone_Attica->id, $tax_class_Taxable->id); $this->assertEquals(2, count($taxes)); print_r($taxes); $taxes = $this->service->calculateTaxes(100, $zone_Islands->id, $tax_class_Taxable->id); $this->assertEquals(1, count($taxes)); print_r($taxes); $taxes = $this->service->calculateTaxes(100, -90, $tax_class_Taxable->id); $this->assertEquals(0, count($taxes)); print_r($taxes); $taxes = $this->service->calculateTaxes(100, $zone_Attica->id, -1); $this->assertEquals(0, count($taxes)); print_r($taxes); }
public function actionUpdate($id) { $model = new ProductForm(); if (isset($_POST['ProductForm'])) { $model->attributes = $_POST['ProductForm']; if ($model->validate()) { $model->save(); $this->redirect(array('index')); } } else { $model->loadDataFromProduct($id); } $statuses = array(0 => Yii::t('common', 'Disabled'), 1 => Yii::t('common', 'Enabled')); $yes_no = array(0 => Yii::t('common', 'No'), 1 => Yii::t('common', 'Yes')); $taxClasses = TaxClass::model()->findAll(); $taxClassesList = array(); foreach ($taxClasses as $taxClass) { $taxClassesList[$taxClass->tax_class_id] = $taxClass->title; } // TODO: add language $stockStatuses = StockStatus::model()->findAll(); $stockStatusesList = array(); foreach ($stockStatuses as $stockStatus) { $stockStatusesList[$stockStatus->stock_status_id] = $stockStatus->name; } // TODO: add language $weightClasses = WeightClass::model()->findAll(); $weightClassesList = array(); foreach ($weightClasses as $weightClass) { $weightClassesList[$weightClass->weight_class_id] = $weightClass->description->title; } // TODO: add language $lengthClasses = LengthClass::model()->findAll(); $lengthClassesList = array(); foreach ($lengthClasses as $lengthClass) { $lengthClassesList[$lengthClass->length_class_id] = $lengthClass->description->title; } $this->render('update', array('model' => $model, 'statuses' => $statuses, 'taxClasses' => $taxClassesList, 'yes_no' => $yes_no, 'stockStatuses' => $stockStatusesList, 'weightClasses' => $weightClassesList, 'lengthClasses' => $lengthClassesList)); }
private function getFieldName(DeliveryZone $zone = null, TaxClass $class = null) { $classID = $class ? $class->getID() : '-1'; $zoneID = $zone ? $zone->getID() : '-1'; if ($classID == 0) { $classID = -1; } if ($zoneID == 0) { $zoneID = -1; } return 'taxRate_' . $zoneID . '_' . $classID; }
function createTable() { $cols = array('id?', DBColumn::make('!select', 'country', 'Country', Address::getCountries()), DBColumn::make('!select', 'province', 'Province / State', Address::getStates()), DBColumn::make('!select', 'tax_class', 'Tax Class', TaxClass::getAllTaxClassesIdAndName()), DBColumn::make('!float', 'tax_rate', 'Tax Rate %'), DBColumn::make('timestamp', 'date_added', 'Date Added'), DBColumn::make('//text', 'last_modified', 'Last Modified'), DBColumn::make('tinymce', 'details', 'Details')); return new DBTable("ecomm_tax_rate", __CLASS__, $cols); }
private function productForm(Product $product) { $productFormData = $product->toArray(); if ($product->isLoaded()) { $product->loadSpecification(); $productFormData = array_merge($productFormData, $product->getSpecification()->getFormData()); if (isset($productFormData['Manufacturer']['name'])) { $productFormData['manufacturer'] = $productFormData['Manufacturer']['name']; } } else { $product->load(ActiveRecord::LOAD_REFERENCES); } $product->loadPricing(); $form = $this->buildForm($product); $pricing = $product->getPricingHandler(); $pricesData = $product->toArray(); $listPrices = $pricing->toArray(ProductPricing::DEFINED, ProductPricing::LIST_PRICE); $pricesData['shippingHiUnit'] = (int) $pricesData['shippingWeight']; $pricesData['shippingLoUnit'] = ($pricesData['shippingWeight'] - $pricesData['shippingHiUnit']) * 1000; if (array_key_exists('defined', $pricesData)) { foreach ($pricesData['calculated'] as $currency => $price) { $pricesData['price_' . $currency] = isset($pricesData['defined'][$currency]) ? $pricesData['defined'][$currency] : ''; $productFormData['price_' . $currency] = $pricesData['price_' . $currency]; } } foreach ($listPrices as $currency => $price) { $pricesData['listPrice_' . $currency] = $price; } $form->setData($productFormData); // status values $status = array(0 => $this->translate('_disabled'), 1 => $this->translate('_enabled')); // product types $types = array(Product::TYPE_TANGIBLE => $this->translate('_tangible'), Product::TYPE_DOWNLOADABLE => $this->translate('_intangible'), Product::TYPE_BUNDLE => $this->translate('_bundle')); // default product type if (!$product->isLoaded()) { $product->type->set(substr($this->config->get('DEFAULT_PRODUCT_TYPE'), -1)); $form->set('type', $product->type->get()); } $response = new ActionResponse(); $product->getSpecification()->setFormResponse($response, $form); $response->set("cat", $product->getCategory()->getID()); $response->set("hideFeedbackMessage", $this->request->get("afterAdding") == 'on'); $response->set("productForm", $form); $response->set("path", $product->getCategory()->getPathNodeArray(true)); $response->set("productTypes", $types); $response->set("productStatuses", $status); $response->set("baseCurrency", $this->application->getDefaultCurrency()->getID()); $response->set("otherCurrencies", $this->application->getCurrencyArray(LiveCart::EXCLUDE_DEFAULT_CURRENCY)); $response->set("shippingClasses", $this->getSelectOptionsFromSet(ShippingClass::getAllClasses())); $response->set("taxClasses", $this->getSelectOptionsFromSet(TaxClass::getAllClasses())); $productData = $product->toArray(); if (empty($productData['ID'])) { $productData['ID'] = 0; } $response->set("product", $productData); return $response; }
private function productForm($isExisting) { ClassLoader::import('application.LiveCartRenderer'); ClassLoader::import('application.model.presentation.CategoryPresentation'); $response = new BlockResponse(); $response->set('themes', array_merge(array(''), LiveCartRenderer::getThemeList())); $form = $this->buildForm($isExisting); // status values $status = array(0 => $this->translate('_disabled'), 1 => $this->translate('_enabled')); // product types $types = array(Product::TYPE_TANGIBLE => $this->translate('_tangible'), Product::TYPE_DOWNLOADABLE => $this->translate('_intangible'), Product::TYPE_BUNDLE => $this->translate('_bundle'), Product::TYPE_RECURRING => $this->translate('_recurring')); //$product->type->set(substr($this->config->get('DEFAULT_PRODUCT_TYPE'), -1)); $response->set("productForm", $form); $response->set("productTypes", $types); $response->set("productStatuses", $status); $response->set("baseCurrency", $this->application->getDefaultCurrency()->getID()); $response->set("otherCurrencies", $this->application->getCurrencyArray(LiveCart::EXCLUDE_DEFAULT_CURRENCY)); $response->set("shippingClasses", $this->getSelectOptionsFromSet(ShippingClass::getAllClasses())); $response->set("taxClasses", $this->getSelectOptionsFromSet(TaxClass::getAllClasses())); // get user groups $f = new ARSelectFilter(); $f->setOrder(new ARFieldHandle('UserGroup', 'name')); $groups[0] = $this->translate('_all_customers'); foreach (ActiveRecordModel::getRecordSetArray('UserGroup', $f) as $group) { $groups[$group['ID']] = $group['name']; } $groups[''] = ''; $response->set('userGroups', $groups); return $response; }
public function importInstance($record, CsvImportProfile $profile) { $this->className = 'Product'; $impReq = new Request(); $defLang = $this->application->getDefaultLanguageCode(); $references = array('DefaultImage' => 'ProductImage', 'Manufacturer', 'ShippingClass', 'TaxClass'); $cat = $this->getCategory($profile, $record); $extraCategories = null; $fields = $profile->getSortedFields(); if (isset($fields['Categories']['ExtraCategories'])) { $extraCategories = explode('; ', $record[$fields['Categories']['ExtraCategories']]); } if (isset($fields['Product']) && $cat) { $product = null; if (isset($fields['Product']['ID']) && !empty($record[$fields['Product']['ID']])) { $id = $record[$fields['Product']['ID']]; if (ActiveRecord::objectExists('Product', $id)) { $product = Product::getInstanceByID($id, Product::LOAD_DATA, $references); } } else { if (isset($fields['Product']['sku']) && !empty($record[$fields['Product']['sku']])) { $product = Product::getInstanceBySku($record[$fields['Product']['sku']], $references); } } if ($product && $product->getID()) { $this->registerImportedID($product->getID()); } if (!$product && 'update' == $this->options['action'] || $product && 'add' == $this->options['action']) { return false; } if ($product) { $product->loadSpecification(); $product->loadPricing(); } else { if ($cat instanceof Category) { $product = Product::getNewInstance($cat); } else { $product = $cat->createChildProduct(); } $product->isEnabled->set(true); } // product information $impReq->clearData(); foreach ($profile->getFields() as $csvIndex => $field) { $column = $field['name']; $params = $field['params']; if (!isset($record[$csvIndex]) || empty($column)) { continue; } $value = $record[$csvIndex]; list($className, $field) = explode('.', $column, 2); if (isset($params['language'])) { $lang = $params['language']; if ($lang != $defLang) { $field .= '_' . $lang; } } if ($value) { if ('Product.parentID' == $column) { $product->parent->set(); continue; } if ('Product.parentSKU' == $column) { $product->parent->set(Product::getInstanceBySKU($value)); continue; } } if ('Product.taxClass' == $column) { $product->taxClass->set(TaxClass::findByName($value)); } if ('Product.shippingClass' == $column) { $product->shippingClass->set(ShippingClass::findByName($value)); } if ('Product' == $className) { if ('shippingWeight' == $field) { if ($this->application->getConfig()->get('UNIT_SYSTEM') == 'ENGLISH') { $value = $value / 0.45359237; } } if ('shippingWeight' == $field && $product->parent->get()) { $value = $this->setChildSetting($product, 'weight', $value); } $impReq->set($field, $value); } else { if ('Manufacturer' == $className) { $impReq->set('manufacturer', $value); } else { if ('ProductPrice.price' == $column) { if ($product->parent->get()) { $value = $this->setChildSetting($product, 'price', $value); } $value = preg_replace('/,([0-9]{3})/', '\\1', $value); $value = (double) preg_replace('/[^\\.0-9]/', '', str_replace(',', '.', $value)); $currency = isset($params['currency']) ? $params['currency'] : $this->application->getDefaultCurrencyCode(); $quantityLevel = isset($params['quantityLevel']) ? $params['quantityLevel'] : ''; $group = isset($params['group']) ? $params['group'] : ''; $price = $product->getPricingHandler()->getPriceByCurrencyCode($currency); $product->getPricingHandler()->setPrice($price); if ($group || $quantityLevel) { if ($value > 0) { $quantity = $quantityLevel ? $record[$fields['ProductPrice'][$quantityLevel]] : 1; $group = $group ? UserGroup::getInstanceByID($group) : null; $price->setPriceRule($quantity, $group, $value); } } else { $price->price->set($value); } } else { if ('ProductPrice.listPrice' == $column) { $value = (double) preg_replace('/[^\\.0-9]/', '', str_replace(',', '.', $value)); $currency = $params['currency']; $price = $product->getPricingHandler()->getPriceByCurrencyCode($currency); $price->listPrice->set($value); $product->getPricingHandler()->setPrice($price); } else { if ('ProductVariation' == $className) { if ($parent = $product->parent->get()) { $this->importProductVariationValue($product, $field, $value); } else { $this->importVariationType($product, $field, $value); } } } } } } } $product->loadRequestData($impReq); $product->save(); $this->importAttributes($product, $record, $fields, 'specField'); $this->setLastImportedRecordName($product->getValueByLang('name')); if (isset($fields['ProductImage']['mainurl'])) { if (!($image = $product->defaultImage->get())) { $image = ProductImage::getNewInstance($product); } $image->setOwner($product); // this is needed when ProductApi imports default ProductImage. $this->importImage($image, $record[$fields['ProductImage']['mainurl']]); unset($image); } if (isset($fields['ProductAdditionalImage'])) { foreach ($fields['ProductAdditionalImage'] as $index) { $this->importImage(ProductImage::getNewInstance($product), $record[$index]); } } if (isset($fields['ProductImage']['Images'])) { $images = explode('; ', $record[$fields['ProductImage']['Images']]); if ($images) { $product->deleteRelatedRecordSet('ProductImage'); foreach ($images as $path) { $image = ProductImage::getNewInstance($product); $this->importImage($image, $path); unset($image); } } } if (isset($fields['ProductOption']['options'])) { $options = explode('; ', $record[$fields['ProductOption']['options']]); if ($options) { $product->deleteRelatedRecordSet('ProductOption'); foreach ($options as $option) { $parts = explode(':', $option, 2); if (count($parts) < 2) { continue; } $optionInstance = ProductOption::getNewInstance($product); $optionInstance->setValueByLang('name', null, trim($parts[0])); $optionInstance->type->set(ProductOption::TYPE_SELECT); $optionInstance->isDisplayed->set(true); $optionInstance->save(); foreach (explode(',', $parts[1]) as $choice) { $choiceInstance = ProductOptionChoice::getNewInstance($optionInstance); $choiceInstance->setValueByLang('name', null, trim($choice)); $choiceInstance->save(); } } } } // create variation by name if ((isset($fields['Product']['parentID']) || isset($fields['Parent']['parentSKU'])) && !isset($fields['ProductVariation']) && $product->parent->get()) { $this->importProductVariationValue($product, 1, $product->getValueByLang('name', 'en')); } // additional categories if (is_array($extraCategories)) { $this->importAdditionalCategories($profile, $product, $extraCategories); } if ($this->callback) { call_user_func($this->callback, $product); } $product->__destruct(); $product->destruct(true); ActiveRecord::clearPool(); return true; } }
public function actionIndex() { $taxClasses = TaxClass::model()->findAll(); $this->render('index', array('taxClasses' => $taxClasses)); }
public function delete_class($tcID) { TaxClass::getByID($tcID)->delete(); $this->redirect("/dashboard/store/settings/tax/class_deleted"); }
/** * @role update */ public function sort() { foreach ($this->request->get($this->request->get('target'), array()) as $position => $key) { $class = TaxClass::getInstanceByID((int) $key); $class->position->set((int) $position); $class->save(); } return new JSONResponse(false, 'success'); }
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); }
public function getShippingTaxClass() { $shippingTaxClassId = self::getApplication()->getConfig()->get('DELIVERY_TAX_CLASS'); return !is_numeric($shippingTaxClassId) ? null : TaxClass::getInstanceById($shippingTaxClassId, TaxClass::LOAD_DATA); }
private function getFieldName(Tax $tax, TaxClass $class = null) { $classID = $class ? $class->getID() : ''; return 'tax_' . $tax->getID() . '_' . $classID; }
echo $form->labelEx($model, 'price'); ?> <?php echo $form->textField($model, 'price', array('size' => 15, 'maxlength' => 15)); ?> <?php echo $form->error($model, 'price'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'tax_class_id'); ?> <?php echo CHtml::activeDropDownList($model, 'tax_class_id', CHtml::listData(TaxClass::model()->findAll(), 'id', function ($data) { return $data->getName(); })); ?> <?php echo $form->error($model, 'tax_class_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'date_available'); ?> <?php echo CHtml::activeDateField($model, 'date_available'); ?>