예제 #1
0
 public function verifyTaxList($value, ExecutionContextInterface $context)
 {
     $jsonType = new JsonType();
     if (!$jsonType->isValid($value)) {
         $context->addViolation(Translator::getInstance()->trans("Tax list is not valid JSON"));
     }
     $taxList = json_decode($value, true);
     /* check we have 2 level max */
     foreach ($taxList as $taxLevel1) {
         if (is_array($taxLevel1)) {
             foreach ($taxLevel1 as $taxLevel2) {
                 if (is_array($taxLevel2)) {
                     $context->addViolation(Translator::getInstance()->trans("Bad tax list JSON"));
                 } else {
                     $taxModel = TaxQuery::create()->findPk($taxLevel2);
                     if (null === $taxModel) {
                         $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
                     }
                 }
             }
         } else {
             $taxModel = TaxQuery::create()->findPk($taxLevel1);
             if (null === $taxModel) {
                 $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
             }
         }
     }
 }
예제 #2
0
파일: Tax.php 프로젝트: alex63530/thelia
 /**
  * @param TaxEvent $event
  */
 public function delete(TaxEvent $event)
 {
     if (null !== ($tax = TaxQuery::create()->findPk($event->getId()))) {
         $tax->delete();
         $event->setTax($tax);
     }
 }
예제 #3
0
 public function verifyTaxId($value, ExecutionContextInterface $context)
 {
     $tax = TaxQuery::create()->findPk($value);
     if (null === $tax) {
         $context->addViolation("Tax ID not found");
     }
 }
예제 #4
0
 protected function getExistingObject()
 {
     $tax = TaxQuery::create()->findOneById($this->getRequest()->get('tax_id', 0));
     if (null !== $tax) {
         $tax->setLocale($this->getCurrentEditionLocale());
     }
     return $tax;
 }
예제 #5
0
파일: Tax.php 프로젝트: margery/thelia
 public function buildModelCriteria()
 {
     $search = TaxQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search, array('TITLE', 'DESCRIPTION'));
     $id = $this->getId();
     if (null !== $id) {
         $search->filterById($id, Criteria::IN);
     }
     $exclude = $this->getExclude();
     if (null !== $exclude) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $country = $this->getCountry();
     $taxRule = $this->getTaxRule();
     if (null !== $taxRule && null !== $country) {
         $search->filterByTaxRuleCountry(TaxRuleCountryQuery::create()->filterByCountryId($country, Criteria::EQUAL)->filterByTaxRuleId($taxRule, Criteria::IN)->find(), Criteria::IN);
     }
     $excludeTaxRule = $this->getExcludeTaxRule();
     if (null !== $excludeTaxRule && null !== $country) {
         $excludedTaxes = TaxRuleCountryQuery::create()->filterByCountryId($country, Criteria::EQUAL)->filterByTaxRuleId($excludeTaxRule, Criteria::IN)->find();
         /*DOES NOT WORK
            * $search->filterByTaxRuleCountry(
               $excludedTaxes,
               Criteria::NOT_IN
           );*/
         foreach ($excludedTaxes as $excludedTax) {
             $search->filterByTaxRuleCountry($excludedTax, Criteria::NOT_EQUAL);
         }
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "id":
                 $search->orderById(Criteria::ASC);
                 break;
             case "id_reverse":
                 $search->orderById(Criteria::DESC);
                 break;
             case "alpha":
                 $search->addAscendingOrderByColumn('i18n_TITLE');
                 break;
             case "alpha_reverse":
                 $search->addDescendingOrderByColumn('i18n_TITLE');
                 break;
         }
     }
     return $search;
 }
 public function testCreateTaxRule()
 {
     $taxes = TaxQuery::create()->limit(2)->select(TaxTableMap::ID)->find()->toArray();
     $countries = CountryQuery::create()->limit(2)->select(CountryTableMap::ID)->find()->toArray();
     $data = ["country" => $countries, "tax" => $taxes, "i18n" => array(["locale" => "en_US", "title" => "Test tax rule", "description" => "foo"], ["locale" => "fr_FR", "title" => "Test règle de taxe"])];
     $requestContent = json_encode($data);
     $client = static::createClient();
     $servers = $this->getServerParameters();
     $servers['CONTENT_TYPE'] = 'application/json';
     $client->request('POST', '/api/tax-rules?lang=en_US&sign=' . $this->getSignParameter($requestContent), [], [], $servers, $requestContent);
     $response = $client->getResponse();
     $this->assertEquals(201, $response->getStatusCode());
     $content = json_decode($response->getContent(), true)[0];
     $this->assertEquals("Test tax rule", $content["TITLE"]);
     $this->assertEquals(0, $content["IS_DEFAULT"]);
     return $content["ID"];
 }
예제 #7
0
 /**
  *
  * in this function you add all the fields you need for your Form.
  * Form this you have to call add method on $this->formBuilder attribute :
  *
  * $this->formBuilder->add("name", "text")
  *   ->add("email", "email", array(
  *           "attr" => array(
  *               "class" => "field"
  *           ),
  *           "label" => "email",
  *           "constraints" => array(
  *               new \Symfony\Component\Validator\Constraints\NotBlank()
  *           )
  *       )
  *   )
  *   ->add('age', 'integer');
  *
  * @return null
  */
 protected function buildForm()
 {
     /**
      * Get information
      */
     if (ShoppingFluxConfigQuery::getDefaultLang() !== null) {
         $langId = ShoppingFluxConfigQuery::getDefaultLang()->getId();
     } else {
         $langId = Lang::getDefaultLanguage()->getId();
     }
     $langsId = LangQuery::create()->select("Id")->find()->toArray();
     $langsId = array_flip($langsId);
     $deliveryModulesId = ModuleQuery::create()->filterByType(AbstractDeliveryModule::DELIVERY_MODULE_TYPE)->filterByActivate(1)->select("Id")->find()->toArray();
     $deliveryModulesId = array_flip($deliveryModulesId);
     $taxesId = TaxQuery::create()->filterByType("Thelia\\TaxEngine\\TaxType\\FixAmountTaxType")->select("Id")->find()->toArray();
     $taxesId = array_flip($taxesId);
     $translator = Translator::getInstance();
     /**
      * Then build the form
      */
     $this->formBuilder->add("token", "text", array("label" => $translator->trans("ShoppingFlux Token", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_token"], "constraints" => [], "required" => true, "data" => ShoppingFluxConfigQuery::getToken()))->add("prod", "checkbox", array("label" => $translator->trans("In production", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_prod"], "required" => false, "data" => ShoppingFluxConfigQuery::getProd()))->add("delivery_module_id", "choice", array("label" => $translator->trans("Delivery module", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_delivery_module_id"], "required" => true, "multiple" => false, "choices" => $deliveryModulesId, "data" => ShoppingFluxConfigQuery::getDeliveryModuleId()))->add("lang_id", "choice", array("label" => $translator->trans("Language", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_lang"], "required" => true, "multiple" => false, "choices" => $langsId, "data" => $langId))->add("ecotax_id", "choice", array("label" => $translator->trans("Ecotax rule", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_ecotax"], "required" => true, "choices" => $taxesId, "multiple" => false, "data" => ShoppingFluxConfigQuery::getEcotaxRuleId()))->add("action_type", "choice", array("required" => true, "choices" => ["save" => 0, "export" => 1], "multiple" => false));
 }
예제 #8
0
파일: Tax.php 프로젝트: zorn-v/thelia
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Tax::setDeleted()
  * @see Tax::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(TaxTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildTaxQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
예제 #9
0
 public function preImport()
 {
     // Delete table before proceeding
     ProductQuery::create()->deleteAll();
     ProductImageQuery::create()->deleteAll();
     ProductDocumentQuery::create()->deleteAll();
     TaxRuleQuery::create()->deleteAll();
     TaxQuery::create()->deleteAll();
     ProductSaleElementsQuery::create()->deleteAll();
     ProductPriceQuery::create()->deleteAll();
     // Create T1 <-> T2 IDs correspondance tables
     $this->product_corresp->reset();
     $this->tax_corresp->reset();
     // Importer les taxes
     $this->importTaxes();
 }
예제 #10
0
<?php

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();
예제 #11
0
 /**
  * Get the associated ChildTax object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildTax The associated ChildTax object.
  * @throws PropelException
  */
 public function getTax(ConnectionInterface $con = null)
 {
     if ($this->aTax === null && $this->tax_id !== null) {
         $this->aTax = ChildTaxQuery::create()->findPk($this->tax_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aTax->addTaxRuleCountries($this);
            */
     }
     return $this->aTax;
 }
예제 #12
0
 /**
  * Performs an INSERT on the database, given a Tax or Criteria object.
  *
  * @param mixed               $criteria Criteria or Tax object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(TaxTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Tax object
     }
     if ($criteria->containsKey(TaxTableMap::ID) && $criteria->keyContainsValue(TaxTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . TaxTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = TaxQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
예제 #13
0
     $fr = new \Thelia\Model\FeatureI18n();
     $fr->setLocale('fr_FR')->setFeature($feature);
 }
 $fr->setTitle('Ecotaxe');
 $fr->save($con);
 $us = \Thelia\Model\Base\FeatureI18nQuery::create()->filterByLocale('en_US')->filterByFeature($feature)->findOne();
 if (null === $us) {
     $us = new \Thelia\Model\FeatureI18n();
     $us->setLocale('en_US')->setFeature($feature);
 }
 $us->setTitle('Ecotax');
 $us->save($con);
 echo "Adding ecotax\n";
 $tax = null;
 if (null !== $forceEcotaxId) {
     $tax = \Thelia\Model\TaxQuery::create()->findPk($forceEcotaxId);
     if (null === $tax) {
         echo "Tax `{$forceEcotaxId}` not found\n";
     }
 }
 if (null === $tax) {
     $tax = new \Thelia\Model\Tax();
     $tax->setType('FeatureFixAmountTaxType')->setSerializedRequirements(base64_encode(sprintf('{"feature":%s}', $feature->getId())));
     $tax->save();
     echo sprintf("Ecotax added with ID \n", $tax->getId());
 }
 $fr = \Thelia\Model\Base\TaxI18nQuery::create()->filterByLocale('fr_FR')->filterByTax($tax)->findOne();
 if (null === $fr) {
     $fr = new \Thelia\Model\TaxI18n();
     $fr->setLocale('fr_FR')->setTax($tax);
 }