Example #1
0
 /**
  * Generate adapter stub
  *
  * @param int    $cartTotalPrice   Cart total price
  * @param string $checkoutCurrency Checkout currency
  * @param string $i18nOutput       Output from each translation
  *
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
 {
     $stubFacade = $this->getMockBuilder('\\Thelia\\Coupon\\BaseFacade')->disableOriginalConstructor()->getMock();
     $customer = new Customer();
     $customer->setId(10);
     $stubFacade->expects($this->any())->method('getCustomer')->will($this->returnValue($customer));
     $stubFacade->expects($this->any())->method('getConditionEvaluator')->will($this->returnValue(new ConditionEvaluator()));
     $stubTranslator = $this->getMockBuilder('\\Thelia\\Core\\Translation\\Translator')->disableOriginalConstructor()->getMock();
     $stubTranslator->expects($this->any())->method('trans')->will($this->returnValue($i18nOutput));
     $stubFacade->expects($this->any())->method('getTranslator')->will($this->returnValue($stubTranslator));
     return $stubFacade;
 }
Example #2
0
 public function testGetCartWithExistingCartAndCustomerAndReferencesEachOther()
 {
     $session = $this->session;
     //create a fake customer just for test. If not persists test fails !
     $customer = new Customer();
     $customer->setFirstname("john test session");
     $customer->setLastname("doe");
     $customer->setTitleId(1);
     $customer->save();
     $session->setCustomerUser($customer);
     $testCart = new Cart();
     $testCart->setToken(uniqid("testSessionGetCart3", true));
     $testCart->setCustomerId($customer->getId());
     $testCart->save();
     $session->setCart($testCart->getId());
     $cart = $session->getCart();
     $this->assertNotNull($cart);
     $this->assertInstanceOf("\\Thelia\\Model\\Cart", $cart, '$cart must be an instance of Thelia\\Model\\Cart');
 }
Example #3
0
 /**
  * Declares an association between this object and a ChildCustomer object.
  *
  * @param                  ChildCustomer $v
  * @return                 \Thelia\Model\CustomerVersion The current object (for fluent API support)
  * @throws PropelException
  */
 public function setCustomer(ChildCustomer $v = null)
 {
     if ($v === null) {
         $this->setId(NULL);
     } else {
         $this->setId($v->getId());
     }
     $this->aCustomer = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildCustomer object, it will not be re-added.
     if ($v !== null) {
         $v->addCustomerVersion($this);
     }
     return $this;
 }
Example #4
0
 /**
  * Retrieve the delivery country for a customer
  *
  * The rules :
  *  - the country of the delivery address of the customer related to the
  *      cart if it exists
  *  - the country saved in cookie if customer have changed
  *      the default country
  *  - the default country for the shop if it exists
  *
  *
  * @param  \Thelia\Model\Customer $customer
  * @return \Thelia\Model\Country
  */
 protected function getDeliveryInformation(Customer $customer = null)
 {
     $address = null;
     // get the selected delivery address
     if (null !== ($addressId = $this->getCurrentRequest()->getSession()->getOrder()->getChoosenDeliveryAddress())) {
         if (null !== ($address = AddressQuery::create()->findPk($addressId))) {
             $this->isCustomizable = false;
             return [$address, $address->getCountry(), null];
         }
     }
     // get country from customer addresses
     if (null !== $customer) {
         $address = AddressQuery::create()->filterByCustomerId($customer->getId())->filterByIsDefault(1)->findOne();
         if (null !== $address) {
             $this->isCustomizable = false;
             return [$address, $address->getCountry(), null];
         }
     }
     // get country from cookie
     $cookieName = ConfigQuery::read('front_cart_country_cookie_name', 'fcccn');
     if ($this->getCurrentRequest()->cookies->has($cookieName)) {
         $cookieVal = $this->getCurrentRequest()->cookies->getInt($cookieName, 0);
         if (0 !== $cookieVal) {
             $country = CountryQuery::create()->findPk($cookieVal);
             if (null !== $country) {
                 return [null, $country, null];
             }
         }
     }
     // get default country for store.
     try {
         $country = Country::getDefaultCountry();
         return [null, $country, null];
     } catch (\LogicException $e) {
     }
     return [null, null, null];
 }
Example #5
0
 /**
  * Send a message to the customer.
  *
  * @param string   $messageCode
  * @param Customer $customer
  * @param array    $messageParameters an array of (name => value) parameters that will be available in the message.
  */
 public function sendEmailToCustomer($messageCode, $customer, $messageParameters = [])
 {
     // Always add the customer ID to the parameters
     $messageParameters['customer_id'] = $customer->getId();
     $this->sendEmailMessage($messageCode, [ConfigQuery::getStoreEmail() => ConfigQuery::getStoreName()], [$customer->getEmail() => $customer->getFirstname() . " " . $customer->getLastname()], $messageParameters, $customer->getCustomerLang()->getLocale());
 }
Example #6
0
 /**
  * Filter the query by a related \Thelia\Model\Customer object
  *
  * @param \Thelia\Model\Customer|ObjectCollection $customer  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCustomerTitleQuery The current query, for fluid interface
  */
 public function filterByCustomer($customer, $comparison = null)
 {
     if ($customer instanceof \Thelia\Model\Customer) {
         return $this->addUsingAlias(CustomerTitleTableMap::ID, $customer->getTitleId(), $comparison);
     } elseif ($customer instanceof ObjectCollection) {
         return $this->useCustomerQuery()->filterByPrimaryKeys($customer->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByCustomer() only accepts arguments of type \\Thelia\\Model\\Customer or Collection');
     }
 }
Example #7
0
 private function createOrUpdateCustomer(CustomerModel $customer, CustomerCreateOrUpdateEvent $event)
 {
     $customer->setDispatcher($event->getDispatcher());
     $customer->createOrUpdate($event->getTitle(), $event->getFirstname(), $event->getLastname(), $event->getAddress1(), $event->getAddress2(), $event->getAddress3(), $event->getPhone(), $event->getCellphone(), $event->getZipcode(), $event->getCity(), $event->getCountry(), $event->getEmail(), $event->getPassword(), $event->getLang(), $event->getReseller(), $event->getSponsor(), $event->getDiscount(), $event->getCompany(), $event->getRef(), $event->getEmailUpdateAllowed());
     $event->setCustomer($customer);
 }
 /**
  * @param Customer $object
  * @return int
  */
 protected function getObjectId($object)
 {
     return $object->getId();
 }
Example #9
0
 public function testCreate()
 {
     $validDeliveryAddress = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
     $validInvoiceAddress = AddressQuery::create()->filterById($validDeliveryAddress->getId(), Criteria::NOT_EQUAL)->findOneByCustomerId($this->customer->getId());
     $deliveryModule = ModuleQuery::create()->filterByType(BaseModule::DELIVERY_MODULE_TYPE)->filterByActivate(1)->findOne();
     if (null === $deliveryModule) {
         throw new \Exception('No Delivery Module fixture found');
     }
     $paymentModule = ModuleQuery::create()->filterByType(BaseModule::PAYMENT_MODULE_TYPE)->filterByActivate(1)->findOne();
     if (null === $paymentModule) {
         throw new \Exception('No Payment Module fixture found');
     }
     /* define payment module in container */
     $paymentModuleClass = $paymentModule->getFullNamespace();
     $this->container->set(sprintf('module.%s', $paymentModule->getCode()), new $paymentModuleClass());
     $this->orderEvent->getOrder()->setChoosenDeliveryAddress($validDeliveryAddress->getId());
     $this->orderEvent->getOrder()->setChoosenInvoiceAddress($validInvoiceAddress->getId());
     $this->orderEvent->getOrder()->setDeliveryModuleId($deliveryModule->getId());
     $this->orderEvent->getOrder()->setPostage(20);
     $this->orderEvent->getOrder()->setPaymentModuleId($paymentModule->getId());
     /* memorize current stocks */
     $itemsStock = array();
     foreach ($this->cartItems as $index => $cartItem) {
         $itemsStock[$index] = $cartItem->getProductSaleElements()->getQuantity();
     }
     $this->orderAction->create($this->orderEvent);
     $placedOrder = $this->orderEvent->getPlacedOrder();
     $this->assertNotNull($placedOrder);
     $this->assertNotNull($placedOrder->getId());
     /* check customer */
     $this->assertEquals($this->customer->getId(), $placedOrder->getCustomerId(), 'customer i does not  match');
     /* check delivery address */
     $deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
     $this->assertEquals($validDeliveryAddress->getCustomerTitle()->getId(), $deliveryOrderAddress->getCustomerTitleId(), 'delivery address title does not match');
     $this->assertEquals($validDeliveryAddress->getCompany(), $deliveryOrderAddress->getCompany(), 'delivery address company does not match');
     $this->assertEquals($validDeliveryAddress->getFirstname(), $deliveryOrderAddress->getFirstname(), 'delivery address fistname does not match');
     $this->assertEquals($validDeliveryAddress->getLastname(), $deliveryOrderAddress->getLastname(), 'delivery address lastname does not match');
     $this->assertEquals($validDeliveryAddress->getAddress1(), $deliveryOrderAddress->getAddress1(), 'delivery address address1 does not match');
     $this->assertEquals($validDeliveryAddress->getAddress2(), $deliveryOrderAddress->getAddress2(), 'delivery address address2 does not match');
     $this->assertEquals($validDeliveryAddress->getAddress3(), $deliveryOrderAddress->getAddress3(), 'delivery address address3 does not match');
     $this->assertEquals($validDeliveryAddress->getZipcode(), $deliveryOrderAddress->getZipcode(), 'delivery address zipcode does not match');
     $this->assertEquals($validDeliveryAddress->getCity(), $deliveryOrderAddress->getCity(), 'delivery address city does not match');
     $this->assertEquals($validDeliveryAddress->getPhone(), $deliveryOrderAddress->getPhone(), 'delivery address phone does not match');
     $this->assertEquals($validDeliveryAddress->getCountryId(), $deliveryOrderAddress->getCountryId(), 'delivery address country does not match');
     /* check invoice address */
     $invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
     $this->assertEquals($validInvoiceAddress->getCustomerTitle()->getId(), $invoiceOrderAddress->getCustomerTitleId(), 'invoice address title does not match');
     $this->assertEquals($validInvoiceAddress->getCompany(), $invoiceOrderAddress->getCompany(), 'invoice address company does not match');
     $this->assertEquals($validInvoiceAddress->getFirstname(), $invoiceOrderAddress->getFirstname(), 'invoice address fistname does not match');
     $this->assertEquals($validInvoiceAddress->getLastname(), $invoiceOrderAddress->getLastname(), 'invoice address lastname does not match');
     $this->assertEquals($validInvoiceAddress->getAddress1(), $invoiceOrderAddress->getAddress1(), 'invoice address address1 does not match');
     $this->assertEquals($validInvoiceAddress->getAddress2(), $invoiceOrderAddress->getAddress2(), 'invoice address address2 does not match');
     $this->assertEquals($validInvoiceAddress->getAddress3(), $invoiceOrderAddress->getAddress3(), 'invoice address address3 does not match');
     $this->assertEquals($validInvoiceAddress->getZipcode(), $invoiceOrderAddress->getZipcode(), 'invoice address zipcode does not match');
     $this->assertEquals($validInvoiceAddress->getCity(), $invoiceOrderAddress->getCity(), 'invoice address city does not match');
     $this->assertEquals($validInvoiceAddress->getPhone(), $invoiceOrderAddress->getPhone(), 'invoice address phone does not match');
     $this->assertEquals($validInvoiceAddress->getCountryId(), $invoiceOrderAddress->getCountryId(), 'invoice address country does not match');
     /* check currency */
     $this->assertEquals($this->cart->getCurrencyId(), $placedOrder->getCurrencyId(), 'currency id does not  match');
     $this->assertEquals($this->cart->getCurrency()->getRate(), $placedOrder->getCurrencyRate(), 'currency rate does not  match');
     /* check delivery module */
     $this->assertEquals(20, $placedOrder->getPostage(), 'postage does not  match');
     $this->assertEquals($deliveryModule->getId(), $placedOrder->getDeliveryModuleId(), 'delivery module does not  match');
     /* check payment module */
     $this->assertEquals($paymentModule->getId(), $placedOrder->getPaymentModuleId(), 'payment module does not  match');
     /* check status */
     $this->assertEquals(OrderStatus::CODE_NOT_PAID, $placedOrder->getOrderStatus()->getCode(), 'status does not  match');
     /* check lang */
     $this->assertEquals($this->request->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not  match');
     /* check ordered product */
     foreach ($this->cartItems as $index => $cartItem) {
         $orderProduct = OrderProductQuery::create()->filterByOrderId($placedOrder->getId())->filterByProductRef($cartItem->getProduct()->getRef())->filterByProductSaleElementsRef($cartItem->getProductSaleElements()->getRef())->filterByQuantity($cartItem->getQuantity())->filterByPrice($cartItem->getPrice(), Criteria::LIKE)->filterByPromoPrice($cartItem->getPromoPrice(), Criteria::LIKE)->filterByWasNew($cartItem->getProductSaleElements()->getNewness())->filterByWasInPromo($cartItem->getPromo())->filterByWeight($cartItem->getProductSaleElements()->getWeight())->findOne();
         $this->assertNotNull($orderProduct);
         /* check attribute combinations */
         $this->assertEquals($cartItem->getProductSaleElements()->getAttributeCombinations()->count(), $orderProduct->getOrderProductAttributeCombinations()->count());
         if ($orderProduct->getVirtual()) {
             /* check same stock*/
             $this->assertEquals($itemsStock[$index], $cartItem->getProductSaleElements()->getQuantity());
         } else {
             /* check stock decrease */
             $this->assertEquals($itemsStock[$index] - $orderProduct->getQuantity(), $cartItem->getProductSaleElements()->getQuantity());
         }
         /* check tax */
         $orderProductTaxList = $orderProduct->getOrderProductTaxes();
         foreach ($cartItem->getProduct()->getTaxRule()->getTaxDetail($cartItem->getProduct(), $validDeliveryAddress->getCountry(), $cartItem->getPrice(), $cartItem->getPromoPrice()) as $index => $tax) {
             $orderProductTax = $orderProductTaxList[$index];
             $this->assertEquals($tax->getAmount(), $orderProductTax->getAmount());
             $this->assertEquals($tax->getPromoAmount(), $orderProductTax->getPromoAmount());
         }
     }
     return $placedOrder;
 }
Example #10
0
 /**
  * @depends testCreate
  * @param OrderModel $order
  * @return OrderModel
  */
 public function testCreateManual(OrderModel $order)
 {
     $orderCopy = $order->copy();
     $validDeliveryAddress = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
     $validInvoiceAddress = AddressQuery::create()->filterById($validDeliveryAddress->getId(), Criteria::NOT_EQUAL)->findOneByCustomerId($this->customer->getId());
     $orderManuelEvent = new OrderManualEvent($orderCopy, $this->cart->getCurrency(), $this->requestStack->getCurrentRequest()->getSession()->getLang(), $this->cart, $this->customer);
     $orderManuelEvent->getOrder()->setChoosenDeliveryAddress($validDeliveryAddress->getId());
     $orderManuelEvent->getOrder()->setChoosenInvoiceAddress($validInvoiceAddress->getId());
     $deliveryModuleId = $orderCopy->getDeliveryModuleId();
     $paymentModuleId = $orderCopy->getPaymentModuleId();
     $this->orderAction->createManual($orderManuelEvent, null, $this->getMockEventDispatcher());
     $placedOrder = $orderManuelEvent->getPlacedOrder();
     $this->assertNotNull($placedOrder);
     $this->assertNotNull($placedOrder->getId());
     /* check customer */
     $this->assertEquals($this->customer->getId(), $placedOrder->getCustomerId(), 'customer i does not  match');
     /* check delivery address */
     $deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
     $this->assertEquals($validDeliveryAddress->getCustomerTitle()->getId(), $deliveryOrderAddress->getCustomerTitleId(), 'delivery address title does not match');
     $this->assertEquals($validDeliveryAddress->getCompany(), $deliveryOrderAddress->getCompany(), 'delivery address company does not match');
     $this->assertEquals($validDeliveryAddress->getFirstname(), $deliveryOrderAddress->getFirstname(), 'delivery address fistname does not match');
     $this->assertEquals($validDeliveryAddress->getLastname(), $deliveryOrderAddress->getLastname(), 'delivery address lastname does not match');
     $this->assertEquals($validDeliveryAddress->getAddress1(), $deliveryOrderAddress->getAddress1(), 'delivery address address1 does not match');
     $this->assertEquals($validDeliveryAddress->getAddress2(), $deliveryOrderAddress->getAddress2(), 'delivery address address2 does not match');
     $this->assertEquals($validDeliveryAddress->getAddress3(), $deliveryOrderAddress->getAddress3(), 'delivery address address3 does not match');
     $this->assertEquals($validDeliveryAddress->getZipcode(), $deliveryOrderAddress->getZipcode(), 'delivery address zipcode does not match');
     $this->assertEquals($validDeliveryAddress->getCity(), $deliveryOrderAddress->getCity(), 'delivery address city does not match');
     $this->assertEquals($validDeliveryAddress->getPhone(), $deliveryOrderAddress->getPhone(), 'delivery address phone does not match');
     $this->assertEquals($validDeliveryAddress->getCountryId(), $deliveryOrderAddress->getCountryId(), 'delivery address country does not match');
     /* check invoice address */
     $invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
     $this->assertEquals($validInvoiceAddress->getCustomerTitle()->getId(), $invoiceOrderAddress->getCustomerTitleId(), 'invoice address title does not match');
     $this->assertEquals($validInvoiceAddress->getCompany(), $invoiceOrderAddress->getCompany(), 'invoice address company does not match');
     $this->assertEquals($validInvoiceAddress->getFirstname(), $invoiceOrderAddress->getFirstname(), 'invoice address fistname does not match');
     $this->assertEquals($validInvoiceAddress->getLastname(), $invoiceOrderAddress->getLastname(), 'invoice address lastname does not match');
     $this->assertEquals($validInvoiceAddress->getAddress1(), $invoiceOrderAddress->getAddress1(), 'invoice address address1 does not match');
     $this->assertEquals($validInvoiceAddress->getAddress2(), $invoiceOrderAddress->getAddress2(), 'invoice address address2 does not match');
     $this->assertEquals($validInvoiceAddress->getAddress3(), $invoiceOrderAddress->getAddress3(), 'invoice address address3 does not match');
     $this->assertEquals($validInvoiceAddress->getZipcode(), $invoiceOrderAddress->getZipcode(), 'invoice address zipcode does not match');
     $this->assertEquals($validInvoiceAddress->getCity(), $invoiceOrderAddress->getCity(), 'invoice address city does not match');
     $this->assertEquals($validInvoiceAddress->getPhone(), $invoiceOrderAddress->getPhone(), 'invoice address phone does not match');
     $this->assertEquals($validInvoiceAddress->getCountryId(), $invoiceOrderAddress->getCountryId(), 'invoice address country does not match');
     /* check currency */
     $this->assertEquals($this->cart->getCurrencyId(), $placedOrder->getCurrencyId(), 'currency id does not  match');
     $this->assertEquals($this->cart->getCurrency()->getRate(), $placedOrder->getCurrencyRate(), 'currency rate does not  match');
     /* check delivery module */
     $this->assertEquals(20, $placedOrder->getPostage(), 'postage does not  match');
     $this->assertEquals($deliveryModuleId, $placedOrder->getDeliveryModuleId(), 'delivery module does not  match');
     /* check payment module */
     $this->assertEquals($paymentModuleId, $placedOrder->getPaymentModuleId(), 'payment module does not  match');
     /* check status */
     $this->assertEquals(OrderStatus::CODE_NOT_PAID, $placedOrder->getOrderStatus()->getCode(), 'status does not  match');
     /* check lang */
     $this->assertEquals($this->requestStack->getCurrentRequest()->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not  match');
     // without address duplication
     $copyOrder = $order->copy();
     $orderManuelEvent->setOrder($copyOrder)->setUseOrderDefinedAddresses(true);
     $validDeliveryAddressId = $orderCopy->getDeliveryOrderAddressId();
     $validInvoiceAddressId = $orderCopy->getInvoiceOrderAddressId();
     $this->orderAction->createManual($orderManuelEvent, null, $this->getMockEventDispatcher());
     $placedOrder = $orderManuelEvent->getPlacedOrder();
     $this->assertNotNull($placedOrder);
     $this->assertNotNull($placedOrder->getId());
     /* check delivery address */
     $deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
     $this->assertEquals($validDeliveryAddressId, $deliveryOrderAddress->getId(), 'delivery address title does not match');
     /* check invoice address */
     $invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
     $this->assertEquals($validInvoiceAddressId, $invoiceOrderAddress->getId(), 'invoice address title does not match');
     return $placedOrder;
 }
Example #11
0
 protected function createOrder(EventDispatcherInterface $dispatcher, ModelOrder $sessionOrder, CurrencyModel $currency, LangModel $lang, CartModel $cart, CustomerModel $customer)
 {
     $con = \Propel\Runtime\Propel::getConnection(OrderTableMap::DATABASE_NAME);
     $con->beginTransaction();
     $placedOrder = $sessionOrder->copy();
     $placedOrder->setDispatcher($dispatcher);
     $deliveryAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenDeliveryAddress());
     $taxCountry = $deliveryAddress->getCountry();
     $invoiceAddress = AddressQuery::create()->findPk($sessionOrder->getChoosenInvoiceAddress());
     $cartItems = $cart->getCartItems();
     /* fulfill order */
     $placedOrder->setCustomerId($customer->getId());
     $placedOrder->setCurrencyId($currency->getId());
     $placedOrder->setCurrencyRate($currency->getRate());
     $placedOrder->setLangId($lang->getId());
     /* hard save the delivery and invoice addresses */
     $deliveryOrderAddress = new OrderAddress();
     $deliveryOrderAddress->setCustomerTitleId($deliveryAddress->getTitleId())->setCompany($deliveryAddress->getCompany())->setFirstname($deliveryAddress->getFirstname())->setLastname($deliveryAddress->getLastname())->setAddress1($deliveryAddress->getAddress1())->setAddress2($deliveryAddress->getAddress2())->setAddress3($deliveryAddress->getAddress3())->setZipcode($deliveryAddress->getZipcode())->setCity($deliveryAddress->getCity())->setPhone($deliveryAddress->getPhone())->setCountryId($deliveryAddress->getCountryId())->save($con);
     $invoiceOrderAddress = new OrderAddress();
     $invoiceOrderAddress->setCustomerTitleId($invoiceAddress->getTitleId())->setCompany($invoiceAddress->getCompany())->setFirstname($invoiceAddress->getFirstname())->setLastname($invoiceAddress->getLastname())->setAddress1($invoiceAddress->getAddress1())->setAddress2($invoiceAddress->getAddress2())->setAddress3($invoiceAddress->getAddress3())->setZipcode($invoiceAddress->getZipcode())->setCity($invoiceAddress->getCity())->setPhone($invoiceAddress->getPhone())->setCountryId($invoiceAddress->getCountryId())->save($con);
     $placedOrder->setDeliveryOrderAddressId($deliveryOrderAddress->getId());
     $placedOrder->setInvoiceOrderAddressId($invoiceOrderAddress->getId());
     $placedOrder->setStatusId(OrderStatusQuery::getNotPaidStatus()->getId());
     $placedOrder->setCart($cart);
     /* memorize discount */
     $placedOrder->setDiscount($cart->getDiscount());
     $placedOrder->save($con);
     /* fulfill order_products and decrease stock */
     foreach ($cartItems as $cartItem) {
         $product = $cartItem->getProduct();
         /* get translation */
         $productI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'Product', $product->getId());
         $pse = $cartItem->getProductSaleElements();
         /* check still in stock */
         if ($cartItem->getQuantity() > $pse->getQuantity() && true === ConfigQuery::checkAvailableStock() && 0 === $product->getVirtual()) {
             throw new TheliaProcessException("Not enough stock", TheliaProcessException::CART_ITEM_NOT_ENOUGH_STOCK, $cartItem);
         }
         if (0 === $product->getVirtual()) {
             /* decrease stock for non virtual product */
             $allowNegativeStock = intval(ConfigQuery::read('allow_negative_stock', 0));
             $newStock = $pse->getQuantity() - $cartItem->getQuantity();
             //Forbid negative stock
             if ($newStock < 0 && 0 === $allowNegativeStock) {
                 $newStock = 0;
             }
             $pse->setQuantity($newStock);
             $pse->save($con);
         }
         /* get tax */
         $taxRuleI18n = I18n::forceI18nRetrieving($lang->getLocale(), 'TaxRule', $product->getTaxRuleId());
         $taxDetail = $product->getTaxRule()->getTaxDetail($product, $taxCountry, $cartItem->getPrice(), $cartItem->getPromoPrice(), $lang->getLocale());
         // get the virtual document path
         $virtualDocumentPath = null;
         if ($product->getVirtual() === 1) {
             // try to find the associated document
             if (null !== ($documentId = MetaDataQuery::getVal('virtual', MetaDataModel::PSE_KEY, $pse->getId()))) {
                 $productDocument = ProductDocumentQuery::create()->findPk($documentId);
                 if (null !== $productDocument) {
                     $virtualDocumentPath = $productDocument->getFile();
                 }
             }
         }
         $orderProduct = new OrderProduct();
         $orderProduct->setOrderId($placedOrder->getId())->setProductRef($product->getRef())->setProductSaleElementsRef($pse->getRef())->setProductSaleElementsId($pse->getId())->setTitle($productI18n->getTitle())->setChapo($productI18n->getChapo())->setDescription($productI18n->getDescription())->setPostscriptum($productI18n->getPostscriptum())->setVirtual($product->getVirtual())->setVirtualDocument($virtualDocumentPath)->setQuantity($cartItem->getQuantity())->setPrice($cartItem->getPrice())->setPromoPrice($cartItem->getPromoPrice())->setWasNew($pse->getNewness())->setWasInPromo($cartItem->getPromo())->setWeight($pse->getWeight())->setTaxRuleTitle($taxRuleI18n->getTitle())->setTaxRuleDescription($taxRuleI18n->getDescription())->setEanCode($pse->getEanCode())->setCartIemId($cartItem->getId())->setDispatcher($dispatcher)->save($con);
         /* fulfill order_product_tax */
         foreach ($taxDetail as $tax) {
             $tax->setOrderProductId($orderProduct->getId());
             $tax->save($con);
         }
         /* fulfill order_attribute_combination and decrease stock */
         foreach ($pse->getAttributeCombinations() as $attributeCombination) {
             $attribute = I18n::forceI18nRetrieving($lang->getLocale(), 'Attribute', $attributeCombination->getAttributeId());
             $attributeAv = I18n::forceI18nRetrieving($lang->getLocale(), 'AttributeAv', $attributeCombination->getAttributeAvId());
             $orderAttributeCombination = new OrderProductAttributeCombination();
             $orderAttributeCombination->setOrderProductId($orderProduct->getId())->setAttributeTitle($attribute->getTitle())->setAttributeChapo($attribute->getChapo())->setAttributeDescription($attribute->getDescription())->setAttributePostscriptum($attribute->getPostscriptum())->setAttributeAvTitle($attributeAv->getTitle())->setAttributeAvChapo($attributeAv->getChapo())->setAttributeAvDescription($attributeAv->getDescription())->setAttributeAvPostscriptum($attributeAv->getPostscriptum())->save($con);
         }
     }
     $con->commit();
     return $placedOrder;
 }
 /**
  * @covers CustomerGroupAclTool::checkAcl()
  *
  * @param CustomerGroup $customerGroup Group to test.
  * @param Customer $customer Customer to use for the test.
  * @param array $expectedRessourceAccesses A map of [expected resource => [expected accesses...], ...].
  */
 protected function doTestCheckAclCustomerWithGroup(CustomerGroup $customerGroup, Customer $customer, $expectedRessourceAccesses)
 {
     // add the customer to the test group
     $addCustomerToGroupEvent = new AddCustomerToCustomerGroupEvent();
     $addCustomerToGroupEvent->setCustomerId($customer->getId())->setCustomerGroupId($customerGroup->getId());
     $this->dispatcher->dispatch(CustomerGroupEvents::ADD_CUSTOMER_TO_CUSTOMER_GROUP, $addCustomerToGroupEvent);
     // login the customer
     $this->dispatcher->dispatch(TheliaEvents::CUSTOMER_LOGIN, new CustomerLoginEvent($customer));
     // assert its accesses
     $this->assertGroupOnlyHasTheseAccesses($expectedRessourceAccesses);
     // assert it twice to also test the ACL checking cache
     $this->assertGroupOnlyHasTheseAccesses($expectedRessourceAccesses);
 }
Example #13
0
 /**
  * Customer is connected but cart not associated to him
  *
  * A new cart must be created (duplicated) containing customer id
  */
 public function testGetCartWithExistingCartAndCustomerButNotSameCustomerId()
 {
     $cartTrait = $this->cartTrait;
     $request = $this->request;
     //create a fake customer just for test. If not persists test fails !
     $customer = new Customer();
     $customer->setFirstname("john");
     $customer->setLastname("doe");
     $customer->setTitleId(1);
     $customer->save();
     $uniqid = uniqid("test3", true);
     //create a fake cart in database;
     $cart = new Cart();
     $cart->setToken($uniqid);
     $cart->save();
     $request->cookies->set("thelia_cart", $uniqid);
     $request->getSession()->setCustomerUser($customer);
     $getCart = $cartTrait->getCart($this->dispatcher, $request);
     $this->assertInstanceOf("Thelia\\Model\\Cart", $getCart, '$cart must be an instance of cart model Thelia\\Model\\Cart');
     $this->assertNotNull($getCart->getCustomerId());
     $this->assertNull($getCart->getAddressDeliveryId());
     $this->assertNull($getCart->getAddressInvoiceId());
     $this->assertNotEquals($cart->getToken(), $getCart->getToken(), "token must be different");
     $this->assertEquals($customer->getId(), $getCart->getCustomerId());
 }
 /**
  * @param Customer $customer
  * @return CustomerUpdateForm
  */
 protected function hydrateCustomerForm(Customer $customer)
 {
     // Get default adress of the customer
     $address = $customer->getDefaultAddress();
     // Prepare the data that will hydrate the form
     $data = array('id' => $customer->getId(), 'firstname' => $customer->getFirstname(), 'lastname' => $customer->getLastname(), 'email' => $customer->getEmail(), 'title' => $customer->getTitleId(), 'discount' => $customer->getDiscount(), 'reseller' => $customer->getReseller());
     if ($address !== null) {
         $data['company'] = $address->getCompany();
         $data['address1'] = $address->getAddress1();
         $data['address2'] = $address->getAddress2();
         $data['address3'] = $address->getAddress3();
         $data['phone'] = $address->getPhone();
         $data['cellphone'] = $address->getCellphone();
         $data['zipcode'] = $address->getZipcode();
         $data['city'] = $address->getCity();
         $data['country'] = $address->getCountryId();
     }
     // A loop is used in the template
     return new CustomerUpdateForm($this->getRequest(), 'form', $data);
 }
Example #15
0
 /**
  * Filter the query by a related \Thelia\Model\Customer object
  *
  * @param \Thelia\Model\Customer|ObjectCollection $customer The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildCartQuery The current query, for fluid interface
  */
 public function filterByCustomer($customer, $comparison = null)
 {
     if ($customer instanceof \Thelia\Model\Customer) {
         return $this->addUsingAlias(CartTableMap::CUSTOMER_ID, $customer->getId(), $comparison);
     } elseif ($customer instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(CartTableMap::CUSTOMER_ID, $customer->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByCustomer() only accepts arguments of type \\Thelia\\Model\\Customer or Collection');
     }
 }
Example #16
0
 /**
  * Exclude object from result
  *
  * @param   ChildCustomer $customer Object to remove from the list of results
  *
  * @return ChildCustomerQuery The current query, for fluid interface
  */
 public function prune($customer = null)
 {
     if ($customer) {
         $this->addUsingAlias(CustomerTableMap::ID, $customer->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
Example #17
0
 /**
  * Sets the properties of the current object to the value they had at a specific version
  *
  * @param ChildOrderVersion $version The version object to use
  * @param ConnectionInterface   $con the connection to use
  * @param array                 $loadedObjects objects that been loaded in a chain of populateFromVersion calls on referrer or fk objects.
  *
  * @return ChildOrder The current object (for fluent API support)
  */
 public function populateFromVersion($version, $con = null, &$loadedObjects = array())
 {
     $loadedObjects['ChildOrder'][$version->getId()][$version->getVersion()] = $this;
     $this->setId($version->getId());
     $this->setRef($version->getRef());
     $this->setCustomerId($version->getCustomerId());
     $this->setInvoiceOrderAddressId($version->getInvoiceOrderAddressId());
     $this->setDeliveryOrderAddressId($version->getDeliveryOrderAddressId());
     $this->setInvoiceDate($version->getInvoiceDate());
     $this->setCurrencyId($version->getCurrencyId());
     $this->setCurrencyRate($version->getCurrencyRate());
     $this->setTransactionRef($version->getTransactionRef());
     $this->setDeliveryRef($version->getDeliveryRef());
     $this->setInvoiceRef($version->getInvoiceRef());
     $this->setDiscount($version->getDiscount());
     $this->setPostage($version->getPostage());
     $this->setPostageTax($version->getPostageTax());
     $this->setPostageTaxRuleTitle($version->getPostageTaxRuleTitle());
     $this->setPaymentModuleId($version->getPaymentModuleId());
     $this->setDeliveryModuleId($version->getDeliveryModuleId());
     $this->setStatusId($version->getStatusId());
     $this->setLangId($version->getLangId());
     $this->setCartId($version->getCartId());
     $this->setCreatedAt($version->getCreatedAt());
     $this->setUpdatedAt($version->getUpdatedAt());
     $this->setVersion($version->getVersion());
     $this->setVersionCreatedAt($version->getVersionCreatedAt());
     $this->setVersionCreatedBy($version->getVersionCreatedBy());
     if ($fkValue = $version->getCustomerId()) {
         if (isset($loadedObjects['ChildCustomer']) && isset($loadedObjects['ChildCustomer'][$fkValue]) && isset($loadedObjects['ChildCustomer'][$fkValue][$version->getCustomerIdVersion()])) {
             $related = $loadedObjects['ChildCustomer'][$fkValue][$version->getCustomerIdVersion()];
         } else {
             $related = new ChildCustomer();
             $relatedVersion = ChildCustomerVersionQuery::create()->filterById($fkValue)->filterByVersion($version->getCustomerIdVersion())->findOne($con);
             $related->populateFromVersion($relatedVersion, $con, $loadedObjects);
             $related->setNew(false);
         }
         $this->setCustomer($related);
     }
     return $this;
 }
 /**
  * @return Customer
  */
 public static function createShoppingFluxCustomer()
 {
     $shoppingFluxCustomer = CustomerQuery::create()->findOneByRef("ShoppingFlux");
     if (null === $shoppingFluxCustomer) {
         $shoppingFluxCustomer = new Customer();
         $shoppingFluxCustomer->setRef("ShoppingFlux")->setCustomerTitle(CustomerTitleQuery::create()->findOne())->setLastname("ShoppingFlux")->setFirstname("ShoppingFlux")->save();
     }
     return $shoppingFluxCustomer;
 }
Example #19
0
 /**
  * Retrieve the delivery country for a customer
  *
  * The rules :
  *  - the country of the delivery address of the customer related to the
  *      cart if it exists
  *  - the country saved in cookie if customer have changed
  *      the default country
  *  - the default country for the shop if it exists
  *
  *
  * @param  \Thelia\Model\Customer $customer
  * @return \Thelia\Model\Country
  */
 protected function getDeliveryCountry(Customer $customer = null)
 {
     // get country from customer addresses
     if (null !== $customer) {
         $address = AddressQuery::create()->filterByCustomerId($customer->getId())->filterByIsDefault(1)->findOne();
         if (null !== $address) {
             $this->isCustomizable = false;
             return $address->getCountry();
         }
     }
     // get country from cookie
     $cookieName = ConfigQuery::read('front_cart_country_cookie_name', 'fcccn');
     if ($this->request->cookies->has($cookieName)) {
         $cookieVal = $this->request->cookies->getInt($cookieName, 0);
         if (0 !== $cookieVal) {
             $country = CountryQuery::create()->findPk($cookieVal);
             if (null !== $country) {
                 return $country;
             }
         }
     }
     // get default country for store.
     try {
         $country = Country::getDefaultCountry();
         return $country;
     } catch (\LogicException $e) {
     }
     return null;
 }
 /**
  * Declares an association between this object and a ChildCustomer object.
  *
  * @param                  ChildCustomer $v
  * @return                 \CustomerBirthDate\Model\CustomerBirthDate The current object (for fluent API support)
  * @throws PropelException
  */
 public function setCustomer(ChildCustomer $v = null)
 {
     if ($v === null) {
         $this->setId(NULL);
     } else {
         $this->setId($v->getId());
     }
     $this->aCustomer = $v;
     // Add binding for other direction of this 1:1 relationship.
     if ($v !== null) {
         $v->setCustomerBirthDate($this);
     }
     return $this;
 }