4

How will final result should looks 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>

1

I think you would use the file located at or whatever the vendor/template you use

vendor/magento/module-checkout/view/frontend/templates/success.phtml

In which case, you would put the google code after the last in the success.phtml file

0

You need to put this code in vendor/magento/module-checkout/view/frontend/templates/success.phtml.

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php /** @var $block \Magento\Checkout\Block\Onepage\Success */ ?>
<div class="checkout-success">
    <?php if ($block->getOrderId()):?>
        <?php if ($block->getCanViewOrder()) :?>
            <p><?= __('Your order number is: %1.', sprintf('<a href="%s" class="order-number"><strong>%s</strong></a>', $block->escapeHtml($block->getViewOrderUrl()), $block->escapeHtml($block->getOrderId()))) ?></p>
        <?php  else :?>
            <p><?= __('Your order # is: <span>%1</span>.', $block->escapeHtml($block->getOrderId())) ?></p>
        <?php endif;?>
            <p><?= /* @escapeNotVerified */ __('We\'ll email you an order confirmation with details and tracking info.') ?></p>
    <?php endif;?>

    <?= $block->getAdditionalInfoHtml() ?>

    <div class="actions-toolbar">
        <div class="primary">
            <a class="action primary continue" href="<?= /* @escapeNotVerified */ $block->getContinueUrl() ?>"><span><?= /* @escapeNotVerified */ __('Continue Shopping') ?></span></a>
        </div>
    </div>
</div>
<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>
-1

app/design/frontend/magento/theme/Magento_Checkout/templates/success.phtml

Add this script

<script>

  window.renderOptIn = function() {

  window.gapi.load('surveyoptin', function() {

  window.gapi.surveyoptin.render(

    {

      "merchant_id": xxxxxxxxx,

      "order_id": "<?php echo $orderData->getIncrementId() ?>",

      "email": "<?php echo $orderData->getCustomerEmail() ?>",

      "delivery_country": "<?php echo $orderData->getShippingAddress()->getCountryId() ?>",

      "estimated_delivery_date": "YYYY-MM-DD"

    });

 });

 }

</script>
  • This looks like code for Magento 1, not Magento 2. – Steve Robbins Nov 14 '17 at 19:27

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.