public function testSetOrderCurrency()
 {
     $currency = 'USD';
     $this->localeSettings->expects($this->once())->method('getCurrency')->willReturn($currency);
     $order = new Order();
     $this->handler->setOrderCurrency($order);
     $this->assertEquals($currency, $order->getCurrency());
 }
 protected function setUp()
 {
     $this->orderCurrencyHandler = $this->getMockBuilder('OroB2B\\Bundle\\OrderBundle\\Model\\OrderCurrencyHandler')->disableOriginalConstructor()->getMock();
     $this->orderCurrencyHandler->expects($this->any())->method('setOrderCurrency')->willReturnCallback(function (Order $order) {
         $order->setCurrency(self::CURRENCY);
     });
     $this->subtotalsProvider = $this->getMockBuilder('OroB2B\\Bundle\\OrderBundle\\Provider\\SubtotalsProvider')->disableOriginalConstructor()->getMock();
     $this->converter = new QuoteToOrderConverter($this->orderCurrencyHandler, $this->subtotalsProvider);
 }
 protected function setUp()
 {
     $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock();
     $this->provider = $this->getMockBuilder('OroB2B\\Bundle\\OrderBundle\\Provider\\OrderAddressSecurityProvider')->disableOriginalConstructor()->getMock();
     $this->paymentTermProvider = $this->getMockBuilder('OroB2B\\Bundle\\PaymentBundle\\Provider\\PaymentTermProvider')->disableOriginalConstructor()->getMock();
     $this->orderCurrencyHandler = $this->getMockBuilder('OroB2B\\Bundle\\OrderBundle\\Model\\OrderCurrencyHandler')->disableOriginalConstructor()->getMock();
     $this->orderCurrencyHandler->expects($this->any())->method('setOrderCurrency')->will($this->returnCallback(function ($order) {
         if ($order instanceof Order) {
             $order->setCurrency('USD');
         }
     }));
     $this->type = new OrderType($this->securityFacade, $this->provider, $this->paymentTermProvider, $this->orderCurrencyHandler);
 }
 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     /** @var Order $order */
     $order = $options['data'];
     $this->orderCurrencyHandler->setOrderCurrency($order);
     $builder->add('poNumber', 'text', ['required' => false, 'label' => 'orob2b.order.po_number.label'])->add('shipUntil', OroDateType::NAME, ['required' => false, 'label' => 'orob2b.order.ship_until.label'])->add('customerNotes', 'textarea', ['required' => false, 'label' => 'orob2b.order.customer_notes.frontend.label'])->add('lineItems', OrderLineItemsCollectionType::NAME, ['type' => FrontendOrderLineItemType::NAME, 'add_label' => 'orob2b.order.orderlineitem.add_label', 'cascade_validation' => true, 'options' => ['currency' => $order->getCurrency()]]);
     if ($this->orderAddressSecurityProvider->isAddressGranted($order, AddressType::TYPE_BILLING)) {
         $builder->add('billingAddress', OrderAddressType::NAME, ['label' => 'orob2b.order.billing_address.label', 'order' => $options['data'], 'required' => false, 'addressType' => AddressType::TYPE_BILLING]);
     }
     if ($this->orderAddressSecurityProvider->isAddressGranted($order, AddressType::TYPE_SHIPPING)) {
         $builder->add('shippingAddress', OrderAddressType::NAME, ['label' => 'orob2b.order.shipping_address.label', 'order' => $options['data'], 'required' => false, 'addressType' => AddressType::TYPE_SHIPPING]);
     }
     $builder->addEventListener(FormEvents::SUBMIT, [$this, 'updateLineItemPrices']);
 }
Example #5
0
 /**
  * {@inheritDoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     /** @var Order $order */
     $order = $options['data'];
     $this->orderCurrencyHandler->setOrderCurrency($order);
     $builder->add('account', AccountSelectType::NAME, ['label' => 'orob2b.order.account.label', 'required' => true])->add('accountUser', AccountUserSelectType::NAME, ['label' => 'orob2b.order.account_user.label', 'required' => false])->add('poNumber', 'text', ['required' => false, 'label' => 'orob2b.order.po_number.label'])->add('shipUntil', OroDateType::NAME, ['required' => false, 'label' => 'orob2b.order.ship_until.label'])->add('customerNotes', 'textarea', ['required' => false, 'label' => 'orob2b.order.customer_notes.label'])->add('priceList', PriceListSelectType::NAME, ['required' => false, 'label' => 'orob2b.order.price_list.label'])->add('currency', 'hidden')->add('lineItems', OrderLineItemsCollectionType::NAME, ['add_label' => 'orob2b.order.orderlineitem.add_label', 'cascade_validation' => true, 'options' => ['currency' => $order->getCurrency()]]);
     if ($this->orderAddressSecurityProvider->isAddressGranted($order, AddressType::TYPE_BILLING)) {
         $builder->add('billingAddress', OrderAddressType::NAME, ['label' => 'orob2b.order.billing_address.label', 'order' => $options['data'], 'required' => false, 'addressType' => AddressType::TYPE_BILLING]);
     }
     if ($this->orderAddressSecurityProvider->isAddressGranted($order, AddressType::TYPE_SHIPPING)) {
         $builder->add('shippingAddress', OrderAddressType::NAME, ['label' => 'orob2b.order.shipping_address.label', 'order' => $options['data'], 'required' => false, 'addressType' => AddressType::TYPE_SHIPPING]);
     }
     if ($this->isOverridePaymentTermGranted()) {
         $builder->add('paymentTerm', PaymentTermSelectType::NAME, ['label' => 'orob2b.order.payment_term.label', 'required' => false, 'attr' => ['data-account-payment-term' => $this->getAccountPaymentTermId($order), 'data-account-group-payment-term' => $this->getAccountGroupPaymentTermId($order)]]);
     }
 }
 /**
  * @param Quote $quote
  * @param AccountUser|null $user
  * @param array|null $selectedOffers
  * @return Order
  */
 public function convert(Quote $quote, AccountUser $user = null, array $selectedOffers = null)
 {
     $accountUser = $user ?: $quote->getAccountUser();
     $account = $user ? $user->getAccount() : $quote->getAccount();
     $order = new Order();
     $order->setAccount($account)->setAccountUser($accountUser)->setOwner($quote->getOwner())->setOrganization($quote->getOrganization());
     if (!$selectedOffers) {
         foreach ($quote->getQuoteProducts() as $quoteProduct) {
             /** @var QuoteProductOffer $productOffer */
             $productOffer = $quoteProduct->getQuoteProductOffers()->first();
             $order->addLineItem($this->createOrderLineItem($productOffer));
         }
     } else {
         foreach ($selectedOffers as $selectedOffer) {
             /** @var QuoteProductOffer $offer */
             $offer = $selectedOffer[self::FIELD_OFFER];
             $order->addLineItem($this->createOrderLineItem($offer, (double) $selectedOffer[self::FIELD_QUANTITY]));
         }
     }
     $this->orderCurrencyHandler->setOrderCurrency($order);
     $this->fillSubtotals($order);
     return $order;
 }