close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Shipping rule doesn't work after clearing cart

Thread began 10/17/2017 5:22 pm by phil107723 | Last modified 10/18/2017 4:22 pm by Ray Borduin | 1359 views | 7 replies |

phil107723

Shipping rule doesn't work after clearing cart

I have a flatrate shipping rule of adding $7 if there is an item in the cart. This works until the cart is cleared and then a new item is added so if a shopper decides they don't want the items and chooses something else, the rule only starts adding when there are 2 items added.

What have I done wrong?

Thanks

Sign in to reply to this post

Ray BorduinWebAssist

You probably set up the rule to only add if there are more than one items in the cart. I'd have to see the cart file to know for sure, but that sounds like what you are describing.

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

phil107723

Hi Ray
Here is the code for eCart1_PHP.php.

<?php
require_once("WA_eCart_Definition_PHP.php");
class eCart1_Definition extends WA_eCartDefinition {
function eCart1_Definition($CartName, $PersistanceType, $CurrencyPrefix, $ForceDecimalsC, $DecimalPlacesC, $CurrencyAlign, $WeightSuffix, $ForceDecimalsW, $DecimalPlacesW, $WeightAlign, $NumberDisplay) {
$this->WA_eCartDefinition($CartName, $PersistanceType, $CurrencyPrefix, $ForceDecimalsC, $DecimalPlacesC, $CurrencyAlign, $WeightSuffix, $ForceDecimalsW, $DecimalPlacesW, $WeightAlign, $NumberDisplay);
}
//start node
function ResetCalculations($itmObj) {
$itmObj->TotalWeight = $itmObj->Weight * $itmObj->Quantity;//w
$itmObj->TotalPrice = $itmObj->Price * $itmObj->Quantity;//c
$itmObj->FullDetails = $itmObj->Quantity . ' ' . $itmObj->Name . ' (' . $itmObj->ID . ')';//t
return $itmObj;
}
//end node
//start node
function ItemIndex($itemID, $itemName, $itemDescription, $itemWeight, $itemQuantity, $itemPrice, $itemFragrance) {
for ($n=0; $n<sizeof($this->Items); $n++) {
if ($this->Items[$n]) {
if ((strcmp($this->Items[$n]->ID, $itemID) === 0) AND (strcmp($this->Items[$n]->Fragrance, $itemFragrance) === 0)) {
return $n;
}
}
}
return -1;
}
//end node
//start node
function AddToCart($AddIfIn, $RedirectIfIn, $itemID, $itemName, $itemDescription, $itemWeight, $itemQuantity, $itemPrice, $itemFragrance) {
if (get_magic_quotes_gpc()) {
$itemName = stripslashes($itemName);
$itemDescription = stripslashes($itemDescription);
$itemFragrance = stripslashes($itemFragrance);
}
$inCartID = $this->ItemIndex($itemID, $itemName, $itemDescription, $itemWeight, $itemQuantity, $itemPrice, $itemFragrance);
$itemQuantity = floatval($itemQuantity);
if ($inCartID >= 0) {
if ($AddIfIn == 0) {
$this->Items[$inCartID]->Quantity = floatval($this->Items[$inCartID]->Quantity) + $itemQuantity;
if ($this->Items[$inCartID]->Quantity < 0) {
$this->Items[$inCartID]->Quantity = 0;
}
if ($this->Items[$inCartID]->Quantity == 0) {
$this->DeleteFromCart($inCartID, true);
}
else {
$this->Items[$inCartID] = $this->ResetCalculations($this->Items[$inCartID]);
}
}
if ($AddIfIn == 2 && $itemQuantity > 0) {
$this->Items[] = new eCart1_ItemDefinition($itemID, $itemName, $itemDescription, $itemWeight, $itemQuantity, $itemPrice, $itemFragrance);
}
if ($AddIfIn == 4 && $itemQuantity > 0) {
$this->DeleteFromCart($inCartID, true);
$this->Items[] = new eCart1_ItemDefinition($itemID, $itemName, $itemDescription, $itemWeight, $itemQuantity, $itemPrice, $itemFragrance);
}
if ($RedirectIfIn != "") {
$this->redirStr = $RedirectIfIn;
}
}
else {
if ($itemQuantity > 0) {
$this->Items[] = new eCart1_ItemDefinition($itemID, $itemName, $itemDescription, $itemWeight, $itemQuantity, $itemPrice, $itemFragrance);
}
}
$this->ResetAll();
$this->SaveCart();
}
//end node
//start node
function DefineRules() {
$this->Discounts = array();
$this->Charges = array();
$this->Tax = array();
$this->Shipping = array();
$this->ShippingIsTaxed = false;
//Discounts
//Charges
//Tax
//Shipping
$this->Shipping[] = new WA_eCart_Rule(urldecode("Flat%20Rate"), true, "WAEC_eCart1_FlatRate");
}
//end node
//start node
//eCart Rule
function WAEC_eCart1_FlatRate() {
$totalShipping = 0;
if (true && (($this->InCart("1") == true))) {
$totalShipping += 7;//Result
}
return WA_eCart_FormatNumber($totalShipping, $this->ForceDecimalsC, $this->DecimalPlacesC);
}
//eCart Rule
//end node
//start node
function UpdateCart() {
for ($n=0; $n<sizeof($this->Items); $n++) {
$itemDelete = (isset($_POST[$this->CartName."_Delete_".$n]))?$_POST[$this->CartName."_Delete_".$n]:null;
$resetCalcs = false;
$itemID = null;
if (isset($_POST[$this->CartName."_ID_hid_".$n])) {
$itemID = floatval($_POST[$this->CartName."_ID_hid_".$n]);
}
if (isset($_POST[$this->CartName."_ID_list_".$n])) {
$itemID = floatval($_POST[$this->CartName."_ID_list_".$n]);
}
if (isset($_POST[$this->CartName."_ID_".$n])) {
$itemID = floatval($_POST[$this->CartName."_ID_".$n]);
}
if (isset($_POST[$this->CartName."_ID_check_".$n])) {
$itemID = floatval($_POST[$this->CartName."_ID_check_".$n]);
}
$itemName = null;
if (isset($_POST[$this->CartName."_Name_hid_".$n])) {
$itemName = $_POST[$this->CartName."_Name_hid_".$n];
}
if (isset($_POST[$this->CartName."_Name_list_".$n])) {
$itemName = $_POST[$this->CartName."_Name_list_".$n];
}
if (isset($_POST[$this->CartName."_Name_".$n])) {
$itemName = $_POST[$this->CartName."_Name_".$n];
}
if (isset($_POST[$this->CartName."_Name_check_".$n])) {
$itemName = $_POST[$this->CartName."_Name_check_".$n];
}
$itemDescription = null;
if (isset($_POST[$this->CartName."_Description_hid_".$n])) {
$itemDescription = $_POST[$this->CartName."_Description_hid_".$n];
}
if (isset($_POST[$this->CartName."_Description_list_".$n])) {
$itemDescription = $_POST[$this->CartName."_Description_list_".$n];
}
if (isset($_POST[$this->CartName."_Description_".$n])) {
$itemDescription = $_POST[$this->CartName."_Description_".$n];
}
if (isset($_POST[$this->CartName."_Description_check_".$n])) {
$itemDescription = $_POST[$this->CartName."_Description_check_".$n];
}
$itemWeight = null;
if (isset($_POST[$this->CartName."_Weight_hid_".$n])) {
$itemWeight = floatval($_POST[$this->CartName."_Weight_hid_".$n]);
}
if (isset($_POST[$this->CartName."_Weight_list_".$n])) {
$itemWeight = floatval($_POST[$this->CartName."_Weight_list_".$n]);
}
if (isset($_POST[$this->CartName."_Weight_".$n])) {
$itemWeight = floatval($_POST[$this->CartName."_Weight_".$n]);
}
if (isset($_POST[$this->CartName."_Weight_check_".$n])) {
$itemWeight = floatval($_POST[$this->CartName."_Weight_check_".$n]);
}
$itemQuantity = null;
if (isset($_POST[$this->CartName."_Quantity_hid_".$n])) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_hid_".$n]);
}
if (isset($_POST[$this->CartName."_Quantity_list_".$n])) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_list_".$n]);
}
if (isset($_POST[$this->CartName."_Quantity_".$n])) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_".$n]);
}
if (isset($_POST[$this->CartName."_Quantity_check_".$n])) {
$itemQuantity = floatval($_POST[$this->CartName."_Quantity_check_".$n]);
}
$itemPrice = null;
if (isset($_POST[$this->CartName."_Price_hid_".$n])) {
$itemPrice = floatval($_POST[$this->CartName."_Price_hid_".$n]);
}
if (isset($_POST[$this->CartName."_Price_list_".$n])) {
$itemPrice = floatval($_POST[$this->CartName."_Price_list_".$n]);
}
if (isset($_POST[$this->CartName."_Price_".$n])) {
$itemPrice = floatval($_POST[$this->CartName."_Price_".$n]);
}
if (isset($_POST[$this->CartName."_Price_check_".$n])) {
$itemPrice = floatval($_POST[$this->CartName."_Price_check_".$n]);
}
$itemFragrance = null;
if (isset($_POST[$this->CartName."_Fragrance_hid_".$n])) {
$itemFragrance = $_POST[$this->CartName."_Fragrance_hid_".$n];
}
if (isset($_POST[$this->CartName."_Fragrance_list_".$n])) {
$itemFragrance = $_POST[$this->CartName."_Fragrance_list_".$n];
}
if (isset($_POST[$this->CartName."_Fragrance_".$n])) {
$itemFragrance = $_POST[$this->CartName."_Fragrance_".$n];
}
if (isset($_POST[$this->CartName."_Fragrance_check_".$n])) {
$itemFragrance = $_POST[$this->CartName."_Fragrance_check_".$n];
}
if (isset($itemID)) {
$this->Items[$n]->ID = $itemID;
$resetCalcs = true;
}
if (isset($itemName)) {
$this->Items[$n]->Name = $itemName;
$resetCalcs = true;
}
if (isset($itemDescription)) {
$this->Items[$n]->Description = $itemDescription;
$resetCalcs = true;
}
if (isset($itemWeight)) {
$this->Items[$n]->Weight = $itemWeight;
$resetCalcs = true;
}
if (isset($itemQuantity)) {
$this->Items[$n]->Quantity = $itemQuantity;
$resetCalcs = true;
}
if (isset($itemPrice)) {
$this->Items[$n]->Price = $itemPrice;
$resetCalcs = true;
}
if (isset($itemFragrance)) {
$this->Items[$n]->Fragrance = $itemFragrance;
$resetCalcs = true;
}
if (is_numeric($itemQuantity)) {
if ($itemQuantity < 0) {
$itemQuantity = 0;
}
if ($itemQuantity == 0) {
$this->DeleteFromCart($n, false);
$resetCalcs = false;
}
else {
if ($this->Items[$n]->Quantity != $itemQuantity) {
$this->Items[$n]->Quantity = floatval($itemQuantity);
$resetCalcs = true;
}
}
}
if (isset($itemDelete) && $itemDelete != "") {
$this->DeleteFromCart($n, false);
$resetCalcs = false;
}
if ($resetCalcs) {
$this->Items[$n] = $this->ResetCalculations($this->Items[$n]);
}
}
$this->ReIndexContent();
$this->ResetAll();
$this->SaveCart();
}
//end node
}
?>
<?php
// eCart Language Pack [En]
$eCart1 = new eCart1_Definition("eCart1", 0, "$", true, 2, 0, "oz", true, 2, 1, 0);
$eCart1->cartAction = "";
$eCart1->redirStr = "";
?>
<?php
class eCart1_ItemDefinition {
var $ID;
var $Name;
var $Description;
var $Weight;
var $Quantity;
var $Price;
var $Fragrance;
var $TotalWeight;
var $TotalPrice;
var $FullDetails;
//define
function eCart1_ItemDefinition($itemID, $itemName, $itemDescription, $itemWeight, $itemQuantity, $itemPrice, $itemFragrance) {
//columns
$this->ID = $itemID;//n√
$this->Name = $itemName;//t
$this->Description = $itemDescription;//t
$this->Weight = $itemWeight;//w
$this->Quantity = $itemQuantity;//n
$this->Price = $itemPrice;//c
$this->Fragrance = $itemFragrance;//t√
//calculations
$this->TotalWeight = $this->Weight * $this->Quantity;//w
$this->TotalPrice = $this->Price * $this->Quantity;//c
$this->FullDetails = $this->Quantity . ' ' . $this->Name . ' (' . $this->ID . ')';//t
}
}
?>


Can you help me edit the code as I can't use ecart until I get the activation issue sorted.
Many thanks
Phil

Sign in to reply to this post

Ray BorduinWebAssist

Please attach the actual file in the future instead of copy/paste the content so that I can open it with Dreamweaver.

It looks like your shipping rule is set up to only charge if an item with the ID = 1 is in the cart. I think you can update it to use if quantity of items in the cart is > 0 instead.

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

phil107723

Oops! Sorry! Just because mine isn't working and it's been a while since I was last here.
(I was wanting to add $7 when there is at least one item in the cart and not $7 per item)
How would I change that code without the use of the ecart wizard?

This is the shipping bit:
//start node
//eCart Rule
function WAEC_eCart1_FlatRate() {
$totalShipping = 0;
if (true && (($this->InCart("1") == true))) {
$totalShipping += 7;//Result
}
return WA_eCart_FormatNumber($totalShipping, $this->ForceDecimalsC, $this->DecimalPlacesC);
}
//eCart Rule
//end node
And I have attached the original file this time as well.
Thanks

Attached Files
eCart1_PHP.php
Sign in to reply to this post

Ray BorduinWebAssist

if (true && ((sizeof($this->Items) > 0))) {

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

phil107723

That was fast. I'll try it out.

Sign in to reply to this post

phil107723

Another lesson learned form the masters at Webassist .

Thank you
Phil

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...