Esempio n. 1
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;
 }
Esempio n. 2
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;
 }
Esempio n. 3
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');
     }
 }
Esempio n. 4
0
 /**
  * Declares an association between this object and a ChildCustomer object.
  *
  * @param                  ChildCustomer $v
  * @return                 \Thelia\Model\Order The current object (for fluent API support)
  * @throws PropelException
  */
 public function setCustomer(ChildCustomer $v = null)
 {
     if ($v === null) {
         $this->setCustomerId(NULL);
     } else {
         $this->setCustomerId($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->addOrder($this);
     }
     return $this;
 }
Esempio n. 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());
 }
Esempio n. 6
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];
 }
Esempio n. 7
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;
 }
Esempio n. 8
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;
 }
Esempio n. 9
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);
 }
 /**
  * @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);
 }
 /**
  * @param Customer $object
  * @return int
  */
 protected function getObjectId($object)
 {
     return $object->getId();
 }
 /**
  * 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;
 }