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?
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?
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.
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
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();
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?
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.
I just happened to look at the documentation on this which reads:
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
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
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.