External file cart empties when using browser back button The 2019 Stack Overflow Developer Survey Results Are In

Why do we hear so much about the Trump administration deciding to impose and then remove tariffs?

Is a "Democratic" Oligarchy-Style System Possible?

Multiply Two Integer Polynomials

Am I thawing this London Broil safely?

Identify boardgame from Big movie

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

Apparent duplicates between Haynes service instructions and MOT

A poker game description that does not feel gimmicky

What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?

Are spiders unable to hurt humans, especially very small spiders?

Why is the maximum length of OpenWrt’s root password 8 characters?

Is flight data recorder erased after every flight?

Why didn't the Event Horizon Telescope team mention Sagittarius A*?

Does a dangling wire really electrocute me if I'm standing in water?

What is the accessibility of a package's `Private` context variables?

Are there any other methods to apply to solving simultaneous equations?

How come people say “Would of”?

Can one be advised by a professor who is very far away?

Have you ever entered Singapore using a different passport or name?

Can someone be penalized for an "unlawful" act if no penalty is specified?

What do hard-Brexiteers want with respect to the Irish border?

Looking for Correct Greek Translation for Heraclitus

How to answer pointed "are you quitting" questioning when I don't want them to suspect

How to deal with fear of taking dependencies



External file cart empties when using browser back button



The 2019 Stack Overflow Developer Survey Results Are In



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have the following code in an external file(same domain) to get the current cart details, and I'm getting all details without any issues.



The problem is, when I go to the checkout page using 'Go to checkout' and press browser back button this cart gets empty. I mean only on this external file.



When I click the 'view and edit cart' and uses the browser back button the cart is fine.



Any help would be appreciated!



<?php
ini_set("display_errors", true);
ini_set("error_reporting", E_ALL);

require '/var/www/html/app/bootstrap.php';

$bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('MagentoFrameworkAppHttp');
$obj = MagentoFrameworkAppObjectManager::getInstance();
$obj->get('MagentoFrameworkAppState')->setAreaCode('frontend');

$storeManager = $obj->create("\Magento\Store\Model\StoreManagerInterface");
$storeManager->setCurrentStore(1);

$state = $obj->get('MagentoFrameworkAppState');

// Getting the object managers dependencies
$quote = $obj->get('MagentoCheckoutModelSession')->getQuote();
$shoppingcart = $obj->get('MagentoCheckoutModelCart');

$imagehelper = $obj->get('MagentoCatalogHelperImage');

// Get quote and cart items collection
$quote = $shoppingcart->getQuote();
$quoteitems = $quote->getAllItems();

// Getting cart
$cart= $shoppingcart->getCart();

// Getting the subtotal of the cart
$subtotal = number_format($quote->getBaseSubtotal(), 2);
$qty = 0;

$arrProducts = array();
$mediaurl= $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
$baseurl = $storeManager->getStore()->getBaseUrl();

$j = 0;
foreach ($quoteitems as $item)

$arrProducts[$j]['productID'] = $item->getProductId();
$arrProducts[$j]['productName'] = $item->getName();
$arrProducts[$j]['productQty'] = $item->getQty();
$arrProducts[$j]['productPrice'] = number_format($item->getPrice(),2);

$qty += $item->getQty();

$_product = $obj->get('MagentoCatalogModelProduct')->load($item->getProductId());
$arrProducts[$j]['productUrl'] = $_product->getUrlKey();
$arrProducts[$j]['productImage'] = $mediaurl.'catalog/product'.$_product->getSmallImage();

$j++;
?>

<div class="CustomMiniCart">
<?php
if($qty > 0 && !empty($arrProducts)) ?>
<span class="miniCartWrap">
Cart Subtotal: <b>$<?php echo $subtotal; ?></b>
<span class="numItems"><b><?php echo count($arrProducts);?></b> Item(s) in Cart</span>
<a href="https://example.com/checkout/" class="chk">GO TO CHECKOUT</a>
<?php
foreach($arrProducts as $product) ?>
<span class="proWrap">
<span class="left"><a href="https://example.com/<?php echo $product['productUrl'] ?>/"><img src="<?php echo $product['productImage'] ?>" /></a></span>
<span class="right"><a href="https://example.com/<?php echo $product['productUrl']?>/"><?php echo$product['productName']?></a><br><br>
<b>$<?php echo$product['productPrice']?></b><br><br>Qty: <?php echo $product['productQty']?>
</span>
</span>
<?php ?>
<span class="viewcart"><a href="https://example.com/checkout/cart/">VIEW AND EDIT CART</a></span>
</span>
<?php else ?>
<span class="emptyCart">You have no items in your shopping cart.</span>
<?php ?>
</div>








share




























    0















    I have the following code in an external file(same domain) to get the current cart details, and I'm getting all details without any issues.



    The problem is, when I go to the checkout page using 'Go to checkout' and press browser back button this cart gets empty. I mean only on this external file.



    When I click the 'view and edit cart' and uses the browser back button the cart is fine.



    Any help would be appreciated!



    <?php
    ini_set("display_errors", true);
    ini_set("error_reporting", E_ALL);

    require '/var/www/html/app/bootstrap.php';

    $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
    $app = $bootstrap->createApplication('MagentoFrameworkAppHttp');
    $obj = MagentoFrameworkAppObjectManager::getInstance();
    $obj->get('MagentoFrameworkAppState')->setAreaCode('frontend');

    $storeManager = $obj->create("\Magento\Store\Model\StoreManagerInterface");
    $storeManager->setCurrentStore(1);

    $state = $obj->get('MagentoFrameworkAppState');

    // Getting the object managers dependencies
    $quote = $obj->get('MagentoCheckoutModelSession')->getQuote();
    $shoppingcart = $obj->get('MagentoCheckoutModelCart');

    $imagehelper = $obj->get('MagentoCatalogHelperImage');

    // Get quote and cart items collection
    $quote = $shoppingcart->getQuote();
    $quoteitems = $quote->getAllItems();

    // Getting cart
    $cart= $shoppingcart->getCart();

    // Getting the subtotal of the cart
    $subtotal = number_format($quote->getBaseSubtotal(), 2);
    $qty = 0;

    $arrProducts = array();
    $mediaurl= $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
    $baseurl = $storeManager->getStore()->getBaseUrl();

    $j = 0;
    foreach ($quoteitems as $item)

    $arrProducts[$j]['productID'] = $item->getProductId();
    $arrProducts[$j]['productName'] = $item->getName();
    $arrProducts[$j]['productQty'] = $item->getQty();
    $arrProducts[$j]['productPrice'] = number_format($item->getPrice(),2);

    $qty += $item->getQty();

    $_product = $obj->get('MagentoCatalogModelProduct')->load($item->getProductId());
    $arrProducts[$j]['productUrl'] = $_product->getUrlKey();
    $arrProducts[$j]['productImage'] = $mediaurl.'catalog/product'.$_product->getSmallImage();

    $j++;
    ?>

    <div class="CustomMiniCart">
    <?php
    if($qty > 0 && !empty($arrProducts)) ?>
    <span class="miniCartWrap">
    Cart Subtotal: <b>$<?php echo $subtotal; ?></b>
    <span class="numItems"><b><?php echo count($arrProducts);?></b> Item(s) in Cart</span>
    <a href="https://example.com/checkout/" class="chk">GO TO CHECKOUT</a>
    <?php
    foreach($arrProducts as $product) ?>
    <span class="proWrap">
    <span class="left"><a href="https://example.com/<?php echo $product['productUrl'] ?>/"><img src="<?php echo $product['productImage'] ?>" /></a></span>
    <span class="right"><a href="https://example.com/<?php echo $product['productUrl']?>/"><?php echo$product['productName']?></a><br><br>
    <b>$<?php echo$product['productPrice']?></b><br><br>Qty: <?php echo $product['productQty']?>
    </span>
    </span>
    <?php ?>
    <span class="viewcart"><a href="https://example.com/checkout/cart/">VIEW AND EDIT CART</a></span>
    </span>
    <?php else ?>
    <span class="emptyCart">You have no items in your shopping cart.</span>
    <?php ?>
    </div>








    share
























      0












      0








      0








      I have the following code in an external file(same domain) to get the current cart details, and I'm getting all details without any issues.



      The problem is, when I go to the checkout page using 'Go to checkout' and press browser back button this cart gets empty. I mean only on this external file.



      When I click the 'view and edit cart' and uses the browser back button the cart is fine.



      Any help would be appreciated!



      <?php
      ini_set("display_errors", true);
      ini_set("error_reporting", E_ALL);

      require '/var/www/html/app/bootstrap.php';

      $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
      $app = $bootstrap->createApplication('MagentoFrameworkAppHttp');
      $obj = MagentoFrameworkAppObjectManager::getInstance();
      $obj->get('MagentoFrameworkAppState')->setAreaCode('frontend');

      $storeManager = $obj->create("\Magento\Store\Model\StoreManagerInterface");
      $storeManager->setCurrentStore(1);

      $state = $obj->get('MagentoFrameworkAppState');

      // Getting the object managers dependencies
      $quote = $obj->get('MagentoCheckoutModelSession')->getQuote();
      $shoppingcart = $obj->get('MagentoCheckoutModelCart');

      $imagehelper = $obj->get('MagentoCatalogHelperImage');

      // Get quote and cart items collection
      $quote = $shoppingcart->getQuote();
      $quoteitems = $quote->getAllItems();

      // Getting cart
      $cart= $shoppingcart->getCart();

      // Getting the subtotal of the cart
      $subtotal = number_format($quote->getBaseSubtotal(), 2);
      $qty = 0;

      $arrProducts = array();
      $mediaurl= $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
      $baseurl = $storeManager->getStore()->getBaseUrl();

      $j = 0;
      foreach ($quoteitems as $item)

      $arrProducts[$j]['productID'] = $item->getProductId();
      $arrProducts[$j]['productName'] = $item->getName();
      $arrProducts[$j]['productQty'] = $item->getQty();
      $arrProducts[$j]['productPrice'] = number_format($item->getPrice(),2);

      $qty += $item->getQty();

      $_product = $obj->get('MagentoCatalogModelProduct')->load($item->getProductId());
      $arrProducts[$j]['productUrl'] = $_product->getUrlKey();
      $arrProducts[$j]['productImage'] = $mediaurl.'catalog/product'.$_product->getSmallImage();

      $j++;
      ?>

      <div class="CustomMiniCart">
      <?php
      if($qty > 0 && !empty($arrProducts)) ?>
      <span class="miniCartWrap">
      Cart Subtotal: <b>$<?php echo $subtotal; ?></b>
      <span class="numItems"><b><?php echo count($arrProducts);?></b> Item(s) in Cart</span>
      <a href="https://example.com/checkout/" class="chk">GO TO CHECKOUT</a>
      <?php
      foreach($arrProducts as $product) ?>
      <span class="proWrap">
      <span class="left"><a href="https://example.com/<?php echo $product['productUrl'] ?>/"><img src="<?php echo $product['productImage'] ?>" /></a></span>
      <span class="right"><a href="https://example.com/<?php echo $product['productUrl']?>/"><?php echo$product['productName']?></a><br><br>
      <b>$<?php echo$product['productPrice']?></b><br><br>Qty: <?php echo $product['productQty']?>
      </span>
      </span>
      <?php ?>
      <span class="viewcart"><a href="https://example.com/checkout/cart/">VIEW AND EDIT CART</a></span>
      </span>
      <?php else ?>
      <span class="emptyCart">You have no items in your shopping cart.</span>
      <?php ?>
      </div>








      share














      I have the following code in an external file(same domain) to get the current cart details, and I'm getting all details without any issues.



      The problem is, when I go to the checkout page using 'Go to checkout' and press browser back button this cart gets empty. I mean only on this external file.



      When I click the 'view and edit cart' and uses the browser back button the cart is fine.



      Any help would be appreciated!



      <?php
      ini_set("display_errors", true);
      ini_set("error_reporting", E_ALL);

      require '/var/www/html/app/bootstrap.php';

      $bootstrap = MagentoFrameworkAppBootstrap::create(BP, $_SERVER);
      $app = $bootstrap->createApplication('MagentoFrameworkAppHttp');
      $obj = MagentoFrameworkAppObjectManager::getInstance();
      $obj->get('MagentoFrameworkAppState')->setAreaCode('frontend');

      $storeManager = $obj->create("\Magento\Store\Model\StoreManagerInterface");
      $storeManager->setCurrentStore(1);

      $state = $obj->get('MagentoFrameworkAppState');

      // Getting the object managers dependencies
      $quote = $obj->get('MagentoCheckoutModelSession')->getQuote();
      $shoppingcart = $obj->get('MagentoCheckoutModelCart');

      $imagehelper = $obj->get('MagentoCatalogHelperImage');

      // Get quote and cart items collection
      $quote = $shoppingcart->getQuote();
      $quoteitems = $quote->getAllItems();

      // Getting cart
      $cart= $shoppingcart->getCart();

      // Getting the subtotal of the cart
      $subtotal = number_format($quote->getBaseSubtotal(), 2);
      $qty = 0;

      $arrProducts = array();
      $mediaurl= $storeManager->getStore()->getBaseUrl(MagentoFrameworkUrlInterface::URL_TYPE_MEDIA);
      $baseurl = $storeManager->getStore()->getBaseUrl();

      $j = 0;
      foreach ($quoteitems as $item)

      $arrProducts[$j]['productID'] = $item->getProductId();
      $arrProducts[$j]['productName'] = $item->getName();
      $arrProducts[$j]['productQty'] = $item->getQty();
      $arrProducts[$j]['productPrice'] = number_format($item->getPrice(),2);

      $qty += $item->getQty();

      $_product = $obj->get('MagentoCatalogModelProduct')->load($item->getProductId());
      $arrProducts[$j]['productUrl'] = $_product->getUrlKey();
      $arrProducts[$j]['productImage'] = $mediaurl.'catalog/product'.$_product->getSmallImage();

      $j++;
      ?>

      <div class="CustomMiniCart">
      <?php
      if($qty > 0 && !empty($arrProducts)) ?>
      <span class="miniCartWrap">
      Cart Subtotal: <b>$<?php echo $subtotal; ?></b>
      <span class="numItems"><b><?php echo count($arrProducts);?></b> Item(s) in Cart</span>
      <a href="https://example.com/checkout/" class="chk">GO TO CHECKOUT</a>
      <?php
      foreach($arrProducts as $product) ?>
      <span class="proWrap">
      <span class="left"><a href="https://example.com/<?php echo $product['productUrl'] ?>/"><img src="<?php echo $product['productImage'] ?>" /></a></span>
      <span class="right"><a href="https://example.com/<?php echo $product['productUrl']?>/"><?php echo$product['productName']?></a><br><br>
      <b>$<?php echo$product['productPrice']?></b><br><br>Qty: <?php echo $product['productQty']?>
      </span>
      </span>
      <?php ?>
      <span class="viewcart"><a href="https://example.com/checkout/cart/">VIEW AND EDIT CART</a></span>
      </span>
      <?php else ?>
      <span class="emptyCart">You have no items in your shopping cart.</span>
      <?php ?>
      </div>






      magento-2.1 checkout cart





      share












      share










      share



      share










      asked 2 mins ago









      ASRASR

      816




      816




















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269634%2fexternal-file-cart-empties-when-using-browser-back-button%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f269634%2fexternal-file-cart-empties-when-using-browser-back-button%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Nidaros erkebispedøme

          Birsay

          Where did Arya get these scars? Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara Favourite questions and answers from the 1st quarter of 2019Why did Arya refuse to end it?Has the pronunciation of Arya Stark's name changed?Has Arya forgiven people?Why did Arya Stark lose her vision?Why can Arya still use the faces?Has the Narrow Sea become narrower?Does Arya Stark know how to make poisons outside of the House of Black and White?Why did Nymeria leave Arya?Why did Arya not kill the Lannister soldiers she encountered in the Riverlands?What is the current canonical age of Sansa, Bran and Arya Stark?