Example #1
0
 /**
  * @param TaxRuleEvent $event
  */
 public function updateTaxes(TaxRuleEvent $event)
 {
     if (null !== ($taxRule = TaxRuleQuery::create()->findPk($event->getId()))) {
         $taxList = $this->getArrayFromJson($event->getTaxList());
         $countryList = $this->getArrayFromJson22Compat($event->getCountryList());
         $countryDeletedList = $this->getArrayFromJson22Compat($event->getCountryDeletedList());
         /* clean the current tax rule for the countries/states */
         $deletes = array_merge($countryList, $countryDeletedList);
         foreach ($deletes as $item) {
             TaxRuleCountryQuery::create()->filterByTaxRule($taxRule)->filterByCountryId(intval($item[0]), Criteria::EQUAL)->filterByStateId(intval($item[1]) !== 0 ? $item[1] : null, Criteria::EQUAL)->delete();
         }
         /* for each country */
         foreach ($countryList as $item) {
             $position = 1;
             $countryId = intval($item[0]);
             $stateId = intval($item[1]);
             /* on applique les nouvelles regles */
             foreach ($taxList as $tax) {
                 if (is_array($tax)) {
                     foreach ($tax as $samePositionTax) {
                         $taxModel = new TaxRuleCountry();
                         $taxModel->setTaxRule($taxRule)->setCountryId($countryId)->setStateId($stateId ?: null)->setTaxId($samePositionTax)->setPosition($position);
                         $taxModel->save();
                     }
                 } else {
                     $taxModel = new TaxRuleCountry();
                     $taxModel->setTaxRule($taxRule)->setCountryId($countryId)->setStateId($stateId ?: null)->setTaxId($tax)->setPosition($position);
                     $taxModel->save();
                 }
                 $position++;
             }
         }
         $event->setTaxRule($taxRule);
     }
 }
Example #2
0
 /**
  * @param TaxRuleEvent $event
  */
 public function updateTaxes(TaxRuleEvent $event)
 {
     if (null !== ($taxRule = TaxRuleQuery::create()->findPk($event->getId()))) {
         if (!is_array($taxList = $event->getTaxList())) {
             $taxList = json_decode($taxList, true);
         }
         /* clean the current tax rule for the countries */
         TaxRuleCountryQuery::create()->filterByTaxRule($taxRule)->filterByCountryId($event->getCountryList(), Criteria::IN)->delete();
         /* for each country */
         foreach ($event->getCountryList() as $country) {
             $position = 1;
             /* on applique les nouvelles regles */
             foreach ($taxList as $tax) {
                 if (is_array($tax)) {
                     foreach ($tax as $samePositionTax) {
                         $taxModel = new TaxRuleCountry();
                         $taxModel->setTaxRule($taxRule)->setCountryId($country)->setTaxId($samePositionTax)->setPosition($position);
                         $taxModel->save();
                     }
                 } else {
                     $taxModel = new TaxRuleCountry();
                     $taxModel->setTaxRule($taxRule)->setCountryId($country)->setTaxId($tax)->setPosition($position);
                     $taxModel->save();
                 }
                 $position++;
             }
         }
         $event->setTaxRule($taxRule);
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database. In some cases you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by find*()
  * and findPk*() calls.
  *
  * @param \Thelia\Model\TaxRuleCountry $obj A \Thelia\Model\TaxRuleCountry object.
  * @param string $key             (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if (null === $key) {
             $key = serialize(array((string) $obj->getTaxRuleId(), (string) $obj->getCountryId(), (string) $obj->getTaxId()));
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Example #4
0
 /**
  * Filter the query by a related \Thelia\Model\TaxRuleCountry object
  *
  * @param \Thelia\Model\TaxRuleCountry|ObjectCollection $taxRuleCountry  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCountryQuery The current query, for fluid interface
  */
 public function filterByTaxRuleCountry($taxRuleCountry, $comparison = null)
 {
     if ($taxRuleCountry instanceof \Thelia\Model\TaxRuleCountry) {
         return $this->addUsingAlias(CountryTableMap::ID, $taxRuleCountry->getCountryId(), $comparison);
     } elseif ($taxRuleCountry instanceof ObjectCollection) {
         return $this->useTaxRuleCountryQuery()->filterByPrimaryKeys($taxRuleCountry->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByTaxRuleCountry() only accepts arguments of type \\Thelia\\Model\\TaxRuleCountry or Collection');
     }
 }
Example #5
0
 /**
  * Exclude object from result
  *
  * @param   ChildTaxRuleCountry $taxRuleCountry Object to remove from the list of results
  *
  * @return ChildTaxRuleCountryQuery The current query, for fluid interface
  */
 public function prune($taxRuleCountry = null)
 {
     if ($taxRuleCountry) {
         $this->addCond('pruneCond0', $this->getAliasedColName(TaxRuleCountryTableMap::TAX_RULE_ID), $taxRuleCountry->getTaxRuleId(), Criteria::NOT_EQUAL);
         $this->addCond('pruneCond1', $this->getAliasedColName(TaxRuleCountryTableMap::COUNTRY_ID), $taxRuleCountry->getCountryId(), Criteria::NOT_EQUAL);
         $this->addCond('pruneCond2', $this->getAliasedColName(TaxRuleCountryTableMap::TAX_ID), $taxRuleCountry->getTaxId(), Criteria::NOT_EQUAL);
         $this->combine(array('pruneCond0', 'pruneCond1', 'pruneCond2'), Criteria::LOGICAL_OR);
     }
     return $this;
 }
Example #6
0
 /**
  * Exclude object from result
  *
  * @param   ChildTaxRuleCountry $taxRuleCountry Object to remove from the list of results
  *
  * @return ChildTaxRuleCountryQuery The current query, for fluid interface
  */
 public function prune($taxRuleCountry = null)
 {
     if ($taxRuleCountry) {
         $this->addUsingAlias(TaxRuleCountryTableMap::ID, $taxRuleCountry->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }