Skip to content

Commit

Permalink
Merge pull request #320 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
2.4 develop
  • Loading branch information
Victor-Mageplaza authored Jul 13, 2021
2 parents fce6c59 + 7277765 commit 85c389b
Show file tree
Hide file tree
Showing 19 changed files with 873 additions and 106 deletions.
38 changes: 38 additions & 0 deletions Api/CheckoutManagementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_Smtp
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\Smtp\Api;

/**
* Interface for update item information
* @api
*/
interface CheckoutManagementInterface
{
/**
* @param string $cartId
* @param string $address
* @param boolean $isOsc
*
* @return bool
*/
public function updateOrder($cartId, $address, $isOsc);
}
96 changes: 94 additions & 2 deletions Block/Script.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
namespace Mageplaza\Smtp\Block;

use Magento\Catalog\Block\Product\Context;
use Magento\Customer\Model\SessionFactory as CustomerSession;
use Magento\Checkout\Model\Session;
use Magento\Framework\App\Http\Context as HttpContext;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Template;
use Magento\Sales\Model\Order;
use Mageplaza\Smtp\Helper\EmailMarketing;
use Magento\Framework\Registry;

/**
* Class Script
Expand All @@ -43,22 +48,46 @@ class Script extends Template
*/
protected $checkoutSession;

/**
* @var CustomerSession
*/
protected $customerSession;

/**
* @var Registry
*/
protected $registry;

/**
* @var HttpContext
*/
protected $httpContext;

/**
* Script constructor.
*
* @param Context $context
* @param EmailMarketing $helperEmailMarketing
* @param Session $checkoutSession
* @param CustomerSession $customerSession
* @param Registry $registry
* @param HttpContext $httpContext
* @param array $data
*/
public function __construct(
Context $context,
EmailMarketing $helperEmailMarketing,
Session $checkoutSession,
CustomerSession $customerSession,
Registry $registry,
HttpContext $httpContext,
array $data = []
) {
$this->helperEmailMarketing = $helperEmailMarketing;
$this->checkoutSession = $checkoutSession;
$this->checkoutSession = $checkoutSession;
$this->customerSession = $customerSession;
$this->registry = $registry;
$this->httpContext = $httpContext;
parent::__construct($context, $data);
}

Expand All @@ -76,7 +105,7 @@ public function getHelperEmailMarketing()
public function isSuccessPage()
{
$fullActionName = $this->getRequest()->getFullActionName();
$pages = ['checkout_onepage_success', 'mpthankyoupage_index_index'];
$pages = ['checkout_onepage_success', 'mpthankyoupage_index_index'];

return in_array($fullActionName, $pages);
}
Expand All @@ -100,4 +129,67 @@ public function toHtml()

return parent::toHtml();
}

/**
* @return mixed
* @throws NoSuchEntityException
*/
public function getCurrencyCode()
{
return $this->_storeManager->getStore()->getCurrentCurrency()->getCode();
}

/**
* @return array
* @throws NoSuchEntityException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getCustomerData()
{
$isLoggedIn = $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_AUTH);
if (!$isLoggedIn) {
$shippingAddress = $this->checkoutSession->getQuote()->getShippingAddress();
$data = [
'email' => $shippingAddress->getData('email') === null ? '' : $shippingAddress->getData('email'),
'firstname' => $shippingAddress->getData('firstname') === null ? '' : $shippingAddress->getData('firstname'),
'lastname' => $shippingAddress->getData('lastname') === null ? '' : $shippingAddress->getData('lastname')
];
return $data;
} else {
$customer = $this->customerSession->create()->getCustomer();
$data = [
'email' => $customer->getData('email') === null ? '' : $customer->getData('email'),
'firstname' => $customer->getData('firstname') === null ? '' : $customer->getData('firstname'),
'lastname' => $customer->getData('lastname') === null ? '' : $customer->getData('lastname')
];
return $data;
}
}

/**
* @return array|false
* @throws NoSuchEntityException
*/
public function productAbandoned()
{
if ($this->getRequest()->getFullActionName() === 'catalog_product_view') {
$product = $this->registry->registry('current_product');
$imageUrl = $this->_storeManager->getStore()
->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage();

return [
'collections' => [],
'id' => $product->getId(),
'image' => $imageUrl,
'price' => $product->getFinalPrice(),
'productType' => $product->getTypeId(),
'tags' => [],
'title' => $product->getName(),
'url' => $product->getProductUrl(),
'vendor' => 'magento'
];
}

return false;
}
}
Loading

0 comments on commit 85c389b

Please sign in to comment.