You are here:  » Adding Shoppinglist Items by ID

Active Forum Topics


Adding Shoppinglist Items by ID

Submitted by Antony on Sun, 2021-01-03 05:42 in

Hi David, Happy new year to you and the team!

I am using the Add to shopping list from search results from /node/6723

I would like to change the bellow to ad by ID (if necessary) instead of Name so that the ACTUAL product is added to the shopping list and not the MAIN. Simply modifying the below did not work as I imagine its a little more complicated.

Is there a simple way to get this to work?

{print "<a type='button' class='btn text-danger' href='".tapestry_shoppingListHREF()."?add=".urlencode($product["name"])."' title='Add to Favourites'><i class='far fa-heart'></i></a>";}

Thanks,

Ant

Submitted by support on Mon, 2021-01-04 08:59

Hello Ant and a Happy New Year to you too!

It can be modified to work on an individual product basis with just a few changes to use "id" instead of "name". First, edit includes/tapestry.php and look for the following code at line 503:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($name)."'";

...and REPLACE with:

    $sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE id='".database_safe($name)."'";

Edit html/product.php and look for the following code beginning at line 29:

    if (isset($product_shoppingList[$product_main["name"]]))
    {
      $product_shoppingListHTML = "<p><a href='".tapestry_shoppingListHREF()."'><i class='fi-check'></i> ".translate("This item is in your Shopping List")."</a></p>";
    }
    else
    {
      $product_shoppingListHTML = "<p><a href='".tapestry_shoppingListHREF()."?add=".urlencode($product_main["name"])."'><i class='fi-shopping-cart'></i> ".translate("Add to Shopping List")."</a></p>";
    }

...and REPLACE with:

    if (isset($product_shoppingList[$product_main["id"]]))
    {
      $product_shoppingListHTML = "<p><a href='".tapestry_shoppingListHREF()."'><i class='fi-check'></i> ".translate("This item is in your Shopping List")."</a></p>";
    }
    else
    {
      $product_shoppingListHTML = "<p><a href='".tapestry_shoppingListHREF()."?add=".urlencode($product_main["id"])."'><i class='fi-shopping-cart'></i> ".translate("Add to Shopping List")."</a></p>";
    }

And finally edit html/shoppinglistitems.php and look for the following code at line 80:

        <a href='?remove=<?php print urlencode($product["name"]); ?>'><i class='fi-x'></i> <?php print translate("Remove"); ?></a>

...and REPLACE with:

        <a href='?remove=<?php print urlencode($product["id"]); ?>'><i class='fi-x'></i> <?php print translate("Remove"); ?></a>

Cheers,
David.
--
PriceTapestry.com

Submitted by Antony on Mon, 2021-01-04 12:05

Many thanks David!