External file cart empties when using browser back button The 2019 Stack Overflow Developer...

Right tool to dig six foot holes?

Feature engineering suggestion required

Identify boardgame from Big movie

What is the motivation for a law requiring 2 parties to consent for recording a conversation

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

If I score a critical hit on an 18 or higher, what are my chances of getting a critical hit if I roll 3d20?

How technical should a Scrum Master be to effectively remove impediments?

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

Why can Shazam fly?

How come people say “Would of”?

What to do when moving next to a bird sanctuary with a loosely-domesticated cat?

Worn-tile Scrabble

When should I buy a clipper card after flying to OAK?

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

How to save as into a customized destination on macOS?

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

Output the Arecibo Message

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

"as much details as you can remember"

Why hard-Brexiteers don't insist on a hard border to prevent illegal immigration after Brexit?

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

What do the Banks children have against barley water?

Why not take a picture of a closer black hole?

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



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|improve this question





























    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|improve this question

























      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|improve this question














      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|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 11 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

          “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

          How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

          夢乃愛華...