Skip to content

Commit

Permalink
checkout success page append html for returning shopper reviews featu…
Browse files Browse the repository at this point in the history
…re (#5)
  • Loading branch information
kadukia123 authored Dec 20, 2024
1 parent 4b5d38a commit 981e2b5
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
111 changes: 111 additions & 0 deletions src/app/code/Fera/Ai/Block/Checkout/Success.php
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);
}
}
2 changes: 1 addition & 1 deletion src/app/code/Fera/Ai/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Fera_Ai" setup_version="1.0.1">
<module name="Fera_Ai" setup_version="1.1.0">
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_Checkout"/>
Expand Down
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>
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; ?>

0 comments on commit 981e2b5

Please sign in to comment.