Forums / General Questions / echo a message if total in cart from a specific manufacturer = XXX

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

Started by schoolboy on 24 Jul 2012, 4:55 PM · Views: 580

Results 1 to 3 of 3
24 Jul 2012, 4:55 PM
#1
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

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.

20 years a Zencart User

5 Aug 2012, 7:52 PM
#2
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

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 ?

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

20 years a Zencart User

5 Aug 2012, 9:43 PM
#3
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,511
Plugin Contributions:
176

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:```
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;
}

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.