Thread: echo a message if total in cart from a specific manufacturer = XXX

1. echo a message if total in cart from a specific manufacturer = XXX

I need a method for the cart to calculate the total value of items from a specific manufacturer, and if the total of items in the cart from that manufacturer does not exceed a certain value, then a message is echoed in the cart screen.

The cart can contain products from many manufacturers, so it needs to work out the total from that specified manufacturer. If the total in cart from manufacturer XYZ < 1000, then echo a special message.

Checkout is still permitted - we just need to alert customers to a certain condition, if total from manufacturer XYZ are less than \$1000.

If the total value in cart from manufacturer is greater than 1000, then no message needed.

2. Re: echo a message if total in cart from a specific manufacturer = XXX

I know it has something to do with the shopping cart class area... but what? (I also know it's not an easy task... Too many variables on the pricing side.)

Basically, can I tweak this... and if so, how ?

PHP Code:
```   /**   * Method to calculate the number of items in a cart based on an abitrary property   *   * \$check_what is the fieldname example: 'products_is_free'   * \$check_value is the value being tested for - default is 1   * Syntax: \$_SESSION['cart']->in_cart_check('product_is_free','1');   *   * @param string product field to check   * @param mixed value to check for   * @return integer number of items matching restraint   */  function in_cart_check(\$check_what, \$check_value='1') {    global \$db;    // if nothing is in cart return 0    if (!is_array(\$this->contents)) return 0;    // compute total quantity for field    \$in_cart_check_qty=0;    reset(\$this->contents);    while (list(\$products_id, ) = each(\$this->contents)) {      \$testing_id = zen_get_prid(\$products_id);      // check if field it true      \$product_check = \$db->Execute("select " . \$check_what . " as check_it from " . TABLE_PRODUCTS . " where products_id='" . \$testing_id . "' limit 1");      if (\$product_check->fields['check_it'] == \$check_value) {        \$in_cart_check_qty += \$this->contents[\$products_id]['qty'];      }    }    return \$in_cart_check_qty;  }  ```
If anyone has any pointers I'd be very grateful.

3. Re: echo a message if total in cart from a specific manufacturer = XXX

Starting with that function as a potential starting-point, one could possibly use something like this as an additional function (method) added to that class:
Code:
```    function in_cart_check_value_for_manufacturer(\$mfg_id = 0, \$check_threshold=0) {
global \$db;
// if nothing is in cart return 0
if (!is_array(\$this->contents)) return 0;

// if no mfg, abort
if (\$mfg_id == 0) return 0;

// compute total for field
\$in_cart_check_value=0;

reset(\$this->contents);
while (list(\$products_id, ) = each(\$this->contents)) {
\$testing_id = zen_get_prid(\$products_id);
\$result = \$db->Execute("select * from " . TABLE_PRODUCTS . " where products_id='" . \$testing_id . "' and manufacturers_id = '" . (int)\$mfg_id . "' limit 1");
\$in_cart_check_value += number_format(\$this->contents[\$products_id]['qty'] * \$result->fields['products_price'], 2);
}
return \$in_cart_check_value;
}```
This calculates based on the product's primary price, agnostic of any discounts such as sales or specials, and ignores the addition of any taxes (or if tax-included pricing is turned on, it will of course include taxes because tax is included in prices in that case).

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•