/**
  * @dataProvider notIsValidDataProvider
  * @param $data
  * @param $result
  */
 public function testNotIsValid($data, $result)
 {
     $provider = $this->getMockForAbstractClass('Magento\\Checkout\\Model\\Agreements\\AgreementsProviderInterface');
     $provider->expects($this->once())->method('getRequiredAgreementIds')->will($this->returnValue([1, 3, '4']));
     $this->object = $this->objectManagerHelper->getObject('Magento\\Checkout\\Model\\Agreements\\AgreementsValidator', ['list' => [$provider]]);
     $this->assertEquals($result, $this->object->isValid($data));
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function placeOrder($cartId, $agreements = null, PaymentInterface $paymentMethod = null)
 {
     if (!$this->agreementsValidator->isValid($agreements)) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Please agree to all the terms and conditions before placing the order.'));
     }
     $quote = $this->quoteRepository->getActive($cartId);
     if ($paymentMethod) {
         $paymentMethod->setChecks([\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_CHECKOUT, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX, \Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL]);
         $quote->getPayment()->setQuote($quote);
         $data = $paymentMethod->getData();
         if (isset($data['additional_data'])) {
             $data = array_merge($data, (array) $data['additional_data']);
             unset($data['additional_data']);
         }
         $quote->getPayment()->importData($data);
     }
     if ($quote->getCheckoutMethod() === self::METHOD_GUEST) {
         $quote->setCustomerId(null);
         $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
         $quote->setCustomerIsGuest(true);
         $quote->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID);
     }
     $order = $this->submit($quote);
     $this->checkoutSession->setLastQuoteId($quote->getId());
     $this->checkoutSession->setLastSuccessQuoteId($quote->getId());
     $this->checkoutSession->setLastOrderId($order->getId());
     $this->checkoutSession->setLastRealOrderId($order->getIncrementId());
     $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]);
     return $order->getId();
 }