You are here:  » Responsive HTML - Shopping List


Responsive HTML - Shopping List

Submitted by support on Wed, 2016-05-25 12:30 in

Hi everyone,

I've updated the Shopping List add-on for the latest Responsive HTML template to include price change information for watched products and the number of items in the shopping list in brackets alongside the link in the main menu.

Shopping list items view showing price change details:

Installation

Download and extract ShoppingList.zip to a temporary folder on your local computer.

Archive contains new files:

shoppingList.php
html/shoppingListItems.php

...and replacement files (15/09A distribution)

html/menu.php (adds "Shopping List (x)" menu item)
html/product.php (adds "Add to Shopping List" function to main product page)

- For a modified existing Price Tapestry installation, upload the new files only and see the notes in the follow up to this post regarding menu entry and "Add to Shopping List" functionality.

Post Installation

- html/shoppingListItems.php contains some inline CSS at the very top of the script - this can be removed from here and merged with html/default.css.

- Translations for the following can be added to includes/translate.php as required:

"My Shopping List"
"Add to Shopping List"
"This item is in your Shopping List"
"now from"
"no price change"
"Item"
"Items"
"Remove"
"Remove All"

Enjoy!

Cheers,
David
--
PriceTapestry.com

Submitted by support on Wed, 2016-05-25 12:31

For an existing / modified installation:

- To add menu entry "Shopping List (x)" use the following code within your main menu as required:

  <?php
    $shoppingListCookie = "shoppingList".bin2hex($config_baseHREF);
    $shoppingListCount = (isset($_COOKIE[$shoppingListCookie])?count(unserialize($_COOKIE[$shoppingListCookie])):"0");
  ?>
  <li>
    <a href='<?php print $config_baseHREF?>shoppingList.php'>
    <i class='fi-shopping-cart'></i>
    <?php print translate("My Shopping List"); ?> (<?php print $shoppingListCount?>)
    </a>
  </li>

- To add "Add to Shopping List" functionality, use the following code within html/product.php as required:

Look for the following code at line 58 of html/product.php:

  <?php if (isset($product_main["extraHTML"])) print $product_main["extraHTML"]; ?>

...and REPLACE with:

  <?php
    $shoppingListCookie = "shoppingList".bin2hex($config_baseHREF);
    $product_shoppingList = (isset($_COOKIE[$shoppingListCookie])?unserialize($_COOKIE[$shoppingListCookie]):array());
    if (isset($product_shoppingList[$product_main["name"]]))
    {
      $product_shoppingListHTML = "<a href='".$config_baseHREF."shoppingList.php'><i class='fi-check'></i> ".translate("This item is in your Shopping List")."</a>";
    }
    else
    {
      $product_shoppingListHTML = "<a href='".$config_baseHREF."shoppingList.php?add=".urlencode($product_main["name"])."'><i class='fi-shopping-cart'></i> ".translate("Add to Shopping List")."</a>";
    }
  ?>
  <p><?php print $product_shoppingListHTML?></p>
  <?php if (isset($product_main["extraHTML"])) print $product_main["extraHTML"]; ?>

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Wed, 2016-06-08 17:07

Hi David,

I have implemented this on the product page.

Would it be possible to adapt shopping list to use on the results page so that users could select products via a button/tick box/text and save for later?

BR

Richard

Submitted by support on Wed, 2016-06-08 18:17

Hello Richard,

Sure - Add to / In Shopping List links can be added to search results - firstly, add the following PHP section to the very top of html/searchresults.php:

<?php
  $shoppingListCookie 
"shoppingList".bin2hex($config_baseHREF);
  
$shoppingList = (isset($_COOKIE[$shoppingListCookie])?unserialize($_COOKIE[$shoppingListCookie]):array());
?>

And then within the loop, at the point you wish to display the link (e.g. below the More Information / Compare Prices button, use:

<?php
  
if (isset($shoppingList[$product["name"]]))
  {
    print 
"<br /><a href='".tapestry_shoppingListHREF()."'><i class='fi-check'></i> ".translate("In Shopping List")."</a>";
  }
  else
  {
    print 
"<br /><a href='".tapestry_shoppingListHREF()."?add=".urlencode($product["name"])."'><i class='fi-shopping-cart'></i> ".translate("Add to Shopping List")."</a>";
  }
?>

If you'd prefer to have shoppingList.php redirect back to the page from where "Add to Shopping List" was clicked, look for the following code at line 54:

  header("Location: ".$config_baseHREF."shoppingList.php");

...and REPLACE with:

  header("Location: ".$_SERVER["HTTP_REFERER"]);

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Wed, 2016-06-08 18:56

Brilliant :) :)

Thank you!

Submitted by Keeop on Thu, 2016-06-09 14:54

Hi David,

I'm having caching issues with this. If I add a product to the Shopping List, it updates the header when on the actual Shopping List page to '1' or whatever, but when navigating back to a different page, the count is back to '0'. Any ideas how I can force a refresh on this?

Cheers.
Keeop

Submitted by support on Thu, 2016-06-09 15:19

Hello Keeop,

I'll look into this further - depending on the caching headers that you're sending for main pages "Back" functionality can be implemented by the browser without any network activity at all - in which case, if you would be happy to use the redirect back to referrer as described at the end of this post above, that may force a reload, but again does depend on the caching headers being sent but that might an option..

Cheers,
David.
--
PriceTapestry.com

Submitted by Keeop on Thu, 2016-06-09 15:41

Hi David,

I've implemented that and also moved the 'getcookie' bit to the header so it should always re-run it. It's definitely writing to the cookie straight away as I can see that. Just not reading it back in. This is on a sub-domain, so don't know if that effects cookies? I've disabled caching for that site although haven't explicitly set 'no-cache'. I'll do that and check the headers.

Cheers.
Keeop

Submitted by Keeop on Thu, 2016-06-09 16:04

Yep, caching on my proxy/reverse proxy server! Very strange though as I use cookies on my other sites, using the same PHP methods, but they update fine. Bizarre. I'll have to copy the headers I'm using from one of those on to this site as I expect that will sort it then.

Cheers.
Keeop

Submitted by keshavkshirsagar on Fri, 2016-06-10 05:09

Hi David

Its wonderful additional Change
Thanks for adding such functionality in PT

Submitted by augirl on Tue, 2016-06-28 02:10

Hi David

Made all changes but can't seem to get page to load it keeps coming up with 404 error page.
Can you assist please.

Thank You
Annette

Submitted by support on Tue, 2016-06-28 08:19

Hello Annette,

As the majority of web servers are Linux based that means that filenames are case sensitive, so if you could double check that all of your links to shoppingList.php use the "camelCase" in the name that should be all it is - if still no joy, if you could let me know the installation URL (I'll remove before publishing your reply) I'll check it out further for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by augirl on Tue, 2016-06-28 16:48

Hi David

Have two installations both are same one is at {link saved}
For some reason it no adding the comparison to link for shopping list.

Thank you
Annette

Submitted by support on Tue, 2016-06-28 17:13

Hello Annette,

I spotted the problem - my apologies, the instructions above for creating a menu link to the Shopping List (and in the download replacement html/menu.php) were hard coded to a top level installation and not using $config_baseHREF. In the code you have added to html/menu.php, where you have:

  <a href='/shoppingList.php'>

...REPLACE with;

  <a href='<?php print $config_baseHREF?>shoppingList.php'>

Corrected above, and in the download.

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Mon, 2016-08-15 22:36

Hi David,

I have noticed that if a product no longer exists in the database but is within a shopping list, the list shows the current price (£zero), the old price and a link for more information to a non existent page. There is no product name or description.

Is it possible to store product name & description in cookie and state that product is no longer available?

Best regards

Richard

Submitted by support on Tue, 2016-08-16 09:25

Hello Richard,

Thanks for pointing this out, I have updated the Shopping List add on to show products not currently available in a separate list, with an "Item not currently available." message and remove link. All text translatable through includes/translate.php as normal.

I haven't included the description but you can add this easily if you want, firstly in shoppingList.php look for the following code at line 47:

      $item["price"] = $rows[0]["price"];

...and REPLACE with:

      $item["price"] = $rows[0]["price"];
      $item["description"] = tapestry_substr($rows[0]["description"]["description"],250,"...");

And then in html/shoppingListItems.php, look for the following code at line 139:

  <p><?php print translate("Item not currently available."); ?></p>

...and REPLACE with:

  <?php if ($product["description"]): ?>
    <p><?php print $product["description"]; ?></p>
  <?php endif; ?>
  <p><?php print translate("Item not currently available."); ?></p>

Note that the above saves the tapestry_substr() truncated version of the description which will keep the size of the cookie down - synchronise the length used with the truncated length of current product descriptions in html/shoppingListItems.php at line 83...

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Tue, 2016-08-16 17:52

Thanks David,

Neat solution.

One small thing, in html/shoppinglistitems.php I moved     <?php endforeach; ?> from row 151 to 154 so that it was after the final </div>

Best regards

Richard

Submitted by support on Wed, 2016-08-17 09:40

Hi Richard,

Thanks - I checked the balancing, it was actually the closing </div> matching <div class='row pt_sr_each'> that was missing ( should have been on the line before <?php endforeach; ?> ) so you may need to correct that on your site to ensure valid markup - corrected in the download.

Cheers,
David.
--
PriceTapestry.com

Submitted by richard on Wed, 2016-08-17 22:44

Cheers, amended.

Thanks again :)

Submitted by allanch on Mon, 2016-09-19 17:32

Hi David,

This is a useful add-on you've come up with! Can you tell me if this will work for Wordpress installs and if so how you would integrate this? Thanks.

Submitted by support on Tue, 2016-09-20 08:51

Hello Allan,
I am currently working towards the next update to PriceTapestry.org for WordPress (more info and beta registration link here) and it is my intention to include Shopping List (as well as Auto-complete) in that version - hoping to release towards the beginning of next month...

Cheers,
David.
--
PriceTapestry.com

Submitted by allanch on Tue, 2016-09-20 18:01

That's cool, thanks David!

Submitted by sirmanu on Wed, 2017-01-11 11:10

Hi David!
I have noticed that I can "only" save about 16 items. My cookie is about 3906 bytes and I think, is the maximum size allowed.
Do you have any workaround? Maybe creating another cookie or with localStorage?
Regards!

Submitted by support on Wed, 2017-01-11 12:06

Hi,

I'll review this after the next update, local storage might be a little tricky as the shopping list data needs to be processed server-side in order to generate the price deltas etc., however in the mean time it's no problem to set a limit and show an alert box if the shopping list becomes full. I'll add this code to limit to 10 items in the download, but to add to an existing installation, edit shoppingList.php and look for the following code at line 37:

  if (isset($_GET["add"]))

...and REPLACE with:

  if (isset($_GET["add"]) && (count($shoppingList) >= 10))
  {
    $shoppingListFull = TRUE;
  }
  elseif (isset($_GET["add"]))

And then the following code at line 120:

  require("html/shoppingListItems.php");

...and REPLACE with:

  require("html/shoppingListItems.php");
  if (isset($shoppingListFull))
  {
    print "<script>alert('Sorry, your Shopping List is full.');</script>";
  }

Cheers,
David.
--
PriceTapestry.com

Submitted by Retro135 on Thu, 2017-01-12 18:49

This may also help reduce the amount of info saved. Don't think a shopper needs the full description here. In html > shoppingListItems.php I reduced the number of characters from 250 to 100, around line 83:
print tapestry_substr($product["description"],100,"...");

Submitted by support on Fri, 2017-01-13 09:51

Thanks for that - unfortunately description isn't actually part of the cookie data (just product name and price at time of adding in order to show the delta). I will look at a standalone JavaScript / Local Storage version after the next update releases.

Cheers,
David.
--
PriceTapestry.com

Submitted by Retro135 on Wed, 2017-04-12 23:23

I noticed the shopping list saves the original price. Is there any way to add the sale price if it exists?

Submitted by support on Thu, 2017-04-13 10:11

Hi,

To add your custom field `sale_price` in the stored record, edit shoppinglist.php and where you have the following code around line 47:

      $item["price"] = $rows[0]["price"];

...REPLACE with:

      $item["price"] = $rows[0]["price"];
      $item["sale_price"] = $rows[0]["sale_price"];

Then to have your html/shoppingListItems.php work out the price change and delta graphic based on previous and current sale_price; look for the following code at line 44:

  if ($product["price"] == $shoppingListItem["price"])

...and REPLACE with:

  if ($product["sale_price"]!="0.00") $product["price"] = $product["sale_price"];
  if ($shoppingListItem["sale_price"]!="0.00") $shoppingListItem["price"] = $shoppingListItem["sale_price"];
  if ($product["price"] == $shoppingListItem["price"])

Hope this helps! If you're not sure about the display side of things with price, sale price and the price change all involved if you could email me your latest html/searchresults.php and html/shoppingListItems.php I'll check if out further with you...

Cheers,
David.
--
PriceTapestry.com

Submitted by IG on Tue, 2018-10-23 11:45

Hi David,

What is the price change in the shopping list showing? The change in price vs. previous import or change in price vs. when the product added to the shopping list?

Kind regards,
IG

Submitted by support on Tue, 2018-10-23 11:52

Hello IG,

It's the change in price since added to the shopping list.

Cheers,
David.
--
PriceTapestry.com