예제 #1
1
 /**
  * Fetch quote totals data
  *
  * @param Quote $quote
  * @return array
  */
 public function map(Quote $quote)
 {
     $totals = [Totals::BASE_GRAND_TOTAL => $quote->getBaseGrandTotal(), Totals::GRAND_TOTAL => $quote->getGrandTotal(), Totals::BASE_SUBTOTAL => $quote->getBaseSubtotal(), Totals::SUBTOTAL => $quote->getSubtotal(), Totals::BASE_SUBTOTAL_WITH_DISCOUNT => $quote->getBaseSubtotalWithDiscount(), Totals::SUBTOTAL_WITH_DISCOUNT => $quote->getSubtotalWithDiscount(), Totals::BASE_CURRENCY_CODE => $quote->getBaseCurrencyCode(), Totals::QUOTE_CURRENCY_CODE => $quote->getQuoteCurrencyCode()];
     $shippingAddress = $quote->getShippingAddress();
     $totals[Totals::DISCOUNT_AMOUNT] = $shippingAddress->getDiscountAmount();
     $totals[Totals::BASE_DISCOUNT_AMOUNT] = $shippingAddress->getBaseDiscountAmount();
     $totals[Totals::SHIPPING_AMOUNT] = $shippingAddress->getShippingAmount();
     $totals[Totals::BASE_SHIPPING_AMOUNT] = $shippingAddress->getBaseShippingAmount();
     $totals[Totals::SHIPPING_DISCOUNT_AMOUNT] = $shippingAddress->getShippingDiscountAmount();
     $totals[Totals::BASE_SHIPPING_DISCOUNT_AMOUNT] = $shippingAddress->getBaseShippingDiscountAmount();
     $totals[Totals::TAX_AMOUNT] = $shippingAddress->getTaxAmount();
     $totals[Totals::BASE_TAX_AMOUNT] = $shippingAddress->getBaseTaxAmount();
     $totals[Totals::SHIPPING_TAX_AMOUNT] = $shippingAddress->getShippingTaxAmount();
     $totals[Totals::BASE_SHIPPING_TAX_AMOUNT] = $shippingAddress->getBaseShippingTaxAmount();
     $totals[Totals::SUBTOTAL_INCL_TAX] = $shippingAddress->getSubtotalInclTax();
     $totals[Totals::BASE_SUBTOTAL_INCL_TAX] = $shippingAddress->getBaseSubtotalTotalInclTax();
     $totals[Totals::SHIPPING_INCL_TAX] = $shippingAddress->getShippingInclTax();
     $totals[Totals::BASE_SHIPPING_INCL_TAX] = $shippingAddress->getBaseShippingInclTax();
     return $totals;
 }
예제 #2
0
 protected function setUp()
 {
     $this->markTestIncomplete();
     $this->messageManager = $this->getMockForAbstractClass('Magento\\Framework\\Message\\ManagerInterface');
     $this->config = $this->getMock('Magento\\Paypal\\Model\\Config', [], [], '', false);
     $this->request = $this->getMock('Magento\\Framework\\App\\Request\\Http', [], [], '', false);
     $this->quote = $this->getMock('Magento\\Sales\\Model\\Quote', [], [], '', false);
     $this->quote->expects($this->any())->method('hasItems')->will($this->returnValue(true));
     $this->redirect = $this->getMockForAbstractClass('Magento\\Framework\\App\\Response\\RedirectInterface');
     $this->response = $this->getMock('Magento\\Framework\\App\\Response\\Http', [], [], '', false);
     $this->customerData = $this->getMock('Magento\\Customer\\Service\\V1\\Data\\Customer', [], [], '', false);
     $this->checkout = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout', [], [], '', false);
     $this->customerSession = $this->getMock('Magento\\Customer\\Model\\Session', [], [], '', false);
     $this->customerSession->expects($this->any())->method('getCustomerDataObject')->will($this->returnValue($this->customerData));
     $this->checkoutSession = $this->getMock('Magento\\Checkout\\Model\\Session', [], [], '', false);
     $this->checkoutFactory = $this->getMock('Magento\\Paypal\\Model\\Express\\Checkout\\Factory', [], [], '', false);
     $this->checkoutFactory->expects($this->any())->method('create')->will($this->returnValue($this->checkout));
     $this->checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote));
     $this->session = $this->getMock('Magento\\Framework\\Session\\Generic', [], [], '', false);
     $objectManager = $this->getMock('Magento\\Framework\\ObjectManager', [], [], '', false);
     $this->objectManagerCallback = function ($className) {
         if ($className == 'Magento\\Paypal\\Model\\Config') {
             return $this->config;
         }
         return $this->getMock($className, [], [], '', false);
     };
     $objectManager->expects($this->any())->method('get')->will($this->returnCallback(function ($className) {
         return call_user_func($this->objectManagerCallback, $className);
     }));
     $objectManager->expects($this->any())->method('create')->will($this->returnCallback(function ($className) {
         return call_user_func($this->objectManagerCallback, $className);
     }));
     $helper = new ObjectManagerHelper($this);
     $this->model = $helper->getObject('\\Magento\\\\Paypal\\Controller\\Express\\' . $this->name, ['messageManager' => $this->messageManager, 'response' => $this->response, 'redirect' => $this->redirect, 'request' => $this->request, 'customerSession' => $this->customerSession, 'checkoutSession' => $this->checkoutSession, 'checkoutFactory' => $this->checkoutFactory, 'paypalSession' => $this->session, 'objectManager' => $objectManager]);
 }
예제 #3
0
 /**
  * Check quote amount
  *
  * @param \Magento\Sales\Model\Quote $quote
  * @param float $amount
  * @return $this
  */
 public function checkQuoteAmount(\Magento\Sales\Model\Quote $quote, $amount)
 {
     if (!$quote->getHasError() && $amount >= self::MAXIMUM_AVAILABLE_NUMBER) {
         $quote->setHasError(true);
         $quote->addMessage(__('This item price or quantity is not valid for checkout.'));
     }
     return $this;
 }
예제 #4
0
파일: Filter.php 프로젝트: aiesh/magento2
 /**
  * Whether there are items with recurring payment
  *
  * @param \Magento\Sales\Model\Quote $quote
  * @return bool
  */
 public function hasRecurringItems(Quote $quote)
 {
     foreach ($quote->getAllVisibleItems() as $item) {
         if ($item->getProduct() && $item->getProduct()->getIsRecurring()) {
             return true;
         }
     }
     return false;
 }
예제 #5
0
 protected function setUp()
 {
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['convertPrice', '__wakeup'])->getMock();
     $this->quote = $this->getMockBuilder('Magento\\Sales\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getStore', '__wakeup'])->getMock();
     $this->quote->expects($this->once())->method('getStore')->will($this->returnValue($this->store));
     $checkoutSession = $this->getMockBuilder('\\Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods(['getQuote', '__wakeup'])->getMock();
     $checkoutSession->expects($this->once())->method('getQuote')->will($this->returnValue($this->quote));
     $this->priceObj = $objectManager->getObject('\\Magento\\Checkout\\Block\\Shipping\\Price', ['checkoutSession' => $checkoutSession]);
 }
예제 #6
0
 /**
  * Check whether payment method is applicable to quote
  *
  * @param PaymentMethodChecksInterface $paymentMethod
  * @param \Magento\Sales\Model\Quote $quote
  * @return bool
  */
 public function isApplicable(PaymentMethodChecksInterface $paymentMethod, Quote $quote)
 {
     $total = $quote->getBaseGrandTotal();
     $minTotal = $paymentMethod->getConfigData(self::MIN_ORDER_TOTAL);
     $maxTotal = $paymentMethod->getConfigData(self::MAX_ORDER_TOTAL);
     if (!empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) {
         return false;
     }
     return true;
 }
예제 #7
0
 public function setUp()
 {
     $objectManager = new ObjectManager($this);
     $this->taxConfig = $this->getMockBuilder('\\Magento\\Tax\\Model\\Config')->disableOriginalConstructor()->setMethods(['getShippingTaxClass', 'shippingPriceIncludesTax'])->getMock();
     $this->store = $this->getMockBuilder('\\Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['__wakeup'])->getMock();
     $this->quote = $this->getMockBuilder('\\Magento\\Sales\\Model\\Quote')->disableOriginalConstructor()->setMethods(['__wakeup', 'getStore'])->getMock();
     $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
     $this->address = $this->getMockBuilder('\\Magento\\Sales\\Model\\Quote\\Address')->disableOriginalConstructor()->setMethods(['__wakeup', 'getQuote'])->getMock();
     $this->address->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote));
     $this->commonTaxCollector = $objectManager->getObject('Magento\\Tax\\Model\\Sales\\Total\\Quote\\CommonTaxCollector', ['taxConfig' => $this->taxConfig]);
 }
예제 #8
0
파일: CartTest.php 프로젝트: aiesh/magento2
 /**
  * Gets \Magento\Sales\Model\Quote\Item from \Magento\Sales\Model\Quote by product id
  *
  * @param \Magento\Sales\Model\Quote $quote
  * @param mixed $productId
  * @return \Magento\Sales\Model\Quote\Item|null
  */
 private function _getQuoteItemIdByProductId(\Magento\Sales\Model\Quote $quote, $productId)
 {
     /** @var $quoteItems \Magento\Sales\Model\Quote\Item[] */
     $quoteItems = $quote->getAllItems();
     foreach ($quoteItems as $quoteItem) {
         if ($productId == $quoteItem->getProductId()) {
             return $quoteItem;
         }
     }
     return null;
 }
예제 #9
0
 protected function setUp()
 {
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->store = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->setMethods(['convertPrice', '__wakeup'])->getMock();
     $this->quote = $this->getMockBuilder('Magento\\Sales\\Model\\Quote')->disableOriginalConstructor()->setMethods(['getStore', '__wakeup', 'getCustomerTaxClassId'])->getMock();
     $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($this->store));
     $checkoutSession = $this->getMockBuilder('\\Magento\\Checkout\\Model\\Session')->disableOriginalConstructor()->setMethods(['getQuote', '__wakeup'])->getMock();
     $checkoutSession->expects($this->any())->method('getQuote')->will($this->returnValue($this->quote));
     $this->taxHelper = $this->getMockBuilder('\\Magento\\Tax\\Helper\\Data')->disableOriginalConstructor()->setMethods(['getShippingPrice', 'displayShippingPriceIncludingTax', 'displayShippingBothPrices'])->getMock();
     $this->priceObj = $objectManager->getObject('\\Magento\\Tax\\Block\\Checkout\\Shipping\\Price', ['checkoutSession' => $checkoutSession, 'taxHelper' => $this->taxHelper]);
 }
예제 #10
0
 public function testInitWithNonDecimalQty()
 {
     $quoteItemMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Item', ['getStockId', 'getIsQtyDecimal', '__wakeup'], [], '', false);
     $this->stockItemServiceMock->expects($this->once())->method('getStockItem')->will($this->returnValue($this->getStockItemDo(false)));
     $this->productMock->expects($this->once())->method('getId')->will($this->returnSelf());
     $this->productMock->expects($this->never())->method('setIsQtyDecimal');
     $this->productMock->expects($this->once())->method('setCartQty')->will($this->returnSelf());
     $this->configMock->expects($this->exactly(2))->method('getQty')->will($this->returnValue(10));
     $this->configMock->expects($this->once())->method('setQty')->will($this->returnSelf());
     $this->quoteMock->expects($this->once())->method('addProduct')->will($this->returnValue($quoteItemMock));
     $this->assertInstanceOf('Magento\\Sales\\Model\\Quote\\Item', $this->model->init($this->quoteMock, $this->productMock, $this->configMock));
 }
예제 #11
0
 /**
  * @param \Magento\Sales\Model\Quote $quote
  * @param \Magento\Catalog\Model\Product $product
  * @param \Magento\Framework\Object $config
  * @return \Magento\Sales\Model\Quote\Item|string
  */
 public function init(\Magento\Sales\Model\Quote $quote, \Magento\Catalog\Model\Product $product, \Magento\Framework\Object $config)
 {
     /** @var \Magento\CatalogInventory\Service\V1\Data\StockItem $stockItemDo */
     $stockItemDo = $this->stockItemService->getStockItem($product->getId());
     if ($stockItemDo->getStockId() && $stockItemDo->getIsQtyDecimal()) {
         $product->setIsQtyDecimal(1);
     } else {
         $config->setQty((int) $config->getQty());
     }
     $product->setCartQty($config->getQty());
     $item = $quote->addProduct($product, $config, \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL);
     return $item;
 }
예제 #12
0
 /**
  * @param \Magento\Sales\Model\Quote $quote
  * @return \Magento\Payment\Model\MethodInterface[]
  */
 public function getAvailableMethods(\Magento\Sales\Model\Quote $quote = null)
 {
     $store = $quote ? $quote->getStoreId() : null;
     $methods = array();
     $specification = $this->methodSpecificationFactory->create(array(AbstractMethod::CHECK_ZERO_TOTAL));
     foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
         if ($this->_canUseMethod($method, $quote) && $specification->isApplicable($method, $quote)) {
             $method->setInfoInstance($quote->getPayment());
             $methods[] = $method;
         }
     }
     return $methods;
 }
예제 #13
0
 /**
  * Loads customer, quote and quote item by request params
  *
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _initData()
 {
     $this->_customerId = (int) $this->getRequest()->getParam('customer_id');
     if (!$this->_customerId) {
         throw new \Magento\Framework\Model\Exception(__('No customer ID defined.'));
     }
     $quoteItemId = (int) $this->getRequest()->getParam('id');
     $websiteId = (int) $this->getRequest()->getParam('website_id');
     $this->_quote = $this->_objectManager->create('Magento\\Sales\\Model\\Quote')->setWebsite($this->_objectManager->get('Magento\\Framework\\StoreManagerInterface')->getWebsite($websiteId))->loadByCustomer($this->_customerId);
     $this->_quoteItem = $this->_quote->getItemById($quoteItemId);
     if (!$this->_quoteItem) {
         throw new Exception(__('Please correct the quote items and try again.'));
     }
     return $this;
 }
예제 #14
0
 /**
  * @param array $giftMessages
  * @param \Magento\Sales\Model\Quote $quote
  * @return $this
  */
 public function add($giftMessages, $quote)
 {
     if (!is_array($giftMessages)) {
         return $this;
     }
     // types are 'quote', 'quote_item', etc
     foreach ($giftMessages as $type => $giftMessageEntities) {
         foreach ($giftMessageEntities as $entityId => $message) {
             $giftMessage = $this->messageFactory->create();
             switch ($type) {
                 case 'quote':
                     $entity = $quote;
                     break;
                 case 'quote_item':
                     $entity = $quote->getItemById($entityId);
                     break;
                 case 'quote_address':
                     $entity = $quote->getAddressById($entityId);
                     break;
                 case 'quote_address_item':
                     $entity = $quote->getAddressById($message['address'])->getItemById($entityId);
                     break;
                 default:
                     $entity = $quote;
                     break;
             }
             if ($entity->getGiftMessageId()) {
                 $giftMessage->load($entity->getGiftMessageId());
             }
             if (trim($message['message']) == '') {
                 if ($giftMessage->getId()) {
                     try {
                         $giftMessage->delete();
                         $entity->setGiftMessageId(0)->save();
                     } catch (\Exception $e) {
                     }
                 }
                 continue;
             }
             try {
                 $giftMessage->setSender($message['from'])->setRecipient($message['to'])->setMessage($message['message'])->save();
                 $entity->setGiftMessageId($giftMessage->getId())->save();
             } catch (\Exception $e) {
             }
         }
     }
     return $this;
 }
예제 #15
0
 /**
  * Prepare recurring payments
  *
  * @param \Magento\Sales\Model\Quote $quote
  * @throws \Exception
  * @return array
  */
 public function import(\Magento\Sales\Model\Quote $quote)
 {
     if (!$quote->getTotalsCollectedFlag()) {
         throw new \Exception('Quote totals must be collected before this operation.');
     }
     $result = array();
     foreach ($quote->getAllVisibleItems() as $item) {
         $product = $item->getProduct();
         if (is_object($product) && $product->getIsRecurring() && ($payment = $this->_paymentFactory->create()->importProduct($product))) {
             $payment->importQuote($quote);
             $payment->importQuoteItem($item);
             $result[] = $payment;
         }
     }
     return $result;
 }
예제 #16
0
 /**
  * Retrieve payment method and assign additional template values
  *
  * @return $this
  */
 protected function _beforeToHtml()
 {
     $methodInstance = $this->_quote->getPayment()->getMethodInstance();
     $this->setPaymentMethodTitle($methodInstance->getTitle());
     $this->setShippingRateRequired(true);
     if ($this->_quote->getIsVirtual()) {
         $this->setShippingRateRequired(false);
     } else {
         // prepare shipping rates
         $this->_address = $this->_quote->getShippingAddress();
         $groups = $this->_address->getGroupedAllShippingRates();
         if ($groups && $this->_address) {
             $this->setShippingRateGroups($groups);
             // determine current selected code & name
             foreach ($groups as $code => $rates) {
                 foreach ($rates as $rate) {
                     if ($this->_address->getShippingMethod() == $rate->getCode()) {
                         $this->_currentShippingRate = $rate;
                         break 2;
                     }
                 }
             }
         }
         $canEditShippingAddress = $this->_quote->getMayEditShippingAddress() && $this->_quote->getPayment()->getAdditionalInformation(\Magento\Paypal\Model\Express\Checkout::PAYMENT_INFO_BUTTON) == 1;
         // misc shipping parameters
         $this->setShippingMethodSubmitUrl($this->getUrl("{$this->_controllerPath}/saveShippingMethod"))->setCanEditShippingAddress($canEditShippingAddress)->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod());
     }
     $this->setEditUrl($this->getUrl("{$this->_controllerPath}/edit"))->setPlaceOrderUrl($this->getUrl("{$this->_controllerPath}/placeOrder"));
     return parent::_beforeToHtml();
 }
예제 #17
0
파일: Quote.php 프로젝트: aiesh/magento2
 /**
  * Get rid of all nominal items
  *
  * @return void
  */
 protected function _deleteNominalItems()
 {
     foreach ($this->_quote->getAllVisibleItems() as $item) {
         if ($item->isNominal()) {
             $item->isDeleted(true);
         }
     }
 }
예제 #18
0
 public function testValidateMiniumumAmountNegative()
 {
     $storeId = 1;
     $this->quote->setStoreId($storeId);
     $valueMap = [['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true], ['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true], ['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20], ['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true]];
     $this->scopeConfig->expects($this->any())->method('isSetFlag')->will($this->returnValueMap($valueMap));
     $this->quoteAddressMock->expects($this->once())->method('validateMinimumAmount')->willReturn(false);
     $this->quoteAddressCollectionMock->expects($this->once())->method('setQuoteFilter')->willReturn([$this->quoteAddressMock]);
     $this->assertFalse($this->quote->validateMinimumAmount());
 }
예제 #19
0
 /**
  * @covers \Magento\SalesRule\Model\Rule\Action\Discount\CartFixed::calculate
  */
 public function testCalculate()
 {
     $this->rule->setData(array('id' => 1, 'discount_amount' => 10.0));
     $this->address->expects($this->any())->method('getCartFixedRules')->will($this->returnValue(array()));
     $store = $this->getMock('Magento\\Store\\Model\\Store', array(), array(), '', false);
     $this->priceCurrency->expects($this->atLeastOnce())->method('convert')->will($this->returnArgument(0));
     $this->priceCurrency->expects($this->atLeastOnce())->method('round')->will($this->returnArgument(0));
     $this->quote->expects($this->any())->method('getStore')->will($this->returnValue($store));
     /** validators data */
     $this->validator->expects($this->once())->method('getItemPrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemBasePrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemOriginalPrice')->with($this->item)->will($this->returnValue(100));
     $this->validator->expects($this->once())->method('getItemBaseOriginalPrice')->with($this->item)->will($this->returnValue(100));
     $this->address->expects($this->once())->method('setCartFixedRules')->with(array(1 => 0.0));
     $this->model->calculate($this->rule, $this->item, 1);
     $this->assertEquals($this->data->getAmount(), 10);
     $this->assertEquals($this->data->getBaseAmount(), 10);
     $this->assertEquals($this->data->getOriginalAmount(), 10);
     $this->assertEquals($this->data->getBaseOriginalAmount(), 100);
 }
예제 #20
0
 /**
  * @param QuotePaymentMethod $object
  * @param Quote $quote
  * @return \Magento\Sales\Model\Quote\Payment
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function build(QuotePaymentMethod $object, Quote $quote)
 {
     $payment = $quote->getPayment();
     try {
         $data = $object->__toArray();
         $additionalDataValue = $object->getPaymentDetails();
         unset($data[QuotePaymentMethod::PAYMENT_DETAILS]);
         if (!empty($additionalDataValue)) {
             $additionalData = @unserialize($additionalDataValue);
             if (is_array($additionalData) && !empty($additionalData)) {
                 $data = array_merge($data, $additionalData);
             }
         }
         $data['checks'] = array(\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);
         $payment->importData($data);
     } catch (\Exception $e) {
         throw new LocalizedException('The requested Payment Method is not available.');
     }
     return $payment;
 }
예제 #21
0
파일: Cart.php 프로젝트: aiesh/magento2
 /**
  * Get quote
  *
  * @return \Magento\Sales\Model\Quote
  */
 protected function getQuote()
 {
     if (null == $this->quote) {
         $storeIds = $this->_storeManager->getWebsite($this->getWebsiteId())->getStoreIds();
         $this->quote = $this->_quoteFactory->create()->setSharedStoreIds($storeIds);
         $currentCustomerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
         if (!empty($currentCustomerId)) {
             $this->quote->loadByCustomer($currentCustomerId);
         }
     }
     return $this->quote;
 }
예제 #22
0
파일: Checkout.php 프로젝트: aiesh/magento2
 /**
  * Involve new customer to system
  *
  * @return $this
  */
 protected function _involveNewCustomer()
 {
     $customer = $this->_quote->getCustomerData();
     $confirmationStatus = $this->_customerAccountService->getConfirmationStatus($customer->getId());
     if ($confirmationStatus === CustomerAccountServiceInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
         $url = $this->_customerData->getEmailConfirmationUrl($customer->getEmail());
         $this->_messageManager->addSuccess(__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%1">click here</a>.', $url));
     } else {
         $this->getCustomerSession()->loginById($customer->getId());
     }
     return $this;
 }
예제 #23
0
 /**
  * Add products to items and item options
  *
  * @return $this
  */
 protected function _assignProducts()
 {
     \Magento\Framework\Profiler::start('QUOTE:' . __METHOD__, array('group' => 'QUOTE', 'method' => __METHOD__));
     $productIds = array();
     foreach ($this as $item) {
         $productIds[] = (int) $item->getProductId();
     }
     $this->_productIds = array_merge($this->_productIds, $productIds);
     $productCollection = $this->_productCollectionFactory->create()->setStoreId($this->getStoreId())->addIdFilter($this->_productIds)->addAttributeToSelect($this->_quoteConfig->getProductAttributes())->addOptionsToResult()->addStoreFilter()->addUrlRewrite()->addTierPriceData();
     $this->_eventManager->dispatch('prepare_catalog_product_collection_prices', array('collection' => $productCollection, 'store_id' => $this->getStoreId()));
     $this->_eventManager->dispatch('sales_quote_item_collection_products_after_load', array('product_collection' => $productCollection));
     $recollectQuote = false;
     foreach ($this as $item) {
         $product = $productCollection->getItemById($item->getProductId());
         if ($product) {
             $product->setCustomOptions(array());
             $qtyOptions = array();
             $optionProductIds = array();
             foreach ($item->getOptions() as $option) {
                 /**
                  * Call type-specific logic for product associated with quote item
                  */
                 $product->getTypeInstance()->assignProductToOption($productCollection->getItemById($option->getProductId()), $option, $product);
                 if (is_object($option->getProduct()) && $option->getProduct()->getId() != $product->getId()) {
                     $optionProductIds[$option->getProduct()->getId()] = $option->getProduct()->getId();
                 }
             }
             if ($optionProductIds) {
                 foreach ($optionProductIds as $optionProductId) {
                     $qtyOption = $item->getOptionByCode('product_qty_' . $optionProductId);
                     if ($qtyOption) {
                         $qtyOptions[$optionProductId] = $qtyOption;
                     }
                 }
             }
             $item->setQtyOptions($qtyOptions)->setProduct($product);
         } else {
             $item->isDeleted(true);
             $recollectQuote = true;
         }
         $item->checkData();
     }
     if ($recollectQuote && $this->_quote) {
         $this->_quote->collectTotals();
     }
     \Magento\Framework\Profiler::stop('QUOTE:' . __METHOD__);
     return $this;
 }
예제 #24
0
파일: Create.php 프로젝트: aiesh/magento2
 /**
  * Retrieve customer cart quote object model
  *
  * @return \Magento\Sales\Model\Quote
  */
 public function getCustomerCart()
 {
     if (!is_null($this->_cart)) {
         return $this->_cart;
     }
     $this->_cart = $this->_objectManager->create('Magento\\Sales\\Model\\Quote');
     $customerId = (int) $this->getSession()->getCustomerId();
     if ($customerId) {
         $this->_cart->setStore($this->getSession()->getStore())->loadByCustomer($customerId);
         if (!$this->_cart->getId()) {
             $customerData = $this->_customerAccountService->getCustomer($customerId);
             $this->_cart->assignCustomer($customerData);
             $this->_cart->save();
         }
     }
     return $this->_cart;
 }
예제 #25
0
 public function testAddProductItemPreparation()
 {
     $itemMock = $this->getMock('\\Magento\\Sales\\Model\\Quote\\Item', [], [], '', false);
     $expectedResult = $itemMock;
     $requestMock = $this->getMock('\\Magento\\Framework\\Object');
     $this->objectFactoryMock->expects($this->once())->method('create')->with($this->equalTo(['qty' => 1]))->will($this->returnValue($requestMock));
     $typeInstanceMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Type\\Simple', ['prepareForCartAdvanced'], [], '', false);
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getParentProductId', 'setStickWithinParent', '__wakeup'], [], '', false);
     $collectionMock = $this->getMock('Magento\\Sales\\Model\\Resource\\Quote\\Item\\Collection', [], [], '', false);
     $itemMock->expects($this->any())->method('representProduct')->will($this->returnValue(true));
     $iterator = new \ArrayIterator([$itemMock]);
     $collectionMock->expects($this->any())->method('getIterator')->will($this->returnValue($iterator));
     $this->quoteItemCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock));
     $typeInstanceMock->expects($this->once())->method('prepareForCartAdvanced')->will($this->returnValue([$productMock]));
     $this->productMock->expects($this->once())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock));
     $result = $this->quote->addProduct($this->productMock, null);
     $this->assertEquals($expectedResult, $result);
 }
예제 #26
0
 public function testPopulateBeforeSaveData()
 {
     /** Preconditions */
     $customerId = 1;
     $customerAddressId = 1;
     $this->_address->setQuote($this->_quote);
     $this->assertNotEquals($customerId, $this->_address->getCustomerId(), "Precondition failed: Customer ID was not set.");
     $this->assertNotEquals(1, $this->_address->getQuoteId(), "Precondition failed: Quote ID was not set.");
     $this->assertNotEquals($customerAddressId, $this->_address->getCustomerAddressId(), "Precondition failed: Customer address ID was not set.");
     /** @var \Magento\Customer\Service\V1\Data\AddressBuilder $addressBuilder */
     $addressBuilder = Bootstrap::getObjectManager()->create('Magento\\Customer\\Service\\V1\\Data\\AddressBuilder');
     $customerAddressData = $addressBuilder->setId($customerAddressId)->create();
     $this->_address->setCustomerAddressData($customerAddressData);
     $this->_address->save();
     $this->assertEquals($customerId, $this->_address->getCustomerId());
     $this->assertEquals($this->_quote->getId(), $this->_address->getQuoteId());
     $this->assertEquals($customerAddressId, $this->_address->getCustomerAddressId());
 }
예제 #27
0
파일: Quote.php 프로젝트: aiesh/magento2
 /**
  * Retrieve quote model object
  *
  * @return \Magento\Sales\Model\Quote
  */
 public function getQuote()
 {
     if (is_null($this->_quote)) {
         $this->_quote = $this->_quoteFactory->create();
         if ($this->getStoreId() && $this->getQuoteId()) {
             $this->_quote->setStoreId($this->getStoreId())->load($this->getQuoteId());
         } elseif ($this->getStoreId() && $this->hasCustomerId()) {
             $customerGroupId = $this->_scopeConfig->getValue(self::XML_PATH_DEFAULT_CREATEACCOUNT_GROUP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
             $this->_quote->setStoreId($this->getStoreId())->setCustomerGroupId($customerGroupId)->setIsActive(false)->save();
             $this->setQuoteId($this->_quote->getId());
             try {
                 $customerData = $this->_customerService->getCustomer($this->getCustomerId());
                 $this->_quote->assignCustomer($customerData);
             } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
                 /** Customer does not exist */
             }
         }
         $this->_quote->setIgnoreOldQty(true);
         $this->_quote->setIsSuperMode(true);
     }
     return $this->_quote;
 }
예제 #28
0
 /**
  * Fetch quote item totals data
  *
  * @param Quote $quote
  * @return array
  */
 protected function fetchItemTotalsData(Quote $quote)
 {
     $items = [];
     foreach ($quote->getAllItems() as $item) {
         $items[] = $this->itemTotalsMapper->extractDto($item);
     }
     return $items;
 }
예제 #29
0
 /**
  * @param $expectedMergedRuleIds
  * @param \Magento\Sales\Model\Quote\Address|\Magento\Sales\Model\Quote $object
  * @return $this
  */
 protected function assertObjectHasRuleIdsSet($expectedMergedRuleIds, $object)
 {
     $array = explode(',', $object->getAppliedRuleIds());
     sort($array);
     $this->assertEquals($expectedMergedRuleIds, join(',', $array));
     return $this;
 }
예제 #30
0
 /**
  * Set gift message to item or quote
  *
  * @param \Magento\Sales\Model\Quote $quote
  * @param string $type
  * @param \Magento\GiftMessage\Service\V1\Data\Message $giftMessage
  * @param null|int $entityId
  * @return void
  * @throws \Magento\Framework\Exception\CouldNotSaveException
  * @throws \Magento\Framework\Exception\State\InvalidTransitionException
  */
 protected function setMessage(\Magento\Sales\Model\Quote $quote, $type, $giftMessage, $entityId = null)
 {
     if (is_null($quote->getBillingAddress()->getCountryId())) {
         throw new InvalidTransitionException('Billing address is not set');
     }
     // check if shipping address is set
     if (is_null($quote->getShippingAddress()->getCountryId())) {
         throw new InvalidTransitionException('Shipping address is not set');
     }
     $configType = $type == 'quote' ? '' : 'items';
     if (!$this->helper->getIsMessagesAvailable($configType, $quote, $this->storeManager->getStore())) {
         throw new CouldNotSaveException('Gift Message is not available');
     }
     $message[$type][$entityId] = ['from' => $giftMessage->getSender(), 'to' => $giftMessage->getRecipient(), 'message' => $giftMessage->getMessage()];
     try {
         $this->giftMessageManager->add($message, $quote);
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not add gift message to shopping cart');
     }
 }