/**
  * Exclude object from result
  *
  * @param   ChildOrderCoupon $orderCoupon Object to remove from the list of results
  *
  * @return ChildOrderCouponQuery The current query, for fluid interface
  */
 public function prune($orderCoupon = null)
 {
     if ($orderCoupon) {
         $this->addUsingAlias(OrderCouponTableMap::ID, $orderCoupon->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Exemple #2
0
 /**
  * @param \Thelia\Core\Event\Order\OrderEvent $event
  *
  * @throws \Exception if something goes wrong.
  */
 public function afterOrder(OrderEvent $event)
 {
     $consumedCoupons = $this->request->getSession()->getConsumedCoupons();
     if (is_array($consumedCoupons)) {
         $con = Propel::getWriteConnection(OrderCouponTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             foreach ($consumedCoupons as $couponCode) {
                 $couponQuery = CouponQuery::create();
                 $couponModel = $couponQuery->findOneByCode($couponCode);
                 $couponModel->setLocale($this->request->getSession()->getLang()->getLocale());
                 /* decrease coupon quantity */
                 $this->couponManager->decrementQuantity($couponModel, $event->getOrder()->getCustomerId());
                 /* memorize coupon */
                 $orderCoupon = new OrderCoupon();
                 $orderCoupon->setOrder($event->getOrder())->setCode($couponModel->getCode())->setType($couponModel->getType())->setAmount($couponModel->getAmount())->setTitle($couponModel->getTitle())->setShortDescription($couponModel->getShortDescription())->setDescription($couponModel->getDescription())->setExpirationDate($couponModel->getExpirationDate())->setIsCumulative($couponModel->getIsCumulative())->setIsRemovingPostage($couponModel->getIsRemovingPostage())->setIsAvailableOnSpecialOffers($couponModel->getIsAvailableOnSpecialOffers())->setSerializedConditions($couponModel->getSerializedConditions())->setPerCustomerUsageCount($couponModel->getPerCustomerUsageCount());
                 $orderCoupon->save();
                 // Copy order coupon free shipping data for countries and modules
                 $couponCountries = CouponCountryQuery::create()->filterByCouponId($couponModel->getId())->find();
                 /** @var CouponCountry $couponCountry */
                 foreach ($couponCountries as $couponCountry) {
                     $occ = new OrderCouponCountry();
                     $occ->setCouponId($orderCoupon->getId())->setCountryId($couponCountry->getCountryId())->save();
                 }
                 $couponModules = CouponModuleQuery::create()->filterByCouponId($couponModel->getId())->find();
                 /** @var CouponModule $couponModule */
                 foreach ($couponModules as $couponModule) {
                     $ocm = new OrderCouponModule();
                     $ocm->setCouponId($orderCoupon->getId())->setModuleId($couponModule->getModuleId())->save();
                 }
             }
             $con->commit();
         } catch (\Exception $ex) {
             $con->rollBack();
             throw $ex;
         }
     }
     // Clear all coupons.
     $event->getDispatcher()->dispatch(TheliaEvents::COUPON_CLEAR_ALL);
 }
Exemple #3
0
 /**
  * Declares an association between this object and a ChildOrderCoupon object.
  *
  * @param                  ChildOrderCoupon $v
  * @return                 \Thelia\Model\OrderCouponModule The current object (for fluent API support)
  * @throws PropelException
  */
 public function setOrderCoupon(ChildOrderCoupon $v = null)
 {
     if ($v === null) {
         $this->setCouponId(NULL);
     } else {
         $this->setCouponId($v->getId());
     }
     $this->aOrderCoupon = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildOrderCoupon object, it will not be re-added.
     if ($v !== null) {
         $v->addOrderCouponModule($this);
     }
     return $this;
 }
Exemple #4
0
 /**
  * Filter the query by a related \Thelia\Model\OrderCoupon object
  *
  * @param \Thelia\Model\OrderCoupon|ObjectCollection $orderCoupon  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildOrderQuery The current query, for fluid interface
  */
 public function filterByOrderCoupon($orderCoupon, $comparison = null)
 {
     if ($orderCoupon instanceof \Thelia\Model\OrderCoupon) {
         return $this->addUsingAlias(OrderTableMap::ID, $orderCoupon->getOrderId(), $comparison);
     } elseif ($orderCoupon instanceof ObjectCollection) {
         return $this->useOrderCouponQuery()->filterByPrimaryKeys($orderCoupon->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByOrderCoupon() only accepts arguments of type \\Thelia\\Model\\OrderCoupon or Collection');
     }
 }
 /**
  * Filter the query by a related \Thelia\Model\OrderCoupon object
  *
  * @param \Thelia\Model\OrderCoupon|ObjectCollection $orderCoupon The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildOrderCouponModuleQuery The current query, for fluid interface
  */
 public function filterByOrderCoupon($orderCoupon, $comparison = null)
 {
     if ($orderCoupon instanceof \Thelia\Model\OrderCoupon) {
         return $this->addUsingAlias(OrderCouponModuleTableMap::COUPON_ID, $orderCoupon->getId(), $comparison);
     } elseif ($orderCoupon instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(OrderCouponModuleTableMap::COUPON_ID, $orderCoupon->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByOrderCoupon() only accepts arguments of type \\Thelia\\Model\\OrderCoupon or Collection');
     }
 }
Exemple #6
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);
 }