close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Moldify cart values

Thread begun 5/28/2009 5:00 pm by neo314 | Last modified 6/03/2009 9:26 pm by neo314 | 3625 views | 6 replies |

neo314

Moldify cart values

If I move and rename a file who's name is already saved in the shopping cart, is there an easy way to change/update the cart's column value (say the "image" column) for that cart item?

Sign in to reply to this post

Ray BorduinWebAssist

You should look at the code in the update cart function in the eCart include file. It has code that updates from a form, but someone with experience writing php would be able to pretty easily see how it was done.

The cart is stored as an object and the items in an array. So updating the column is just a matter of updating the cart object and the corresponding item in the item array. The update cart function should give you insight on how to reference that object and array.

Sign in to reply to this post
Did this help? Tips are appreciated...

neo314

Well, I was hoping there was something built in. I think I resolved the issue by pushing the file move in the flow of things to just before I destroy the cart and work off the DB, but just for the sake of potential future use and because it might help someone else...

I don't see a function that just returns the item's index so I tested this and it works. Any better method?

<?php
if (!isset($_SESSION)) {
session_start();
}
//WA eCart Include
require_once("WA_eCart/MyCart_PHP.php");
$MyCart->GetContent();
// Diagnostic Display
print_r($MyCart->Items);
// Change Value
for ($n=0;$n<count($MyCart->Items);$n++) {
if ($MyCart->Items[$n]->ID == $MyProductIDValue) {
$MyCart->Items[$n]->image = $newImageName;
$MyCart->ReIndexContent();
$MyCart->ResetAll();
$MyCart->SaveCart();
break;
}
}
// Diagnostic Display
echo "<hr><hr>";
print_r($MyCart->Items);
echo "<hr><hr>";
print_r($_SESSION);
?>



It would be nice if eCart included a method like

$MyCart->SetValue($ID, "columnName", "New Value");



Thanx :D

Sign in to reply to this post

Ray BorduinWebAssist

The method wouldn't be able to work exactly like that because ID may not be the only unique column in the database. You may need ID and Color for instance to find a unique item.

The way it works now is that you need to pass all column values to the ItemIndex function to find the current index.

So it would be something like:
$updateID = $MyCart->ItemIndex($itemID, $itemName, $itemDescription, $itemWeight, $itemQuantity, $itemPrice, $yourFirstCustomColumn) ;

all columns would be ignored except those marked unique, so you could pass "" for all of the values in your case (if you added only one custom column) like:
$updateID = $MyCart->ItemIndex($itemID, "", "", "", "", "", "") ;

That would return the correct ID since none of the other columns are necessary in your case to determine a unique row.

to update that row would look something like:
$MyCart->Items[$updateID]->Column = "New Value";

Once updating the row, if that row is involved in any calculations you use, you would need to call:
$MyCart->ResetCalculations($updateID);

That will reset all of the calculations for that row.

Then you would want to commit your changes to the session or cookie where the cart is being stored so that it would persist on the next page and throughout the checkout proces.... this is done with:

$MyCart->SaveCart();

Sign in to reply to this post
Did this help? Tips are appreciated...

neo314

Ok, you refer to the database, but we are working in the object's array and the session or cookie right?

So unique means 'one of a kind' and the cart column ID is unique and that appears to be unchangeable in the GUI. I assumed that the cart ID was one of a kind. Why can't I find the cart item by ID alone regardless of whether or not there is another unique column?

Are you saying that unique means something like a concatenation of all the tagged "unique" cart columns has to be unique but not necessarily any one column?

I assume that would be so that the same product, let's say a t-shirt, could have the same ID, but one be green and one be red. That threw me because you construct the object in the DW interface so I only see the ID as receiving a comparison.

So, does $MyCart->ResetCalculations($updateID); reset cart wide calculations like Total? Would ResetAll() be better or just as good?

Sign in to reply to this post

Ray BorduinWebAssist

ResetAll resets all of the rows. It is just as good. Technically slightly less efficient. It only applies to calculations. Things like Total are recaculated when requested, so it wouldn't effect that.

Unique marked columns are to identify a unique row in your cart. The t-shirt example you gave is a good one. If you had two t-shirts, one red and one green, then the id alone wouldn't be enough to identify a unique row in the cart. You have two rows with same id only with different colors. In this example you would then have to pass both the id and the color to get an accurate index.

I did mean the eCart object item array. I was just imagining a dynamic site populated from a database that might drive that content.

Sign in to reply to this post
Did this help? Tips are appreciated...

neo314

I just happened to look at the documentation on this which reads:

  One column typically contains the unique identifier for a specific product, such as the ID column. A unique column may be selected from all available cart columns, but typically the ID column is used by default.  



That kind of goes against what we have discussed. It is the reason I appended time() to the end of my ID to make it unique because my product is somewhat complex as to the number of factors that make it a unique cart item.

You might want to update that in the docs.

Steven

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...