Multi-Add-to-Cart Template Issues

Questions and answers about ShopSite Custom Templates

Multi-Add-to-Cart Template Issues

Postby chris » Tue Jul 03, 2012 10:12 am

Hi,
I am trying to implement the multi-add-to-cart template which will loop through selected items assigned to this template and put checkboxes next to them and include an add to cart button.
I have followed the directions provided <a href=" http://www.shopsite.com/templates/cookbook/tips-multiaddtocart-page.shtml">here</a> These directions do not mention how to create the template, however. I copied the contents provided for the page template, pasted them into a text editor and save as .sst file then uploaded to the cgi-bin/sc/templates/pages directory on my server. I named the template 'MyPageTemplate.sst'
I did the same for the Product Template, calling it 'myprodtemplate.sst' and uploading it to cgi-bin/sc/templates/products folder.
In MyPageTemplate.sst I changed this line [--PRODUCT --] to [-- PRODUCT myprodtemplate --] to assign the product template to the display of the products

I created a page from the Shopsite admin area: Manage Shopsite > Pages > Create New Page
I named it 'cc_cart' and titled it 'Another Cart'
Under Layout Info of the same Page Creation page, I selected the template 'MyPageTemplate.sst' and saved the settings.
Next, I assigned items to the page:
Manage Shopsite > Assign Items > Product (clicked proceed, selected 3 products, clicked Save Changes)
Clicked Preview and nothing happens.

What am I missing or doing wrong? Thanks for your help.
chris
 
Posts: 6
Joined: Tue Jul 03, 2012 9:19 am

Re: Multi-Add-to-Cart Template Issues

Postby Jim » Tue Jul 03, 2012 11:52 am

Page Preview opens in a new window (or tab if you browser is so configured). The window/tab can sometimes be hidden behind other windows so check all your open browser windows to see if it is hidden somewhere.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: Multi-Add-to-Cart Template Issues

Postby Jim » Tue Jul 03, 2012 12:55 pm

If you want to see the actual page instead of a preview (which doesn't show all features) give your page a file name on the Edit Page Content screen. The field is located in the Advanced Info section near the bottom of the screen. The filename should be something that ends in .html or another valid html page extension. Then you need to publish by clicking on the Publish tab that appears on the right side of navbar at the top of the page. Then click on the My Store icon and change the index.html part of the url to the filename you gave the page.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: Multi-Add-to-Cart Template Issues

Postby chris » Tue Jul 03, 2012 2:39 pm

Thanks. I created another page this time giving it a .php extension in the filename field but when I assign products to it and then go to preview I get the following error: Template Error: Could not find template file x in *****/cgi-bin/sc/templates/products/'myprodtemplate'
chris
 
Posts: 6
Joined: Tue Jul 03, 2012 9:19 am

Re: Multi-Add-to-Cart Template Issues

Postby Jim » Tue Jul 03, 2012 3:13 pm

To quote from your first post
"I did the same for the Product Template, calling it 'myprodtemplate.sst' and uploading it to cgi-bin/sc/templates/products folder,"
and
"In MyPageTemplate.sst I changed this line [--PRODUCT --] to [-- PRODUCT myprodtemplate --] to assign the product template to the display of the products
"
So your product template is not "myprodtemplate" as you specified in the [-- PRODUCT myprodtemplate --] tag but "myprodtemplate.sst" So the tag should be [-- PRODUCT myprodtemplate.sst --] Change that and that error will go away.

Unless your server is configured to use php and you actually have php in your pages you shouldn't use that extension.

Templates should not be uploaded to the sc/templates directory, that directory is where ShopSite puts templates and they will be replaced with new versions when a store is upgraded. Depending on the operating system your store is running on the entire directory will be deleted and recreated on an upgrade so any templates you put in that directory could be lost. The proper place for merchant created templates is in the stores data directory in a templates/ directory tree similar to the one that the ShopSite templates are placed in. These templates will not be replaced on an upgrade so you won't run the risk of losing them. These templates will appear at the bottom of the list of templates in places where you can assign them in the backoffice of ShopSite, such as Pages > Edit page layout; Products < Edit Product Layout; Preferences > Search Settings > Search Layout; Commerce Setup > Order System > Layout info. When you edit templates from Merchandising > Custom Templates > ... the templates are read from the merchant area, or you can use the Copy ShopSite ... button to make a copy of any of the ShopStie template files into your merchant area.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: Multi-Add-to-Cart Template Issues

Postby chris » Tue Jul 03, 2012 4:38 pm

Thank you very much! Your clarifications were very helpful. So if I want to apply my own coding and styling, that would be in the page template?
chris
 
Posts: 6
Joined: Tue Jul 03, 2012 9:19 am

Re: Multi-Add-to-Cart Template Issues

Postby Jim » Tue Jul 03, 2012 9:00 pm

It depends on what you want to style. If it is something specific to the product, such as make the name red, then that would be done in the product template (or a style in the product template and the class in a css file). If it is something that relates to the entire page then that would be done in the page template, or if you use styles they could be included in a .css file
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: Multi-Add-to-Cart Template Issues

Postby chris » Wed Jul 04, 2012 11:17 am

Hi,
After getting it working I sadly realized how inappropriate a solution this is for what I want to do.
Please look at http://www.collegefair.info/early_fall_2012_registration.php
To create that page, I am using Shopsite's buy anywhere button links. I query a database of our products to get the information about each fair and generate the add to cart button link using the sku as the indentifier for the shopsite button, like so:

<a href="-/order.cgi?storeid=-&dbname=products&sku=THE_PRODUCT_SKU&function=add">
<img src="-/store/shopsite-images/en-US/buttons/modern-bl/modern-bl-addtocart.gif" border="0"></a>

As said earlier, I want to change the 'add to cart' buttons into 'multi add to cart' checkboxes so users can select multiple items.
By querying our own database (instead of querying the products in the shopsite database), I can group fairs by type, add a variety of information about each fair and link to googlemaps for each fair, etc.

I can get halfway to my goal if I generate option tags for checkboxes like so:
<input type="checkbox" name="mycheckboxes[]" value="THE_PRODUCT_SKU" id="THE_PRODUCT_SKU">
(where THE_PRODUCT_SKU is a variable holding the appropriate sku value )

but when I do this, the script taken from the multi-add-to-cart template wants the product id from the shopsite db instead of the sku:
[-- DEFINE PRODUCT --]
<P><input type="checkbox" name="itemnum" value="[-- PRODUCT.RECORDNUMBER --]">
This code comes from the product template that was cut and pasted from the shopsite template cookbook demo. So, is there a shopsite value for "itemsku"??

Basically, I'm just trying to adapt your multi-add-to-cart code to work with sku's instead of itemnum, as your shopsite code for the buy anywhere links already does. It should be very simple. This way, the same items can be referenced in both our database and shopsite's database.

Thanks so much! I believe this would greatly add to the flexibility of the cart!

Here is the product template:
[-- DEFINE PRODUCT --]
<P><input type="checkbox" name="itemnum" value="[-- PRODUCT.RECORDNUMBER --]">
If I change this to PRODUCT.Sku

[--PRODUCT.Name--]
[--PRODUCT.Price--]

Quantity <input type="text" size="2" name="[-- PRODUCT.RECORDNUMBER --]:qnty" value="1">
If I chang size="60" and name="[PRODUCT.Sku]"

<br>[-- Product.ProductDescription --]


[-- IF PRODUCT.DisplayOrderingOptions --]
<br>[-- PRODUCT.OptionText --]
[-- ORDER_OPTION_MENU LINE --]
[-- END_IF --]
</p>
[-- END_DEFINE PRODUCT --]
Could I achieve my goal?
chris
 
Posts: 6
Joined: Tue Jul 03, 2012 9:19 am

Re: Multi-Add-to-Cart Template Issues

Postby Jim » Wed Jul 04, 2012 7:52 pm

<P><input type="checkbox" name="itemnum" value="[-- PRODUCT.RECORDNUMBER --]">
If I change this to PRODUCT.Sku

Correct, you would change the PRODUCT.RECORDNUMBER to PRODUCT.SKU
Quantity <input type="text" size="2" name="[-- PRODUCT.RECORDNUMBER --]:qnty" value="1">
If I chang size="60" and name="[PRODUCT.Sku]"

Partially correct, you would change the PRODUCT.RECORDNUMBER to PRODUCT.SKU. However, unless you are going to allow people to buy a gazillion items there is no reason to have the quantity box be bigger than 2 or 3 decimal places. This field is not for the sku of the item it is for the quantity that the person wants to buy. What are you trying to put into that field?

In order to use a checkbox to have the shopper select just which items to add to the cart you would have to write javascript to check the checkboxes and see which are checked and only submit those that have the box checked. As the code currently functions all items would be added to the cart with whatever quantity is in the input field for the "[-- PRODUCT.SKU --]:qnty" line above. If you set the value to "0" instead of "1" then the item will attempt to be added to the cart with a quantity of 0 so it wouldn't actually be added or would be removed on the first recalc of the cart.

Make the above changes to your template and try it and see how it works, then if you really think you need the checkbox for each product you could look into how that would be done. This topic has been discussed several times in the forum so a search of the forum might give you additional information.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: Multi-Add-to-Cart Template Issues

Postby chris » Thu Jul 05, 2012 9:27 am

Hi and thank you.
So this gets me closer but the forum has a lot of entries and my query is difficult to put in an suitable search term.
In order to use a checkbox to have the shopper select just which items to add to the cart you would have to write javascript to check the checkboxes and see which are checked and only submit those that have the box checked.

I'm using php but is there a specific way the array needs to be formatted in the post variable? Please see the bottom of the form...

Here is the script I'm using:
<html>
<body>
<h1>Newer Cart</h1>

<form action="-/order.cgi" method="post">


<input type=image src="-/media/add_to_cart.gif" name="Add to Cart" alt="Add to Cart">
<input type=image src="-/media/view_cart.gif" name="View Cart" alt="View Cart">
<BR>

<?php
/*DATABASE QUERY, OUTPUT RESULTS OF LOOP
<td><input type="checkbox" name="CHECKBOXES[]" value="{$-['SKU']}" id="{$-['SKU']}"
END;
$CHECKBOX = $_REQUEST['CHECKBOXES'];
if(!isset($CHECKBOX))
$CHECKBOX = array();
echo in_array('this',$CHECKBOX)?'checked = "checked"':'';
print <<<END
><label for=" ">{$-['SKU']}</label><br />
</td>


</tr>
END;

}
echo '</tbody>';
echo '</table>';

echo '</div>';

}


}

?>
<input type="hidden" name="storeid" value="-">
<input type="hidden" name="dbname" value="products">
<input type="hidden" name="sku" value="<?php echo $CHECKBOX ?>">
<input type="hidden" name="function" value="add">


<input type=image src="-/media/add_to_cart.gif" name="Add to Cart" alt="Add to Cart">
<input type=image src="-/media/view_cart.gif" name="View Cart" alt="View Cart">


</form>
</body>
</html>
chris
 
Posts: 6
Joined: Tue Jul 03, 2012 9:19 am

Re: Multi-Add-to-Cart Template Issues

Postby Jim » Thu Jul 05, 2012 10:21 am

I don't know anything about php so can't help there.

The form needs to submit to the full url of the shopping cart, so this needs to change <form action="-/order.cgi" method="post">

The order of the parameters shouldn't matter.

The storeid needs to be specified in <input type="hidden" name="storeid" value="-"> I assume you may have left that out for the post but it will need to be in the action.

This line needs to be included for each product on the page.
<input type="hidden" name="sku" value="<?php echo $CHECKBOX ?>">
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah

Re: Multi-Add-to-Cart Template Issues

Postby chris » Fri Jul 06, 2012 10:19 am

HI again,

I get the following error when trying to submit :
Error in Form!..
Please specify a valid value for the itemnum .

What is itemnum looking for? I'm guessing it's the item number (or index) in the shopsite database. But I am hoping to use the sku instead since that is the same in both our database and the shopsite database - just like with the buy anywhere buttons. Does this make sense?

To workaround this, I would normally script something along the following pseudocode:
var shopsite_product_id = select id from shopsite_product_database where shopsite_database_product_sku = mysku;
and then I could send the itemnum in my form but since I don't have access to the shopsite database, what do you recommend?
chris
 
Posts: 6
Joined: Tue Jul 03, 2012 9:19 am

Re: Multi-Add-to-Cart Template Issues

Postby Jim » Fri Jul 06, 2012 1:24 pm

Make sure that you have SKU's for all of your products. Then go to Merchandising > Order Anywhere and check the box at the bottom of the screen "Use SKU instead of item number" (or Use SKU instead of global unique ID depending on which version of ShopSite you have.) Then Save changes and try adding the products to the cart again.
Jim
Site Admin
 
Posts: 4953
Joined: Fri Aug 04, 2006 1:42 pm
Location: Utah


Return to Custom Template Questions

Who is online

Users browsing this forum: No registered users and 114 guests

cron