コード例 #1
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);
         }
     }
 }
コード例 #2
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;
 }
コード例 #3
0
ファイル: QuoteImporter.php プロジェクト: aiesh/magento2
 /**
  * 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;
 }
コード例 #4
0
ファイル: Quote.php プロジェクト: Atlis/docker-magento2
 /**
  * Merge quotes
  *
  * @param   Quote $quote
  * @return $this
  */
 public function merge(Quote $quote)
 {
     $this->_eventManager->dispatch($this->_eventPrefix . '_merge_before', array($this->_eventObject => $this, 'source' => $quote));
     foreach ($quote->getAllVisibleItems() as $item) {
         $found = false;
         foreach ($this->getAllItems() as $quoteItem) {
             if ($quoteItem->compare($item)) {
                 $quoteItem->setQty($quoteItem->getQty() + $item->getQty());
                 $found = true;
                 break;
             }
         }
         if (!$found) {
             $newItem = clone $item;
             $this->addItem($newItem);
             if ($item->getHasChildren()) {
                 foreach ($item->getChildren() as $child) {
                     $newChild = clone $child;
                     $newChild->setParentItem($newItem);
                     $this->addItem($newChild);
                 }
             }
         }
     }
     /**
      * Init shipping and billing address if quote is new
      */
     if (!$this->getId()) {
         $this->getShippingAddress();
         $this->getBillingAddress();
     }
     if ($quote->getCouponCode()) {
         $this->setCouponCode($quote->getCouponCode());
     }
     $this->_eventManager->dispatch($this->_eventPrefix . '_merge_after', array($this->_eventObject => $this, 'source' => $quote));
     return $this;
 }
コード例 #5
0
ファイル: Data.php プロジェクト: zhangjiachao/magento2
 /**
  * Send email id payment was failed
  *
  * @param \Magento\Sales\Model\Quote $checkout
  * @param string $message
  * @param string $checkoutType
  * @return $this
  */
 public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage')
 {
     $this->inlineTranslation->suspend();
     $template = $this->_scopeConfig->getValue('checkout/payment_failed/template', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId());
     $copyMethod = $this->_scopeConfig->getValue('checkout/payment_failed/copy_method', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $bcc = array();
     if ($copyTo && $copyMethod == 'bcc') {
         $bcc = $copyTo;
     }
     $_receiver = $this->_scopeConfig->getValue('checkout/payment_failed/receiver', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId());
     $sendTo = array(array('email' => $this->_scopeConfig->getValue('trans_email/ident_' . $_receiver . '/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()), 'name' => $this->_scopeConfig->getValue('trans_email/ident_' . $_receiver . '/name', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId())));
     if ($copyTo && $copyMethod == 'copy') {
         foreach ($copyTo as $email) {
             $sendTo[] = array('email' => $email, 'name' => null);
         }
     }
     $shippingMethod = '';
     if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) {
         $data = explode('_', $shippingInfo);
         $shippingMethod = $data[0];
     }
     $paymentMethod = '';
     if ($paymentInfo = $checkout->getPayment()) {
         $paymentMethod = $paymentInfo->getMethod();
     }
     $items = '';
     foreach ($checkout->getAllVisibleItems() as $_item) {
         /* @var $_item \Magento\Sales\Model\Quote\Item */
         $items .= $_item->getProduct()->getName() . '  x ' . $_item->getQty() . '  ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
     }
     $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal();
     foreach ($sendTo as $recipient) {
         $transport = $this->_transportBuilder->setTemplateIdentifier($template)->setTemplateOptions(array('area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()))->setTemplateVars(array('reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => $this->_localeDate->date(), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => $this->_scopeConfig->getValue('carriers/' . $shippingMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'paymentMethod' => $this->_scopeConfig->getValue('payment/' . $paymentMethod . '/title', \Magento\Store\Model\ScopeInterface::SCOPE_STORE), 'items' => nl2br($items), 'total' => $total))->setFrom($this->_scopeConfig->getValue('checkout/payment_failed/identity', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $checkout->getStoreId()))->addTo($recipient['email'], $recipient['name'])->addBcc($bcc)->getTransport();
         $transport->sendMessage();
     }
     $this->inlineTranslation->resume();
     return $this;
 }