예제 #1
0
 /**
  * Exclude object from result
  *
  * @param   ChildOrderProductTax $orderProductTax Object to remove from the list of results
  *
  * @return ChildOrderProductTaxQuery The current query, for fluid interface
  */
 public function prune($orderProductTax = null)
 {
     if ($orderProductTax) {
         $this->addUsingAlias(OrderProductTaxTableMap::ID, $orderProductTax->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
예제 #2
0
 /**
  * Filter the query by a related \Thelia\Model\OrderProductTax object
  *
  * @param \Thelia\Model\OrderProductTax|ObjectCollection $orderProductTax  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildOrderProductQuery The current query, for fluid interface
  */
 public function filterByOrderProductTax($orderProductTax, $comparison = null)
 {
     if ($orderProductTax instanceof \Thelia\Model\OrderProductTax) {
         return $this->addUsingAlias(OrderProductTableMap::ID, $orderProductTax->getOrderProductId(), $comparison);
     } elseif ($orderProductTax instanceof ObjectCollection) {
         return $this->useOrderProductTaxQuery()->filterByPrimaryKeys($orderProductTax->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByOrderProductTax() only accepts arguments of type \\Thelia\\Model\\OrderProductTax or Collection');
     }
 }
예제 #3
0
 /**
  * @param      $untaxedPrice
  * @param null $taxCollection returns OrderProductTaxCollection
  * @param null $askedLocale
  *
  * @return int
  * @throws \Thelia\Exception\TaxEngineException
  */
 public function getTaxedPrice($untaxedPrice, &$taxCollection = null, $askedLocale = null)
 {
     if (null === $this->taxRulesCollection) {
         throw new TaxEngineException('Tax rules collection is empty in Calculator::getTaxedPrice', TaxEngineException::UNDEFINED_TAX_RULES_COLLECTION);
     }
     if (null === $this->product) {
         throw new TaxEngineException('Product is empty in Calculator::getTaxedPrice', TaxEngineException::UNDEFINED_PRODUCT);
     }
     if (false === filter_var($untaxedPrice, FILTER_VALIDATE_FLOAT)) {
         throw new TaxEngineException('BAD AMOUNT FORMAT', TaxEngineException::BAD_AMOUNT_FORMAT);
     }
     $taxedPrice = $untaxedPrice;
     $currentPosition = 1;
     $currentTax = 0;
     if (null !== $taxCollection) {
         $taxCollection = new OrderProductTaxCollection();
     }
     foreach ($this->taxRulesCollection as $taxRule) {
         $position = (int) $taxRule->getTaxRuleCountryPosition();
         $taxType = $taxRule->getTypeInstance();
         if ($currentPosition !== $position) {
             $taxedPrice += $currentTax;
             $currentTax = 0;
             $currentPosition = $position;
         }
         $taxAmount = $taxType->calculate($this->product, $taxedPrice);
         $currentTax += $taxAmount;
         if (null !== $taxCollection) {
             $taxI18n = I18n::forceI18nRetrieving($askedLocale, 'Tax', $taxRule->getId());
             $orderProductTax = new OrderProductTax();
             $orderProductTax->setTitle($taxI18n->getTitle());
             $orderProductTax->setDescription($taxI18n->getDescription());
             $orderProductTax->setAmount($taxAmount);
             $taxCollection->addTax($orderProductTax);
         }
     }
     $taxedPrice += $currentTax;
     return $taxedPrice;
 }
예제 #4
0
 public function import($startRecord = 0)
 {
     $count = 0;
     $errors = 0;
     $hdl = $this->t1db->query(sprintf("select * from commande order by id asc limit %d, %d", intval($startRecord), $this->getChunkSize()));
     while ($hdl && ($commande = $this->t1db->fetch_object($hdl))) {
         $count++;
         try {
             $this->order_corresp->getT2($commande->id);
             Tlog::getInstance()->warning("Order ID={$commande->id} already imported.");
             continue;
         } catch (ImportException $ex) {
             // Okay, the order was not imported.
         }
         try {
             if (null === ($customer = CustomerQuery::create()->findPk($this->cust_corresp->getT2($commande->client)))) {
                 throw new ImportException("Failed to find customer ID={$commande->client}");
             }
             if (null === ($status = OrderStatusQuery::create()->findPk($commande->statut))) {
                 throw new ImportException("Failed to find order status ID={$commande->statut}");
             }
             // Create invoice address
             if (false == ($adr_livr = $this->t1db->query_obj("select * from venteadr where id=?", array($commande->adrlivr)))) {
                 throw new ImportException("Failed to find delivery adresse ID={$commande->adrlivr}");
             }
             // Create invoice address
             if (false == ($adr_fact = $this->t1db->query_obj("select * from venteadr where id=?", array($commande->adrfact)))) {
                 throw new ImportException("Failed to find billing adresse ID={$commande->adrfact}");
             }
             $con = Propel::getConnection(OrderTableMap::DATABASE_NAME);
             $con->beginTransaction();
             try {
                 $order = new Order();
                 $delivery_adr = new OrderAddress();
                 $delivery_adr->setCustomerTitleId($this->getT2CustomerTitle($adr_livr->raison)->getId())->setCompany(isset($adr_livr->entreprise) ? $adr_livr->entreprise : '')->setFirstname($adr_livr->prenom)->setLastname($adr_livr->nom)->setAddress1($adr_livr->adresse1)->setAddress2($adr_livr->adresse2)->setAddress3($adr_livr->adresse3)->setZipcode($adr_livr->cpostal)->setCity($adr_livr->ville)->setPhone($adr_livr->tel)->setCountryId($this->getT2Country($adr_livr->pays)->getId())->save($con);
                 $billing_adr = new OrderAddress();
                 $billing_adr->setCustomerTitleId($this->getT2CustomerTitle($adr_fact->raison)->getId())->setCompany(isset($adr_fact->entreprise) ? $adr_fact->entreprise : '')->setFirstname($adr_fact->prenom)->setLastname($adr_fact->nom)->setAddress1($adr_fact->adresse1)->setAddress2($adr_fact->adresse2)->setAddress3($adr_fact->adresse3)->setZipcode($adr_fact->cpostal)->setCity($adr_fact->ville)->setPhone($adr_fact->tel)->setCountryId($this->getT2Country($adr_fact->pays)->getId())->save($con);
                 // Find the first availables delivery and payment modules, that's the best we can do.
                 $deliveryModule = ModuleQuery::create()->findOneByType(BaseModule::DELIVERY_MODULE_TYPE);
                 $paymentModule = ModuleQuery::create()->findOneByType(BaseModule::PAYMENT_MODULE_TYPE);
                 // Create a cart (now required)
                 $cart = new Cart();
                 $cart->save();
                 $order->setRef($commande->ref)->setCustomer($customer)->setInvoiceDate($commande->datefact)->setCurrency($this->getT2Currency($commande->devise))->setCurrencyRate($this->getT2Currency($commande->devise)->getRate())->setTransactionRef($commande->transaction)->setDeliveryRef($commande->livraison)->setInvoiceRef($commande->facture)->setPostage($commande->port)->setStatusId($status->getId())->setLang($this->getT2Lang($commande->lang))->setDeliveryOrderAddressId($delivery_adr->getId())->setInvoiceOrderAddressId($billing_adr->getId())->setDeliveryModuleId($deliveryModule->getId())->setPaymentModuleId($paymentModule->getId())->setDiscount($commande->remise)->setCartId($cart->getId())->save($con);
                 // Update the order reference
                 $order->setRef($commande->ref)->setCreatedAt($commande->date)->save();
                 if ($commande->remise > 0) {
                     $coupon = new OrderCoupon();
                     $coupon->setOrder($order)->setCode('Not Available')->setType('UNKNOWN')->setAmount($commande->remise)->setTitle('Imported from Thelia 1')->setShortDescription('Imported from Thelia 1')->setDescription('Imported from Thelia 1')->setExpirationDate(time())->setIsCumulative(false)->setIsRemovingPostage(false)->setIsAvailableOnSpecialOffers(false)->setSerializedConditions(new ConditionCollection(array()))->save($con);
                 }
                 $vps = $this->t1db->query_list("select * from venteprod where commande=?", array($commande->id));
                 foreach ($vps as $vp) {
                     $parent = 0;
                     if (isset($vp->parent) && $vp->parent != 0) {
                         $parent = $this->product_corresp->getT2($vp->parent);
                     }
                     $orderProduct = new OrderProduct();
                     $orderProduct->setOrder($order)->setProductRef($vp->ref)->setProductSaleElementsRef($vp->ref)->setTitle($vp->titre)->setChapo($vp->chapo)->setDescription($vp->description)->setPostscriptum("")->setQuantity($vp->quantite)->setPrice($vp->prixu / (1 + $vp->tva / 100))->setPromoPrice($vp->prixu / (1 + $vp->tva / 100))->setWasNew(false)->setWasInPromo(false)->setWeight(0)->setEanCode("")->setTaxRuleTitle("")->setTaxRuleDescription("")->setParent($parent)->save($con);
                     $orderProductTax = new OrderProductTax();
                     $orderProductTax->setAmount($orderProduct->getPrice() * ($vp->tva / 100))->setPromoAmount(0)->setOrderProduct($orderProduct)->setTitle("TVA {$vp->tva} %")->setDescription("TVA {$vp->tva} %")->save($con);
                 }
                 $con->commit();
             } catch (\Exception $ex) {
                 $con->rollBack();
                 throw $ex;
             }
         } catch (\Exception $ex) {
             Tlog::getInstance()->addError("Failed to import order ref {$commande->ref}: ", $ex->getMessage());
             $errors++;
         }
     }
     return new ImportChunkResult($count, $errors);
 }