How will final result should look like for this implementation.
Thank you
file location: /vendor/magento/module-checkout/Controller/Onepage/Success.php
Below is my default Success.php
for Magento 2.1
<?php /** * * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ namespace Magento\Checkout\Controller\Onepage;
class Success extends \Magento\Checkout\Controller\Onepage {
/**
* Order success action
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
$session = $this->getOnepage()->getCheckout();
if (!$this->_objectManager->get('Magento\Checkout\Model\Session\SuccessValidator')->isValid()) {
return $this->resultRedirectFactory->create()->setPath('checkout/cart');
}
$session->clearQuote();
//@todo: Refactor it to match CQRS
$resultPage = $this->resultPageFactory->create();
$this->_eventManager->dispatch(
'checkout_onepage_controller_success_action',
['order_ids' => [$session->getLastOrderId()]]
);
return $resultPage;
} }
………………………. where do i paste this code on Success.php
<script>
window.renderOptIn = function() {
window.gapi.load('surveyoptin', function() {
window.gapi.surveyoptin.render(
{
"merchant_id": XXXXXXXXX,
"order_id": "<?php echo $order->getIncrementId() ?>",
"email": "<?php echo $order->getCustomerEmail() ?>",
"delivery_country": "<?php echo $order->getShippingAddress()->getCountryId() ?>",
"estimated_delivery_date": "YYYY-MM-DD"
});
});
}
</script>
Best Answer
I think you would use the file located at or whatever the vendor/template you use
In which case, you would put the google code after the last in the success.phtml file