public function checkTaxRuleId($value, ExecutionContextInterface $context) { if (0 !== intval($value)) { if (null === TaxRuleQuery::create()->findPk($value)) { $context->addViolation($this->trans("The Tax Rule id '%id' doesn't exist", ["%id" => $value])); } } }
if (php_sapi_name() != 'cli') { throw new \Exception('this script can only be launched with cli sapi'); } require __DIR__ . '/../core/bootstrap.php'; $thelia = new Thelia\Core\Thelia("dev", true); $thelia->boot(); $faker = Faker\Factory::create(); $con = \Propel\Runtime\Propel::getConnection(Thelia\Model\Map\ProductTableMap::DATABASE_NAME); $con->beginTransaction(); $currency = \Thelia\Model\CurrencyQuery::create()->filterByCode('EUR')->findOne(); try { $stmt = $con->prepare("SET foreign_key_checks = 0"); $stmt->execute(); \Thelia\Model\TaxQuery::create()->find()->delete(); \Thelia\Model\Base\TaxRuleQuery::create()->find()->delete(); \Thelia\Model\Base\TaxRuleCountryQuery::create()->find()->delete(); $stmt = $con->prepare("SET foreign_key_checks = 1"); $stmt->execute(); /* 10% tax */ $tax10p = new \Thelia\Model\Tax(); $tax10p->setType('PricePercentTaxType')->setRequirements(array('percent' => 10))->save(); /* 8% tax */ $tax8p = new \Thelia\Model\Tax(); $tax8p->setType('PricePercentTaxType')->setRequirements(array('percent' => 8))->save(); /* fix 5 tax */ $tax5 = new \Thelia\Model\Tax(); $tax5->setType('FixAmountTaxType')->setRequirements(array('amount' => 5))->save(); /* 1% tax */ $tax1p = new \Thelia\Model\Tax(); $tax1p->setType('PricePercentTaxType')->setRequirements(array('percent' => 1))->save();
/** * @param Cart $cart * @param $areaId * @return |null */ protected function getSlicePostage(Cart $cart, Country $country) { $config = self::getConfig(); $currency = $cart->getCurrency(); $areaId = $country->getAreaId(); $query = CustomDeliverySliceQuery::create()->filterByAreaId($areaId); if ($config['method'] != CustomDelivery::METHOD_PRICE) { $query->filterByWeightMax($cart->getWeight(), Criteria::GREATER_THAN); $query->orderByWeightMax(Criteria::ASC); } if ($config['method'] != CustomDelivery::METHOD_WEIGHT) { $total = $cart->getTotalAmount(); // convert amount to the default currency if (0 == $currency->getByDefault()) { $total = $total / $currency->getRate(); } $query->filterByPriceMax($total, Criteria::GREATER_THAN); $query->orderByPriceMax(Criteria::ASC); } $slice = $query->findOne(); $postage = null; if (null !== $slice) { $postage = new OrderPostage(); if (0 == $currency->getByDefault()) { $price = $slice->getPrice() * $currency->getRate(); } else { $price = $slice->getPrice(); } $price = round($price, 2); $postage->setAmount($price); $postage->setAmountTax(0); // taxed amount if (0 !== $config['tax']) { $taxRuleI18N = I18n::forceI18nRetrieving($this->getRequest()->getSession()->getLang()->getLocale(), 'TaxRule', $config['tax']); $taxRule = TaxRuleQuery::create()->findPk($config['tax']); if (null !== $taxRule) { $taxCalculator = new Calculator(); $taxCalculator->loadTaxRuleWithoutProduct($taxRule, $country); $postage->setAmount(round($taxCalculator->getTaxedPrice($price), 2)); $postage->setAmountTax($postage->getAmount() - $price); $postage->setTaxRuleTitle($taxRuleI18N->getTitle()); } } } return $postage; }