Пример #1
0
 /**
  * Add cart item to wishlist and remove from cart
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @throws NotFoundException
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 public function execute()
 {
     $wishlist = $this->wishlistProvider->getWishlist();
     if (!$wishlist) {
         throw new NotFoundException(__('Page not found.'));
     }
     try {
         $itemId = (int) $this->getRequest()->getParam('item');
         $item = $this->cart->getQuote()->getItemById($itemId);
         if (!$item) {
             throw new LocalizedException(__('The requested cart item doesn\'t exist.'));
         }
         $productId = $item->getProductId();
         $buyRequest = $item->getBuyRequest();
         $wishlist->addNewItem($productId, $buyRequest);
         $this->cart->getQuote()->removeItem($itemId);
         $this->cart->save();
         $this->wishlistHelper->calculate();
         $wishlist->save();
         $this->messageManager->addSuccessMessage(__("%1 has been moved to your wish list.", $this->escaper->escapeHtml($item->getProduct()->getName())));
     } catch (LocalizedException $e) {
         $this->messageManager->addErrorMessage($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addExceptionMessage($e, __('We can\'t move the item to the wish list.'));
     }
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     return $resultRedirect->setUrl($this->cartHelper->getCartUrl());
 }
Пример #2
0
 /**
  * Add shared wishlist item to shopping cart
  *
  * If Product has required options - redirect
  * to product view page with message about needed defined required options
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     $itemId = (int) $this->getRequest()->getParam('item');
     /* @var $item Item */
     $item = $this->itemFactory->create()->load($itemId);
     $redirectUrl = $this->_redirect->getRefererUrl();
     try {
         /** @var OptionCollection $options */
         $options = $this->optionFactory->create()->getCollection()->addItemFilter([$itemId]);
         $item->setOptions($options->getOptionsByItem($itemId));
         $item->addToCart($this->cart);
         $this->cart->save();
         if (!$this->cart->getQuote()->getHasError()) {
             $message = __('You added %1 to your shopping cart.', $this->escaper->escapeHtml($item->getProduct()->getName()));
             $this->messageManager->addSuccess($message);
         }
         if ($this->cartHelper->getShouldRedirectToCart()) {
             $redirectUrl = $this->cartHelper->getCartUrl();
         }
     } catch (ProductException $e) {
         $this->messageManager->addError(__('This product(s) is out of stock.'));
     } catch (LocalizedException $e) {
         $this->messageManager->addNotice($e->getMessage());
         $redirectUrl = $item->getProductUrl();
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('We can\'t add the item to the cart right now.'));
     }
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     $resultRedirect->setUrl($redirectUrl);
     return $resultRedirect;
 }
Пример #3
0
 /**
  * Add wishlist item to shopping cart and remove from wishlist
  *
  * If Product has required options - item removed from wishlist and redirect
  * to product view page with message about needed defined required options
  *
  * @return ResponseInterface
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function execute()
 {
     $itemId = (int) $this->getRequest()->getParam('item');
     /* @var $item \Magento\Wishlist\Model\Item */
     $item = $this->itemFactory->create()->load($itemId);
     if (!$item->getId()) {
         return $this->_redirect('*/*');
     }
     $wishlist = $this->wishlistProvider->getWishlist($item->getWishlistId());
     if (!$wishlist) {
         return $this->_redirect('*/*');
     }
     // Set qty
     $qty = $this->getRequest()->getParam('qty');
     if (is_array($qty)) {
         if (isset($qty[$itemId])) {
             $qty = $qty[$itemId];
         } else {
             $qty = 1;
         }
     }
     $qty = $this->quantityProcessor->process($qty);
     if ($qty) {
         $item->setQty($qty);
     }
     $redirectUrl = $this->_url->getUrl('*/*');
     $configureUrl = $this->_url->getUrl('*/*/configure/', ['id' => $item->getId(), 'product_id' => $item->getProductId()]);
     try {
         /** @var \Magento\Wishlist\Model\Resource\Item\Option\Collection $options */
         $options = $this->optionFactory->create()->getCollection()->addItemFilter([$itemId]);
         $item->setOptions($options->getOptionsByItem($itemId));
         $buyRequest = $this->productHelper->addParamsToBuyRequest($this->getRequest()->getParams(), ['current_config' => $item->getBuyRequest()]);
         $item->mergeBuyRequest($buyRequest);
         $item->addToCart($this->cart, true);
         $this->cart->save()->getQuote()->collectTotals();
         $wishlist->save();
         if (!$this->cart->getQuote()->getHasError()) {
             $message = __('You added %1 to your shopping cart.', $this->escaper->escapeHtml($item->getProduct()->getName()));
             $this->messageManager->addSuccess($message);
         }
         if ($this->cart->getShouldRedirectToCart()) {
             $redirectUrl = $this->cart->getCartUrl();
         } else {
             $refererUrl = $this->_redirect->getRefererUrl();
             if ($refererUrl && $refererUrl != $configureUrl) {
                 $redirectUrl = $refererUrl;
             }
         }
     } catch (ProductException $e) {
         $this->messageManager->addError(__('This product(s) is out of stock.'));
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addNotice($e->getMessage());
         $redirectUrl = $configureUrl;
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Cannot add item to shopping cart'));
     }
     $this->helper->calculate();
     return $this->getResponse()->setRedirect($redirectUrl);
 }
Пример #4
0
 /**
  * Get checkout method
  *
  * @return string
  */
 public function getCheckoutMethod()
 {
     if ($this->_cart->getCustomerSession()->isLoggedIn()) {
         return \Magento\Checkout\Model\Type\Onepage::METHOD_CUSTOMER;
     }
     if (!$this->_cart->getQuote()->getCheckoutMethod()) {
         if ($this->_checkoutData->isAllowedGuestCheckout($this->_cart->getQuote())) {
             $this->_cart->getQuote()->setCheckoutMethod(\Magento\Checkout\Model\Type\Onepage::METHOD_GUEST);
         } else {
             $this->_cart->getQuote()->setCheckoutMethod(\Magento\Checkout\Model\Type\Onepage::METHOD_REGISTER);
         }
     }
     return $this->_cart->getQuote()->getCheckoutMethod();
 }
Пример #5
0
 /**
  * Add or Move item product to shopping cart
  *
  * Return true if product was successful added or exception with code
  * Return false for disabled or unvisible products
  *
  * @param \Magento\Checkout\Model\Cart $cart
  * @param bool $delete  delete the item after successful add to cart
  * @return bool
  * @throws \Magento\Catalog\Model\Product\Exception
  */
 public function addToCart(\Magento\Checkout\Model\Cart $cart, $delete = false)
 {
     $product = $this->getProduct();
     $storeId = $this->getStoreId();
     if ($product->getStatus() != \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) {
         return false;
     }
     if (!$product->isVisibleInSiteVisibility()) {
         if ($product->getStoreId() == $storeId) {
             return false;
         }
         $urlData = $this->_catalogUrl->getRewriteByProductStore([$product->getId() => $storeId]);
         if (!isset($urlData[$product->getId()])) {
             return false;
         }
         $product->setUrlDataObject(new \Magento\Framework\Object($urlData));
         $visibility = $product->getUrlDataObject()->getVisibility();
         if (!in_array($visibility, $product->getVisibleInSiteVisibilities())) {
             return false;
         }
     }
     if (!$product->isSalable()) {
         throw new ProductException(__('Product is not salable.'));
     }
     $buyRequest = $this->getBuyRequest();
     $cart->addProduct($product, $buyRequest);
     if (!$product->isVisibleInSiteVisibility()) {
         $cart->getQuote()->getItemByProduct($product)->setStoreId($storeId);
     }
     if ($delete) {
         $this->delete();
     }
     return true;
 }
Пример #6
0
 /**
  * Retrieve subtotal block html
  *
  * @return string
  */
 protected function getSubtotalHtml()
 {
     $totals = $this->cart->getQuote()->getTotals();
     $subtotal = isset($totals['subtotal']) && $totals['subtotal'] instanceof Total ? $totals['subtotal']->getValue() : 0;
     return $this->helperData->formatPrice($subtotal);
 }
Пример #7
0
 /**
  * Disable multishipping
  *
  * @param \Magento\Framework\App\Action\Action $subject
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function beforeExecuteInternal(\Magento\Framework\App\Action\Action $subject)
 {
     $this->cart->getQuote()->setIsMultiShipping(0);
 }
Пример #8
0
 /**
  * Init payment, server2server
  *
  * @param CheckoutCart $cart
  * @param $urls
  * @param \Magento\Framework\DataObject $data
  *
  * @return \WirecardCEE_QPay_Response_Initiation
  * @throws \Exception
  */
 public function initPaymentByCart(CheckoutCart $cart, $urls, \Magento\Framework\DataObject $data)
 {
     $quote = $cart->getQuote();
     $init = new \WirecardCEE_QPay_FrontendClient($this->_dataHelper->getConfigArray());
     $init->setPluginVersion($this->_dataHelper->getPluginVersion());
     $init->setConfirmUrl($urls['confirm']);
     $quote->reserveOrderId();
     $quote->save();
     $orderId = $quote->getReservedOrderId();
     $init->setOrderReference(sprintf('%010d', $orderId));
     $init->uniqueId = $this->_getUniqueId($cart);
     $init->setAmount(round($cart->getQuote()->getBaseGrandTotal(), $this->_dataHelper->getPrecision()))->setCurrency($quote->getCurrency()->getBaseCurrencyCode())->setPaymentType($this->_paymentMethod)->setOrderDescription($this->getUserDescription($quote))->setSuccessUrl($urls['return'])->setPendingUrl($urls['return'])->setCancelUrl($urls['return'])->setFailureUrl($urls['return'])->createConsumerMerchantCrmId($quote->getCustomerEmail())->setServiceUrl($this->_dataHelper->getConfigData('options/service_url'))->setConsumerData($this->_getConsumerData($quote))->setMaxRetries($this->_dataHelper->getConfigData('options/maxretries'));
     $init->mage_orderId = $orderId;
     $init->mage_quoteId = $quote->getId();
     $init->mage_orderCreation = $this->_dataHelper->getConfigData('options/order_creation');
     $init->generateCustomerStatement($this->_dataHelper->getConfigData('options/shopname'), sprintf('%010d', $orderId));
     if ($this->_dataHelper->getConfigData('options/sendbasketinformation') || $this->forceSendingBasket()) {
         $basket = new \WirecardCEE_Stdlib_Basket();
         $basket->setCurrency($quote->getBaseCurrencyCode());
         foreach ($quote->getAllVisibleItems() as $item) {
             /** @var \Magento\Quote\Model\Quote\Item $item */
             $bitem = new \WirecardCEE_Stdlib_Basket_Item();
             $bitem->setDescription($item->getProduct()->getName());
             $bitem->setArticleNumber($item->getSku());
             $bitem->setUnitPrice(number_format($item->getPrice(), $this->_dataHelper->getPrecision(), '.', ''));
             $bitem->setTax(number_format($item->getTaxAmount(), $this->_dataHelper->getPrecision(), '.', ''));
             $basket->addItem($bitem, (int) $item->getQty());
         }
         $bitem = new \WirecardCEE_Stdlib_Basket_Item();
         $bitem->setArticleNumber('shipping');
         $bitem->setUnitPrice(number_format($quote->getShippingAddress()->getShippingAmount(), $this->_dataHelper->getPrecision(), '.', ''));
         $bitem->setTax(number_format($quote->getShippingAddress()->getShippingTaxAmount(), $this->_dataHelper->getPrecision(), '.', ''));
         $bitem->setDescription($quote->getShippingAddress()->getShippingDescription());
         $basket->addItem($bitem);
         foreach ($basket->__toArray() as $k => $v) {
             $init->{$k} = $v;
         }
     }
     if ($this->_dataHelper->getConfigData('options/sendconfirmationemail')) {
         $init->setConfirmMail($this->_dataHelper->getStoreConfigData('trans_email/ident_general/email'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/bgcolor'))) {
         $init->setBackgroundColor($this->_dataHelper->getConfigData('options/bgcolor'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/displaytext'))) {
         $init->setDisplayText($this->_dataHelper->getConfigData('options/displaytext'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/imageurl'))) {
         $init->setImageUrl($this->_dataHelper->getConfigData('options/imageurl'));
     }
     if (strlen($this->_dataHelper->getConfigData('options/layout'))) {
         $init->setLayout($this->_dataHelper->getConfigData('options/layout'));
     }
     if ($this->_dataHelper->getConfigData('options/autodeposit') && $this->_autoDepositAllowed) {
         $init->setAutoDeposit(true);
     }
     if ($this->_dataHelper->getConfigData('options/duplicaterequestcheck')) {
         $init->setDuplicateRequestCheck($this->_dataHelper->getConfigData('options/duplicaterequestcheck'));
     }
     if ($this->_dataHelper->getConfigData('options/mobiledetect')) {
         $detect = new \WirecardCEE_QPay_MobileDetect();
         if ($detect->isTablet()) {
             $layout = 'TABLET';
         } elseif ($detect->isMobile()) {
             $layout = 'SMARTPHONE';
         } else {
             $layout = 'DESKTOP';
         }
         $init->setLayout($layout);
     }
     if (strlen($data->getData('financialInstitution'))) {
         $init->setFinancialInstitution($data->getData('financialInstitution'));
     }
     $init->iframeUsed = $this->getDisplayMode() != 'redirect';
     $init->quoteHash = $this->_dataHelper->calculateQuoteChecksum($quote);
     $this->setAdditionalRequestData($init, $cart);
     $this->_logger->debug(__METHOD__ . ':' . print_r($init->getRequestData(), true));
     try {
         $initResponse = $init->initiate();
     } catch (\Exception $e) {
         $this->_logger->debug(__METHOD__ . ':' . $e->getMessage());
         throw new $e();
     }
     if ($initResponse->getStatus() == \WirecardCEE_QPay_Response_Initiation::STATE_FAILURE) {
         $error = $initResponse->getError();
         $message = $this->_dataHelper->__('An error occurred during the payment process');
         if ($error !== false) {
             if (strlen($error->getConsumerMessage())) {
                 $message = $error->getConsumerMessage();
             }
             $this->_logger->debug(__METHOD__ . ':' . $error->getMessage());
         }
         throw new \Exception($message);
     }
     return $initResponse;
 }
Пример #9
0
 /**
  * @return \Magento\Framework\View\Result\PageFactory
  */
 public function execute()
 {
     $pId = $this->getRequest()->getParam('pid');
     //productId
     $sdcnt = $this->getRequest()->getParam('sdcnt');
     //shoppree discount
     /* 
      $resultPage = $this->resultPageFactory->create();
      $resultPage->getConfig()->getTitle()->prepend(__('Shoppree Offers'));
      return $resultPage; 
     
      $layout = $this->_view->getLayout();
      $block = $layout->createBlock('Shoppree\Offers\Block\OfferBlock');
      echo $block->getCurrentStoreName();
      echo '<br>';
      echo $block->getProductName('1');
     */
     $layout = $this->_view->getLayout();
     $block = $layout->createBlock('Shoppree\\Offers\\Block\\OfferBlock');
     try {
         if (!empty($pId)) {
             $params = array();
             $params['qty'] = '1';
             //product quantity
             /*get product id*/
             //$pId = '1';//productId
             $_product = $this->product->load($pId);
             if ($_product) {
                 $quote = $this->cart->getQuote();
                 //Create object of quote
                 $_product->setPrice('0.00');
                 //$_product->setFinalPrice('0.00');
                 $this->cart->addProduct($_product, $params);
                 $this->cart->setItemsQty();
                 //$quote->setGrandTotal($this->cart->getQuote()->getGrandTotal() - 50.00);
                 //$this->cart->setQuote($quote);
                 $this->cart->saveQuote();
                 $this->_checkoutSession->setCartWasUpdated(false);
                 $this->cart->save();
                 $this->_checkoutSession->unsShoppreeDiscount();
                 $this->messageManager->addSuccess(__('Add to cart successfully.'));
             }
         } else {
             if (!empty($sdcnt)) {
                 /*sets shoppree discount*/
                 $this->_checkoutSession->setShoppreeDiscount($sdcnt);
                 /*$this->getResponse()->setRedirect('/magento-prototype/checkout/cart');*/
             }
         }
         //$this->messageManager->addSuccess(__('Add to cart successfully.').'--'.$this->_checkoutSession->getQuote()->getSubtotal().'--'.$this->_checkoutSession->getQuote()->getGrandTotal().'--'.$this->cart->getQuote()->getGrandTotal().'--'.$this->cart->getQuote()->getSubtotal());
         //$this->messageManager->addSuccess(__('Add to cart successfully.').$block->getGrandTotal().'--'.$this->cart->getQuote()->getGrandTotal());
         /*
          $this->messageManager->addSuccess(__('Add to cart successfully.').$this->cart->getItemsCount().'--'.$this->cart->getItemsQty()); 
             		 $this->getResponse()->setRedirect('/magento-prototype/checkout/cart');
         */
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addException($e, __('%1', $e->getMessage()));
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('error.'));
     }
 }