0
Magento 2.4.2-p1 Smartwave Porto theme extensions from Amasty subscribed to a Review service from Shopper Approved 

We have been subscribed to the service from Shopper Approved for a long time. This allows our customers to rate us by filling out surveys. I haven't updated the code on our website since upgrading from Magento 1 to Magento 2. I called them today and they said it would be best if I was able to replace 3 variables in the code we are meant to put on the Check-out Confirmation page with the actual variables for:

  • Order Id
  • Name
  • Email

Where can I find these in Magento 2? Or if universal, what are they?


UPDATED on January 19th, 2022:

The JavaScript code we were given by Shopper Approved to enter in on the Checkout Confirmation page is this:

<script type="text/javascript"> var sa_values = { "site":12345, "token":"d138", 'orderid':'ORDER123', 'name':'John Doe', 'email':'[email protected]' }; function saLoadScript(src) { var js = window.document.createElement("script"); js.src = src; js.type = "text/javascript"; document.getElementsByTagName("head")[0].appendChild(js); } var d = new Date(); saLoadScript("https://www.shopperapproved.com/thankyou/rate/23891.js?d=" + d.getTime()); </script> 

Would I put that in like this?

<script type="text/javascript"> var sa_values = { "site":12345, "token":"d138", '$orderId':'ORDER123', '$name':'John Doe', '$email':'[email protected]' }; function saLoadScript(src) { var js = window.document.createElement("script"); js.src = src; js.type = "text/javascript"; document.getElementsByTagName("head")[0].appendChild(js); } var d = new Date(); saLoadScript("https://www.shopperapproved.com/thankyou/rate/23891.js?d=" + d.getTime()); </script> 

or this?

<script type="text/javascript"> var sa_values = { "site":12345, "token":"d138", 'orderid':'$orderId', 'name':'$name', 'email':'$email' }; function saLoadScript(src) { var js = window.document.createElement("script"); js.src = src; js.type = "text/javascript"; document.getElementsByTagName("head")[0].appendChild(js); } var d = new Date(); saLoadScript("https://www.shopperapproved.com/thankyou/rate/23891.js?d=" + d.getTime()); </script> 

1 Answer 1

0

We can make good use of OrderRepositoryInterface to load the information you needed in any classes.

Here is the sample code:

use Magento\Sales\Api\OrderRepositoryInterface; class yourClass{ protected $orderRepository; public function __construct( OrderRepositoryInterface $orderRepository ){ $this->orderRepository = $orderRepository; } public function execute($orderId){ $order = $this->orderRepository->get($orderId); $orderIncrementId = $order->getIncrementId(); $name = $order->getCustomerName(); $email = $order->getCustomerEmail(); //Rest of codes } } 
2
  • Thank you very much for your reply. I've updated my post with the JavaScript code provided to us by Shopper Approved and my attempts to modify it. Am I heading in the right direction with this you think? Commented Jan 19, 2022 at 14:32
  • Your 2nd code is the answer already once this code is written in phtml template Commented Jan 20, 2022 at 13:34

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.