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’;
  • Do you want to add this script on Success.phtml file? – Abhishek Panchal Aug 29 '18 at 21:18
  • Abhishek, yes I want add this script to success.phtml – Sylvester Aug 30 '18 at 6:44
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();
| improve this answer | |
  • 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 Aug 30 '18 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 – Arslan Tabassum Aug 30 '18 at 19:19
  • Arslan, I give you vote for your help. Still I have one question, can you please contact with me on my email address: brandwrox1@gmail.com Thank you. – Sylvester Aug 31 '18 at 7:06
  • Ok sure... .... – Arslan Tabassum Aug 31 '18 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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