Ejemplo n.º 1
0
 /**
  * @param TaxRuleEvent $event
  */
 public function create(TaxRuleEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $taxRule = new TaxRuleModel();
     $taxRule->setDispatcher($dispatcher)->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription());
     $taxRule->save();
     $event->setTaxRule($taxRule)->setId($taxRule->getId());
 }
Ejemplo n.º 2
0
 /**
  * @param TaxRuleEvent $event
  */
 public function create(TaxRuleEvent $event)
 {
     $taxRule = new TaxRuleModel();
     $taxRule->setDispatcher($event->getDispatcher())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription());
     $taxRule->save();
     $event->setTaxRule($taxRule)->setId($taxRule->getId());
 }
Ejemplo n.º 3
0
 /**
  * @param TaxRule $taxRule
  * @param Country $country
  *
  * @return array|mixed|\Propel\Runtime\Collection\ObjectCollection
  */
 public function getTaxCalculatorCollection(TaxRule $taxRule, Country $country, State $state = null)
 {
     $key = sprintf('%s-%s-%s', $taxRule->getId(), $country->getId(), $state !== null ? $state->getId() : 0);
     if (array_key_exists($key, self::$caches)) {
         return self::$caches[$key];
     }
     $taxRuleQuery = TaxRuleCountryQuery::create()->filterByCountry($country, Criteria::EQUAL)->filterByTaxRuleId($taxRule->getId());
     if (null !== $state) {
         $taxRuleCount = $taxRuleQuery->filterByStateId($state->getId(), Criteria::EQUAL)->count();
         if (0 === $taxRuleCount) {
             $taxRuleQuery->filterByStateId(null, Criteria::EQUAL);
         }
     }
     $search = TaxQuery::create()->filterByTaxRuleCountry($taxRuleQuery->find())->withColumn(TaxRuleCountryTableMap::POSITION, self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION)->orderBy(self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION, Criteria::ASC);
     return self::$caches[$key] = $search->find();
 }
Ejemplo n.º 4
0
 public function loadTaxRuleWithoutProduct(TaxRule $taxRule, Country $country)
 {
     $this->product = null;
     $this->country = null;
     $this->taxRulesCollection = null;
     if ($taxRule->getId() === null) {
         throw new TaxEngineException('TaxRule id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_TAX_RULE);
     }
     if ($country->getId() === null) {
         throw new TaxEngineException('Country id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_COUNTRY);
     }
     $this->country = $country;
     $this->product = new Product();
     $this->taxRulesCollection = $this->taxRuleQuery->getTaxCalculatorCollection($taxRule, $country);
     return $this;
 }
Ejemplo n.º 5
0
 public function loadTaxRule(TaxRule $taxRule, Country $country, Product $product)
 {
     $this->product = null;
     $this->country = null;
     $this->taxRulesCollection = null;
     if ($taxRule->getId() === null) {
         throw new TaxEngineException('TaxRule id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_TAX_RULE);
     }
     if ($country->getId() === null) {
         throw new TaxEngineException('Country id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_COUNTRY);
     }
     if ($product->getId() === null) {
         throw new TaxEngineException('Product id is empty in Calculator::loadTaxRule', TaxEngineException::UNDEFINED_PRODUCT);
     }
     $this->country = $country;
     $this->product = $product;
     $key = $product->getTaxRule()->getId() . '-' . $country->getId();
     if (!isset(self::$taxRulesMap[$key])) {
         self::$taxRulesMap[$key] = $this->taxRuleQuery->getTaxCalculatorCollection($taxRule, $country);
     }
     $this->taxRulesCollection = self::$taxRulesMap[$key];
     return $this;
 }
Ejemplo n.º 6
0
 /**
  * @param TaxRule $object
  * @return int
  */
 protected function getObjectId($object)
 {
     return $object->getId();
 }
Ejemplo n.º 7
0
 /**
  * Declares an association between this object and a ChildTaxRule object.
  *
  * @param                  ChildTaxRule $v
  * @return                 \Thelia\Model\Product The current object (for fluent API support)
  * @throws PropelException
  */
 public function setTaxRule(ChildTaxRule $v = null)
 {
     if ($v === null) {
         $this->setTaxRuleId(NULL);
     } else {
         $this->setTaxRuleId($v->getId());
     }
     $this->aTaxRule = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildTaxRule object, it will not be re-added.
     if ($v !== null) {
         $v->addProduct($this);
     }
     return $this;
 }
Ejemplo n.º 8
0
 /**
  * Filter the query by a related \Thelia\Model\TaxRule object
  *
  * @param \Thelia\Model\TaxRule|ObjectCollection $taxRule The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildProductQuery The current query, for fluid interface
  */
 public function filterByTaxRule($taxRule, $comparison = null)
 {
     if ($taxRule instanceof \Thelia\Model\TaxRule) {
         return $this->addUsingAlias(ProductTableMap::TAX_RULE_ID, $taxRule->getId(), $comparison);
     } elseif ($taxRule instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(ProductTableMap::TAX_RULE_ID, $taxRule->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByTaxRule() only accepts arguments of type \\Thelia\\Model\\TaxRule or Collection');
     }
 }
Ejemplo n.º 9
0
 /**
  * @param TaxRule $taxRule
  * @param Country $country
  *
  * @return array|mixed|\Propel\Runtime\Collection\ObjectCollection
  */
 public function getTaxCalculatorCollection(TaxRule $taxRule, Country $country)
 {
     $search = TaxQuery::create()->filterByTaxRuleCountry(TaxRuleCountryQuery::create()->filterByCountry($country, Criteria::EQUAL)->filterByTaxRuleId($taxRule->getId())->orderByPosition()->find())->withColumn(TaxRuleCountryTableMap::POSITION, self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION)->orderBy(self::ALIAS_FOR_TAX_RULE_COUNTRY_POSITION, Criteria::ASC);
     return $search->find();
 }
Ejemplo n.º 10
0
 /**
  * Exclude object from result
  *
  * @param   ChildTaxRule $taxRule Object to remove from the list of results
  *
  * @return ChildTaxRuleQuery The current query, for fluid interface
  */
 public function prune($taxRule = null)
 {
     if ($taxRule) {
         $this->addUsingAlias(TaxRuleTableMap::ID, $taxRule->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }