예제 #1
0
파일: Tax.php 프로젝트: alex63530/thelia
 /**
  * @param TaxEvent $event
  */
 public function create(TaxEvent $event)
 {
     $tax = new TaxModel();
     $tax->setDispatcher($event->getDispatcher())->setRequirements($event->getRequirements())->setType($event->getType())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription());
     $tax->save();
     $event->setTax($tax);
 }
예제 #2
0
 protected function buildForm($change_mode = false)
 {
     if (!$this->container) {
         throw new \LogicException(Translator::getInstance()->trans("The container should not be null in this form. Please use the FormFactory to get an instance."));
     }
     /** @var TaxEngine $taxEngine */
     $taxEngine = $this->container->get('thelia.taxEngine');
     $types = $taxEngine->getTaxTypeList();
     $typeList = array();
     $requirementList = array();
     foreach ($types as $classname) {
         $instance = new $classname();
         $typeList[Tax::escapeTypeName($classname)] = $instance->getTitle();
         $requirementList[$classname] = $instance->getRequirementsDefinition();
     }
     $this->formBuilder->add("locale", "hidden", ["constraints" => [new NotBlank()]])->add("type", "choice", ["choices" => $typeList, "required" => true, "constraints" => [new Constraints\NotBlank()], "label" => Translator::getInstance()->trans("Type"), "label_attr" => ["for" => "type_field"]]);
     foreach ($requirementList as $name => $requirements) {
         /** @var TaxTypeRequirementDefinition $requirement */
         foreach ($requirements as $requirement) {
             if (!isset(self::$typeList[$requirement->getName()])) {
                 self::$typeList[$requirement->getName()] = $requirement->getType();
             }
             $this->formBuilder->add(Tax::escapeTypeName($name) . ':' . $requirement->getName(), new TheliaType(), ["constraints" => [new Constraints\Callback(["methods" => [[$this, "checkRequirementField"]]])], "attr" => ["tag" => "requirements", "tax_type" => Tax::escapeTypeName($name)], "label_attr" => ["type" => $requirement->getName()], "label" => Translator::getInstance()->trans($requirement->getTitle()), "type" => $requirement->getType()->getFormType(), "options" => $requirement->getType()->getFormOptions()]);
         }
     }
     $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale'));
 }
예제 #3
0
 protected function buildForm($change_mode = false)
 {
     if ($this->taxEngine == null) {
         throw new \LogicException(Translator::getInstance()->trans("The TaxEngine should be passed to this form before using it."));
     }
     $types = $this->taxEngine->getTaxTypeList();
     $typeList = array();
     $requirementList = array();
     foreach ($types as $classname) {
         $instance = new $classname();
         $typeList[Tax::escapeTypeName($classname)] = $instance->getTitle();
         $requirementList[$classname] = $instance->getRequirementsDefinition();
     }
     $this->formBuilder->add("locale", "text", array("constraints" => array(new NotBlank())))->add("type", "choice", array("choices" => $typeList, "required" => true, "constraints" => array(new Constraints\NotBlank()), "label" => Translator::getInstance()->trans("Type"), "label_attr" => array("for" => "type_field")));
     foreach ($requirementList as $name => $requirements) {
         foreach ($requirements as $requirement) {
             $this->formBuilder->add(Tax::escapeTypeName($name) . ':' . $requirement->getName(), new TheliaType(), array("constraints" => array(new Constraints\Callback(array("methods" => array(array($requirement->getType(), "verifyForm"))))), "attr" => array("tag" => "requirements", "tax_type" => Tax::escapeTypeName($name)), "label" => Translator::getInstance()->trans($requirement->getName()), "type" => $requirement->getType()->getFormType(), "options" => $requirement->getType()->getFormOptions()));
         }
     }
     $this->addStandardDescFields(array('postscriptum', 'chapo', 'locale'));
 }
예제 #4
0
파일: Tax.php 프로젝트: margery/thelia
 public function parseResults(LoopResult $loopResult)
 {
     /** @var TaxModel $tax */
     foreach ($loopResult->getResultDataCollection() as $tax) {
         $loopResultRow = new LoopResultRow($tax);
         $loopResultRow->set("ID", $tax->getId())->set("TYPE", $tax->getType())->set("ESCAPED_TYPE", TaxModel::escapeTypeName($tax->getType()))->set("REQUIREMENTS", $tax->getRequirements())->set("IS_TRANSLATED", $tax->getVirtualColumn('IS_TRANSLATED'))->set("LOCALE", $this->locale)->set("TITLE", $tax->getVirtualColumn('i18n_TITLE'))->set("DESCRIPTION", $tax->getVirtualColumn('i18n_DESCRIPTION'));
         $this->addOutputFields($loopResultRow, $tax);
         $loopResult->addRow($loopResultRow);
     }
     return $loopResult;
 }
예제 #5
0
 /**
  * @param Tax $object
  * @return int
  */
 protected function getObjectId($object)
 {
     return $object->getId();
 }
예제 #6
0
 protected function hydrateObjectForm($object)
 {
     $data = array('id' => $object->getId(), 'locale' => $object->getLocale(), 'title' => $object->getTitle(), 'description' => $object->getDescription(), 'type' => Tax::escapeTypeName($object->getType()));
     // Setup the object form
     return $this->createForm(AdminForm::TAX_MODIFICATION, "form", $data);
 }
예제 #7
0
 /**
  * Declares an association between this object and a ChildTax object.
  *
  * @param                  ChildTax $v
  * @return                 \Thelia\Model\TaxRuleCountry The current object (for fluent API support)
  * @throws PropelException
  */
 public function setTax(ChildTax $v = null)
 {
     if ($v === null) {
         $this->setTaxId(NULL);
     } else {
         $this->setTaxId($v->getId());
     }
     $this->aTax = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildTax object, it will not be re-added.
     if ($v !== null) {
         $v->addTaxRuleCountry($this);
     }
     return $this;
 }
 /**
  * @return string
  */
 public function doExport()
 {
     /**
      * Define the cache
      */
     $cache = [];
     $cache["brand"] = [];
     $cache["category"] = [];
     $cache["breadcrumb"] = [];
     $cache["feature"]["title"] = [];
     $cache["feature"]["value"] = [];
     $cache["attribute"]["title"] = [];
     $cache["attribute"]["value"] = [];
     $fakeCartItem = new CartItem();
     $fakeCart = new Cart();
     $fakeCart->addCartItem($fakeCartItem);
     /** @var \Thelia\Model\Country $country */
     $country = CountryQuery::create()->findOneById(ConfigQuery::create()->read('store_country', null));
     $deliveryModuleModelId = ShoppingFluxConfigQuery::getDeliveryModuleId();
     $deliveryModuleModel = ModuleQuery::create()->findPk($deliveryModuleModelId);
     /** @var \Thelia\Module\AbstractDeliveryModule $deliveryModule */
     $deliveryModule = $deliveryModuleModel->getModuleInstance($this->container);
     /**
      * Build fake Request to inject in the module
      */
     $fakeRequest = new Request();
     $fakeRequest->setSession((new FakeSession())->setCart($fakeCart));
     $deliveryModule->setRequest($fakeRequest);
     /**
      * Currency
      */
     $currency = Currency::getDefaultCurrency();
     /**
      * Load ecotax
      */
     $ecotax = TaxQuery::create()->findPk(ShoppingFluxConfigQuery::getEcotaxRuleId());
     /**
      * If there's a problem in the configuration, load a fake tax
      */
     if ($ecotax === null) {
         $ecotax = new Tax();
         $ecotax->setType('\\Thelia\\TaxEngine\\TaxType\\FixAmountTaxType')->setRequirements(array('amount' => 0));
     }
     /**
      * Load the tax instance
      */
     $ecotaxInstance = $ecotax->getTypeInstance();
     // Compatibility with Thelia <= 2.0.2
     $ecotaxInstance->loadRequirements($ecotax->getRequirements());
     // We can pass any product as Argument, it is not used
     $ecotax = $ecotaxInstance->fixAmountRetriever(new Product());
     /** @var \Thelia\Model\Product $product */
     foreach ($this->getData() as $product) {
         $product->setLocale($this->locale);
         $node = $this->xml->addChild("produit");
         /**
          * Parent id
          */
         $node->addChild("id", $product->getId());
         $node->addChild("nom", $product->getTitle());
         $node->addChild("url", URL::getInstance()->absoluteUrl("/", ["view" => "product", "product_id" => $product->getId()]));
         $node->addChild("description-courte", $product->getChapo());
         $node->addChild("description", $product->getDescription());
         /**
          * Images URL
          */
         $imagesNode = $node->addChild("images");
         /** @var \Thelia\Model\ProductImage $productImage */
         foreach ($product->getProductImages() as $productImage) {
             $imagesNode->addChild("image", URL::getInstance()->absoluteUrl("/shoppingflux/image/" . $productImage->getId()));
         }
         /**
          * Product Brand
          */
         if ($product->getBrand()) {
             $brand = $product->getBrand();
             $brand->setLocale($this->locale);
             if (!array_key_exists($brandId = $brand->getId(), $cache["brand"])) {
                 $cache["brand"][$brandId] = $brand->getTitle();
             }
             $node->addChild("marque", $cache["brand"][$brandId]);
         } else {
             $node->addChild("marque", null);
         }
         $node->addChild("url-marque");
         /**
          * Compute breadcrumb
          */
         $category = $product->getCategories()[0];
         $category->setLocale($this->locale);
         if (!array_key_exists($categoryId = $category->getId(), $cache["category"])) {
             $cache["category"][$categoryId] = $category->getTitle();
             $breadcrumb = [];
             do {
                 $category->setLocale($this->locale);
                 $breadcrumb[] = $category->getTitle();
             } while (null !== ($category = CategoryQuery::create()->findPk($category->getParent())));
             $reversedBreadcrumb = array_reverse($breadcrumb);
             $reversedBreadcrumb[] = $product->getTitle();
             $cache["breadcrumb"][$categoryId] = implode(" > ", $reversedBreadcrumb);
         }
         $node->addChild("rayon", $cache["category"][$categoryId]);
         $node->addChild("fil-ariane", $cache["breadcrumb"][$categoryId]);
         /**
          * Features
          */
         $featuresNode = $node->addChild("caracteristiques");
         foreach ($product->getFeatureProducts() as $featureProduct) {
             if ($featureProduct->getFeatureAv() !== null && $featureProduct->getFeature() !== null) {
                 if (!array_key_exists($featureId = $featureProduct->getFeature()->getId(), $cache["feature"]["title"])) {
                     $featureProduct->getFeatureAv()->setLocale($this->locale);
                     $featureProduct->getFeature()->setLocale($this->locale);
                     $cache["feature"]["title"][$featureId] = trim(preg_replace("#[^a-z0-9_\\-]#i", "_", $featureProduct->getFeature()->getTitle()), "_");
                     $cache["feature"]["value"][$featureId] = $featureProduct->getFeatureAv()->getTitle();
                 }
                 $featuresNode->addChild($cache["feature"]["title"][$featureId], $cache["feature"]["value"][$featureId]);
             }
         }
         /**
          * Compute VAT
          */
         $taxRuleCountry = TaxRuleCountryQuery::create()->filterByTaxRule($product->getTaxRule())->findOne();
         $tax = $taxRuleCountry->getTax();
         /** @var \Thelia\TaxEngine\TaxType\PricePercentTaxType $taxType*/
         $taxType = $tax->getTypeInstance();
         if (array_key_exists("percent", $taxRequirements = $taxType->getRequirements())) {
             $node->addChild("tva", $taxRequirements["percent"]);
         }
         /**
          * Compute product sale elements
          */
         $productSaleElements = $product->getProductSaleElementss();
         $psesNode = $node->addChild("declinaisons");
         /** @var \Thelia\Model\ProductSaleElements $pse */
         foreach ($productSaleElements as $pse) {
             /**
              * Fake the cart so that module::getPostage() returns the price
              * for only one object
              */
             $fakeCartItem->setProductSaleElements($pse);
             /**
              * If the object is too heavy, don't export it
              */
             try {
                 $shipping_price = $deliveryModule->getPostage($country);
             } catch (DeliveryException $e) {
                 continue;
             }
             $productPrice = $pse->getPricesByCurrency($currency);
             $pse->setVirtualColumn("price_PRICE", $productPrice->getPrice());
             $pse->setVirtualColumn("price_PROMO_PRICE", $productPrice->getPromoPrice());
             $deliveryTimeMin = null;
             $deliveryTimeMax = null;
             $pseNode = $psesNode->addChild("declinaison");
             /**
              * Child id
              */
             $pseNode->addChild("id", $product->getId() . "_" . $pse->getId());
             $pseNode->addChild("prix-ttc", $pse->getPromo() ? $pse->getPromoPrice() : $pse->getPrice());
             $pseNode->addChild("prix-ttc-barre", $pse->getPromo() ? $pse->getPrice() : null);
             $pseNode->addChild("quantite", $pse->getQuantity());
             $pseNode->addChild("ean", $pse->getEanCode());
             $pseNode->addChild("poids", $pse->getWeight());
             $pseNode->addChild("ecotaxe", $ecotax);
             $pseNode->addChild("frais-de-port", $shipping_price);
             $pseNode->addChild("delai-livraison-mini", $deliveryTimeMin);
             $pseNode->addChild("delai-livraison-maxi", $deliveryTimeMax);
             $pseAttrNode = $pseNode->addChild("attributs");
             /** @var \Thelia\Model\AttributeCombination $attr */
             foreach ($pse->getAttributeCombinations() as $attr) {
                 if ($attr->getAttribute() !== null && $attr->getAttributeAv() !== null) {
                     if (!array_key_exists($attributeId = $attr->getAttribute()->getId(), $cache["attribute"]["title"])) {
                         $attr->getAttribute()->setLocale($this->locale);
                         $attr->getAttributeAv()->setLocale($this->locale);
                         $cache["attribute"]["title"][$attributeId] = trim(preg_replace("#[^a-z0-9_\\-]#i", "_", $attr->getAttribute()->getTitle()), "_");
                         $cache["attribute"]["value"][$attributeId] = $attr->getAttributeAv()->getTitle();
                     }
                     $pseAttrNode->addChild($cache["attribute"]["title"][$attributeId], $cache["attribute"]["value"][$attributeId]);
                 }
             }
             $pseNode->addChild("promo-de");
             $pseNode->addChild("promo-a");
         }
     }
     /**
      * Then return a well formed string
      */
     $dom = new \DOMDocument("1.0");
     $dom->preserveWhiteSpace = false;
     $dom->formatOutput = true;
     $dom->loadXML($this->xml->asXML());
     return $dom->saveXML();
 }
예제 #9
0
파일: TaxQuery.php 프로젝트: margery/thelia
 /**
  * Exclude object from result
  *
  * @param   ChildTax $tax Object to remove from the list of results
  *
  * @return ChildTaxQuery The current query, for fluid interface
  */
 public function prune($tax = null)
 {
     if ($tax) {
         $this->addUsingAlias(TaxTableMap::ID, $tax->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
예제 #10
0
 protected function hydrateObjectForm($object)
 {
     $data = array('id' => $object->getId(), 'locale' => $object->getLocale(), 'title' => $object->getTitle(), 'description' => $object->getDescription(), 'type' => Tax::escapeTypeName($object->getType()));
     // Setup the object form
     return new TaxModificationForm($this->getRequest(), "form", $data, ["tax_engine" => $this->container->get('thelia.taxEngine')]);
 }
예제 #11
0
 public function testGetUntaxedPriceAndGetTaxAmountFromTaxedPrice()
 {
     $taxRulesCollection = new ObjectCollection();
     $taxRulesCollection->setModel('\\Thelia\\Model\\Tax');
     $tax = new Tax();
     $tax->setType('\\Thelia\\TaxEngine\\TaxType\\PricePercentTaxType')->setRequirements(array('percent' => 10))->setVirtualColumn('taxRuleCountryPosition', 1);
     $taxRulesCollection->append($tax);
     $tax = new Tax();
     $tax->setType('\\Thelia\\TaxEngine\\TaxType\\PricePercentTaxType')->setRequirements(array('percent' => 8))->setVirtualColumn('taxRuleCountryPosition', 1);
     $taxRulesCollection->append($tax);
     $tax = new Tax();
     $tax->setType('\\Thelia\\TaxEngine\\TaxType\\FixAmountTaxType')->setRequirements(array('amount' => 5))->setVirtualColumn('taxRuleCountryPosition', 2);
     $taxRulesCollection->append($tax);
     $tax = new Tax();
     $tax->setType('\\Thelia\\TaxEngine\\TaxType\\PricePercentTaxType')->setRequirements(array('percent' => 1))->setVirtualColumn('taxRuleCountryPosition', 3);
     $taxRulesCollection->append($tax);
     $aProduct = ProductQuery::create()->findOne();
     if (null === $aProduct) {
         return;
     }
     $calculator = new Calculator();
     $rewritingUrlQuery = $this->getProperty('taxRulesCollection');
     $rewritingUrlQuery->setValue($calculator, $taxRulesCollection);
     $product = $this->getProperty('product');
     $product->setValue($calculator, $aProduct);
     $taxAmount = $calculator->getTaxAmountFromTaxedPrice(600.95);
     $untaxedPrice = $calculator->getUntaxedPrice(600.95);
     /*
      * expect :
      *  tax 3 = 600.95 - 600.95 / (1 + 0.01) = 5,95 // amount without tax 3 : 595
      *  tax 2 = 5 // amount without tax 2 : 590
      *  tax 1 = 590 - 590 / (1 + 0.08 + 0.10) = 90 // amount without tax 1 : 500
      * total tax amount = 100.95
      */
     $this->assertEquals(100.95, $taxAmount);
     $this->assertEquals(500, $untaxedPrice);
 }
예제 #12
0
 /**
  * Filter the query by a related \Thelia\Model\Tax object
  *
  * @param \Thelia\Model\Tax|ObjectCollection $tax The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildTaxRuleCountryQuery The current query, for fluid interface
  */
 public function filterByTax($tax, $comparison = null)
 {
     if ($tax instanceof \Thelia\Model\Tax) {
         return $this->addUsingAlias(TaxRuleCountryTableMap::TAX_ID, $tax->getId(), $comparison);
     } elseif ($tax instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(TaxRuleCountryTableMap::TAX_ID, $tax->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByTax() only accepts arguments of type \\Thelia\\Model\\Tax or Collection');
     }
 }