-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checkout success page append html for returning shopper reviews featu…
…re (#5)
- Loading branch information
1 parent
4b5d38a
commit 981e2b5
Showing
4 changed files
with
126 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
/** | ||
* @author: Sviatoslav Lashkiv | ||
* @email: ss.lashkiv@gmail.com | ||
* @team: MageCloud | ||
*/ | ||
|
||
namespace Fera\Ai\Block\Checkout; | ||
|
||
use Magento\Framework\View\Element\Template\Context; | ||
use Magento\Checkout\Model\Session as CheckoutSession; | ||
use Magento\Sales\Model\Order\Config; | ||
use Magento\Framework\App\Http\Context as HttpContext; | ||
use Magento\Customer\Model\Session as CustomerSession; | ||
use Magento\Directory\Helper\Data as DirectoryHelperData; | ||
use Fera\Ai\Helper\Data as FeraHelper; | ||
|
||
/** | ||
* Class Success | ||
* @package Fera\Ai\Block\Footer\Checkout | ||
*/ | ||
class Success extends \Magento\Checkout\Block\Onepage\Success | ||
{ | ||
/** | ||
* @var CustomerSession | ||
*/ | ||
protected $customerSession; | ||
|
||
/** | ||
* @var DirectoryHelperData | ||
*/ | ||
protected $directoryHelper; | ||
|
||
/** | ||
* @var FeraHelper | ||
*/ | ||
protected $helper; | ||
|
||
/** | ||
* Success constructor. | ||
* @param Context $context | ||
* @param CheckoutSession $checkoutSession | ||
* @param Config $orderConfig | ||
* @param HttpContext $httpContext | ||
* @param CustomerSession $customerSession | ||
* @param DirectoryHelperData $directoryHelper | ||
* @param FeraHelper $helper | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
CheckoutSession $checkoutSession, | ||
Config $orderConfig, | ||
HttpContext $httpContext, | ||
CustomerSession $customerSession, | ||
DirectoryHelperData $directoryHelper, | ||
FeraHelper $helper, | ||
array $data = [] | ||
) | ||
{ | ||
$this->customerSession = $customerSession; | ||
$this->directoryHelper = $directoryHelper; | ||
$this->helper = $helper; | ||
parent::__construct($context, $checkoutSession, $orderConfig, $httpContext, $data); | ||
} | ||
|
||
/** | ||
* @return bool|mixed | ||
*/ | ||
public function isEnabled() | ||
{ | ||
return $this->helper->isEnabled(); | ||
} | ||
|
||
/** | ||
* Get last order, JSONify it and return it. | ||
* @return String | ||
*/ | ||
public function getOrderJson() | ||
{ | ||
$order = $this->_checkoutSession->getLastRealOrder(); | ||
|
||
$customer = null; | ||
if (!empty($this->customerSession->getCustomerId())) { | ||
$customer = $this->customerSession->getCustomer(); | ||
$address = $customer->getDefaultShippingAddress(); | ||
|
||
if (!empty($address)) { | ||
$address = $address->getData(); | ||
} | ||
|
||
$customer = [ | ||
'first_name' => $this->customerSession->getCustomer()->getFirstname(), | ||
'email' => $this->customerSession->getCustomer()->getEmail(), | ||
]; | ||
} else { | ||
$customer = [ | ||
'first_name' => $order->getCustomerFirstname(), | ||
'email' => $order->getCustomerEmail() | ||
]; | ||
} | ||
|
||
$orderData = [ | ||
'orderId' => $order->getId(), | ||
'customer' => $customer, | ||
]; | ||
|
||
|
||
return $this->helper->jsonEncode($orderData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/app/code/Fera/Ai/view/frontend/layout/checkout_onepage_success.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0"?> | ||
|
||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceContainer name="content"> | ||
<block class="Fera\Ai\Block\Checkout\Success" template="Fera_Ai::checkout/success.phtml" | ||
name="fera_ai.footer.checkout.success"/> | ||
</referenceContainer> | ||
</body> | ||
</page> |
3 changes: 3 additions & 0 deletions
3
src/app/code/Fera/Ai/view/frontend/templates/checkout/success.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php if ($block->isEnabled()): ?> | ||
<div class="fera-order-success" style="display: none;" data-fera-order='<?= $block->getOrderJson(); ?>'></div> | ||
<?php endif; ?> |