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

          Integral that is continuous and looks like it converges to a geometric seriesTesting if a geometric series converges by taking limit to infinitySummation of arithmetic-geometric series of higher orderGeometric series with polynomial exponentHow to Recognize a Geometric SeriesShowing an integral equality with series over the integersDiscontinuity of a series of continuous functionsReasons why a Series ConvergesSum of infinite geometric series with two terms in summationUsing geometric series for computing IntegralsLimit of geometric series sum when $r = 1$

          Why is system upgrade showing unstable version when upgrading in backend?System Settings > System Upgrade link does not existsComposer Error While upgrading magento version 2.1.6 to 2.2.2How to upgrade magento 1.4.0.0 to above 1.6 versionIssue with upgrading Magento Version from 2.1.7 to 2.1.12Magento 2.2.5: Error on running setup: upgrade after upgrading Magento from 2.2.2 to 2.2.5Are there any Magento Code Release Notes?getting error when upgrading from Magento 2.1.5 to Magento 2.2.6Will the installed third party plugins upgrade when we upgrade Magento version via composerWhy PHP Settings Check and Checking Component Dependency showing error during Magento 2.3 upgrade?Fatal error: Out of memory (in composer) during upgrade Magento2.2.1 to Magento 2.3 when run composer update command

          If gravity precedes the formation of a solar system, where did the mass come from that caused the gravity? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Where does the Solar System end?The defintion of star/planetary/solar systemSolar System formation, considering its and the universe's ageNaming of the planets of the solar systemEjected planets during the early stages of the formation of the Solar SystemWhy are some universal entities round and others are flat?Are the “extinct species” of meteorites originally from the “Barbarian” asteroids?Is the galaxy made of a nebula or the solar system?Are the planets Trappist-1 in the solar system?How is the term “solar system” defined? Could confirmation of a new planet lead to a change in this definition?