0

I need to configure a script that sends a survey to clients to fill in for trusted reviews.

<script type="text/javascript">
    client_email = ‘here I want display: CUSTOMER EMAIL ADDRESS’;
    order_id = ‘here I want display: ORDER ID’;
    shop_product_ids =‘here I want display: PRODUCT ID’;
</script>

I must put the script in the successful.phtml checkout in the <body> section.

Can anyone help what variables should be here to get this customer data?

Customer email address:

client_email = ‘here I want display: CUSTOMER EMAIL ADDRESS’;

Order ID:

order_id = ‘here I want display: ORDER ID’;

Product ID:

shop_product_ids =‘here I want display: PRODUCT ID’;
2
  • Do you want to add this script on Success.phtml file? Commented Aug 29, 2018 at 21:18
  • Abhishek, yes I want add this script to success.phtml
    – Sylvester
    Commented Aug 30, 2018 at 6:44

1 Answer 1

1

you can get customer data as

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->load($block- >getOrderId()); // pass orderId

if($order->getCustomerId() === NULL){
  $firstname      = $order->getBillingAddress()->getFirstname();
  $lastname       = $order->getBillingAddress()->getLastname();
  $customer_name  = $firstname.' '.$lastname;
  $telephone_tmp  = $order->getBillingAddress()->getTelephone();
  $customer_email = $order->getBillingAddress()->getEmail();
  $postal         = $order->getBillingAddress()->getPostcode();
  $city           = $order->getBillingAddress()->getCity();
  $address_tmp    = $order->getBillingAddress()->getData('street');
  echo $customer_name."<-------- new customer";
}
 /* getting Register Account Details */
else {
   $customer  = $objectManager->create('Magento\Customer\Model\Customer')->load($order->getCustomerId());
  //else, they're a normal registered user.
  $firstname = $customer->getDefaultBillingAddress()->getFirstname();
  $lastname  = $customer->getDefaultBillingAddress()->getLastname();
  echo $customer_name = $firstname.' '.$lastname ."<--------   exist customer";
}

Order id as

$block->getOrderId();

and products items as

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$quoteId = $objectManager->create('Magento\Checkout\Model\Session')->getQuoteId();
$cartData = $objectManager->create('Magento\Quote\Model\QuoteRepository')->get($quoteId)->getAllVisibleItems();
3
  • Arslan, I no want full data customer. Please check my topic. I only want in this fields display: client_email = ‘here I want display: CUSTOMER EMAIL ADDRESS’; order_id = ‘here I want display: ORDER ID’; shop_product_ids =‘here I want display: PRODUCT ID’;
    – Sylvester
    Commented Aug 30, 2018 at 6:45
  • You can get customer email in a variable like this $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $order = $objectManager->create('Magento\Sales\Model\Order')->load($block- >getOrderId()); // pass orderId if($order->getCustomerId() === NULL){ $customer_email = $order->getBillingAddress()->getEmail(); } here $customer_email variable has customer email address Commented Aug 30, 2018 at 19:19
  • Ok sure... .... Commented Aug 31, 2018 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.