External file cart empties when using browser back button The 2019 Stack Overflow Developer Survey Results Are InModify tax rate on cart quote items and recalculateWhen getting current cart from an external file, it's emptyMagento 1.7.0.2 - Subtotal and grand total doubled in cartMagento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleUpdate QTY checkout cart Magento not working after update to 1.9.2.4Price not getting updated for second product…After rewrite MagentoCustomerModelAccountManagement giving me fatal errorMagento 2: Add a product to the cart programmaticallyWhen press browser back button cart is emptyUpdate the Price of an item when adding to the cart

Why do UK politicians seemingly ignore opinion polls on Brexit?

Aging parents with no investments

Feature engineering suggestion required

How to notate time signature switching consistently every measure

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

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

How come people say “Would of”?

Should I use my personal e-mail address, or my workplace one, when registering to external websites for work purposes?

What does Linus Torvalds mean when he says that Git "never ever" tracks a file?

FPGA - DIY Programming

Can we generate random numbers using irrational numbers like π and e?

What do the Banks children have against barley water?

What is the closest word meaning "respect for time / mindful"

Is an up-to-date browser secure on an out-of-date OS?

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

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

A poker game description that does not feel gimmicky

For what reasons would an animal species NOT cross a *horizontal* land bridge?

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

Did Scotland spend $250,000 for the slogan "Welcome to Scotland"?

Where to refill my bottle in India?

Can a flute soloist sit?

Who coined the term "madman theory"?

If a Druid sees an animal’s corpse, can they Wild Shape into that animal?



External file cart empties when using browser back button



The 2019 Stack Overflow Developer Survey Results Are InModify tax rate on cart quote items and recalculateWhen getting current cart from an external file, it's emptyMagento 1.7.0.2 - Subtotal and grand total doubled in cartMagento 2.1: Invoke urlBuilder->getUrl() in a controller in a custom moduleUpdate QTY checkout cart Magento not working after update to 1.9.2.4Price not getting updated for second product…After rewrite MagentoCustomerModelAccountManagement giving me fatal errorMagento 2: Add a product to the cart programmaticallyWhen press browser back button cart is emptyUpdate the Price of an item when adding to the cart



.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 4 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

          Magento 2 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

          Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

          How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2