Zen Cart Logo
Forums / Managing Customers and Orders / limitlimited shipped methods only with one categories

limitlimited shipped methods only with one categories

Locked

Views: 3,607

Results 21 to 30 of 30
This thread is locked. New replies are disabled.
11 Oct 2009, 4:55 PM
#21
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

limitlimited shipped methods only with one categories

That depends on what you are trying to do ...

The function in the shopping_cart.php class for: in_cart_check is checking the products table to see if there is a matching value and sending back the count ...

So, in order to do this you need the master_categories_id as that is a field in the product table and can be tested for ...

11 Oct 2009, 5:11 PM
#22
dw08gm avatar

dw08gm

Totally Zenned

Join Date:
Sep 2008
Location:
DownUnder, overlooking South Pole.
Posts:
1,016
Plugin Contributions:
2

Re: limitlimited shipped methods only with one categories

I meant in the line

if (!IS_ADMIN_FLAG && ($_SESSION['cart']->in_cart_check('master_categories_id','3') > 0 && $_SESSION['cart']->in_cart_check('master_categories_id','39') > 0)) {
  $this->enabled = false;

Is there any situation in the above line when categories_id is used?

11 Oct 2009, 7:16 PM
#23
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: limitlimited shipped methods only with one categories

Not in this case ...

It depends on what you are testing for. This IF statement is testing the Products in the cart based on their master_categories_id in the products table ...

12 Oct 2009, 8:55 AM
#24
kobra8 avatar

kobra8

Zen Follower

Join Date:
Mar 2009
Location:
Serbia
Posts:
350
Plugin Contributions:
0

Re: limitlimited shipped methods only with one categories

I put code:
.........................
// do not show if products from master_categories_id 39 and 25 are in the cart together
global $cart;
if (!IS_ADMIN_FLAG && ($_SESSION['cart']->in_cart_check('master_categories_id','25') > 0 && $_SESSION['cart']->in_cart_check('master_categories_id','39') > 0)) {
$this->enabled = false;
}
}
/**
...........................

End nothing :no:

15 Oct 2009, 3:07 PM
#25
kobra8 avatar

kobra8

Zen Follower

Join Date:
Mar 2009
Location:
Serbia
Posts:
350
Plugin Contributions:
0

Re: limitlimited shipped methods only with one categories

With big help of Ajeh the problem is solved :clap:
Here is the code of modul table.php thet works:

 <?php
/**
 * @package shippingMethod
 * @copyright Copyright 2003-2005 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: table.php 6347 2007-05-20 19:46:59Z ajeh $
 */
/**
 * Enter description here...
 *
 */
class table extends base {
  /**
   * Enter description here...
   *
   * @var unknown_type
   */
  var $code;
  /**
   * Enter description here...
   *
   * @var unknown_type
   */
  var $title;
  /**
   * Enter description here...
   *
   * @var unknown_type
   */
  var $description;
  /**
   * Enter description here...
   *
   * @var unknown_type
   */
  var $icon;
  /**
   * Enter description here...
   *
   * @var unknown_type
   */
  var $enabled;
  /**
   * Enter description here...
   *
   * @return table
   */
  function table() {
    global $order, $db;

    $this->code = 'table';
    $this->title = MODULE_SHIPPING_TABLE_TEXT_TITLE;
    $this->description = MODULE_SHIPPING_TABLE_TEXT_DESCRIPTION;
    $this->sort_order = MODULE_SHIPPING_TABLE_SORT_ORDER;
    $this->icon = '';
    $this->tax_class = MODULE_SHIPPING_TABLE_TAX_CLASS;
    $this->tax_basis = MODULE_SHIPPING_TABLE_TAX_BASIS;
    // disable only when entire cart is free shipping
    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);
    }

    if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_TABLE_ZONE > 0) ) {
      $check_flag = false;
      $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
      while (!$check->EOF) {
        if ($check->fields['zone_id'] < 1) {
          $check_flag = true;
          break;
        } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
          $check_flag = true;
          break;
        }
        $check->MoveNext();
      }

      if ($check_flag == false) {
        $this->enabled = false;
      }
    }

    // do not show if products from master_categories_id 25 and 39 are in the cart together
    global $cart;
    if (!IS_ADMIN_FLAG && ($_SESSION['cart']->in_cart_check('master_categories_id','25') > 0 && $_SESSION['cart']->in_cart_check('master_categories_id','39') > 0)) {
      $this->enabled = false;
    }
  }
  /**
   * Enter description here...
   *
   * @param unknown_type $method
   * @return unknown
   */
  function quote($method = '') {
    global $order, $shipping_weight, $shipping_num_boxes, $total_count;

    // shipping adjustment
    switch (MODULE_SHIPPING_TABLE_MODE) {
      case ('price'):
        $order_total = $_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices() ;
        break;
      case ('weight'):
        $order_total = $shipping_weight;
        break;
      case ('item'):
        $order_total = $total_count - $_SESSION['cart']->free_shipping_items();
        break;
    }

    $order_total_amount = $_SESSION['cart']->show_total() - $_SESSION['cart']->free_shipping_prices() ;

    $table_cost = split("[:,]" , MODULE_SHIPPING_TABLE_COST);
    $size = sizeof($table_cost);
    for ($i=0, $n=$size; $i<$n; $i+=2) {
      if (round($order_total,9) <= $table_cost[$i]) {
        if (strstr($table_cost[$i+1], '%')) {
          $shipping = ($table_cost[$i+1]/100) * $order_total_amount;
        } else {
          $shipping = $table_cost[$i+1];
        }
        break;
      }
    }

    if (MODULE_SHIPPING_TABLE_MODE == 'weight') {
      $shipping = $shipping * $shipping_num_boxes;
      // show boxes if weight
      switch (SHIPPING_BOX_WEIGHT_DISPLAY) {
        case (0):
        $show_box_weight = '';
        break;
        case (1):
        $show_box_weight = ' (' . $shipping_num_boxes . ' ' . TEXT_SHIPPING_BOXES . ')';
        break;
        case (2):
        $show_box_weight = ' (' . number_format($shipping_weight * $shipping_num_boxes,2) . TEXT_SHIPPING_WEIGHT . ')';
        break;
        default:
        $show_box_weight = ' (' . $shipping_num_boxes . ' x ' . number_format($shipping_weight,2) . TEXT_SHIPPING_WEIGHT . ')';
        break;
      }
    }

    $this->quotes = array('id' => $this->code,
    'module' => MODULE_SHIPPING_TABLE_TEXT_TITLE . $show_box_weight,
    'methods' => array(array('id' => $this->code,
    'title' => MODULE_SHIPPING_TABLE_TEXT_WAY,
    'cost' => $shipping + MODULE_SHIPPING_TABLE_HANDLING)));

    if ($this->tax_class > 0) {
      $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
    }

    if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

    return $this->quotes;
  }
  /**
   * Enter description here...
   *
   * @return unknown
   */
  function check() {
    global $db;
    if (!isset($this->_check)) {
      $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_TABLE_STATUS'");
      $this->_check = $check_query->RecordCount();
    }
    return $this->_check;
  }
  /**
   * Enter description here...
   *
   */
  function install() {
    global $db;
    $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) VALUES ('Enable Table Method', 'MODULE_SHIPPING_TABLE_STATUS', 'True', 'Do you want to offer table rate shipping?', '6', '0', 'zen_cfg_select_option(array(\'True\', \'False\'), ', now())");
    $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Shipping Table', 'MODULE_SHIPPING_TABLE_COST', '25:8.50,50:5.50,10000:0.00', 'The shipping cost is based on the total cost or weight of items or count of the items. Example: 25:8.50,50:5.50,etc.. Up to 25 charge 8.50, from there to 50 charge 5.50, etc<br />You can end the last amount as 10000:7% to charge 7% of the Order Total', '6', '0', 'zen_cfg_textarea(', now())");
    $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Table Method', 'MODULE_SHIPPING_TABLE_MODE', 'weight', 'The shipping cost is based on the order total or the total weight of the items ordered or the total number of items orderd.', '6', '0', 'zen_cfg_select_option(array(\'weight\', \'price\', \'item\'), ', now())");
    $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Handling Fee', 'MODULE_SHIPPING_TABLE_HANDLING', '0', 'Handling fee for this shipping method.', '6', '0', now())");
    $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_SHIPPING_TABLE_TAX_CLASS', '0', 'Use the following tax class on the shipping fee.', '6', '0', 'zen_get_tax_class_title', 'zen_cfg_pull_down_tax_classes(', now())");
    $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Tax Basis', 'MODULE_SHIPPING_TABLE_TAX_BASIS', 'Shipping', 'On what basis is Shipping Tax calculated. Options are<br />Shipping - Based on customers Shipping Address<br />Billing Based on customers Billing address<br />Store - Based on Store address if Billing/Shipping Zone equals Store zone', '6', '0', 'zen_cfg_select_option(array(\'Shipping\', \'Billing\', \'Store\'), ', now())");
    $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Shipping Zone', 'MODULE_SHIPPING_TABLE_ZONE', '0', 'If a zone is selected, only enable this shipping method for that zone.', '6', '0', 'zen_get_zone_class_title', 'zen_cfg_pull_down_zone_classes(', now())");
    $db->Execute("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_SHIPPING_TABLE_SORT_ORDER', '0', 'Sort order of display.', '6', '0', now())");
  }
  /**
   * Enter description here...
   *
   */
  function remove() {
    global $db;
    $db->Execute("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
  }
  /**
   * Enter description here...
   *
   * @return unknown
   */
  function keys() {
    return array('MODULE_SHIPPING_TABLE_STATUS', 'MODULE_SHIPPING_TABLE_COST', 'MODULE_SHIPPING_TABLE_MODE', 'MODULE_SHIPPING_TABLE_HANDLING', 'MODULE_SHIPPING_TABLE_TAX_CLASS', 'MODULE_SHIPPING_TABLE_TAX_BASIS', 'MODULE_SHIPPING_TABLE_ZONE', 'MODULE_SHIPPING_TABLE_SORT_ORDER');
  }
}
?>  
16 Oct 2009, 8:51 AM
#26
kobra8 avatar

kobra8

Zen Follower

Join Date:
Mar 2009
Location:
Serbia
Posts:
350
Plugin Contributions:
0

Re: limitlimited shipped methods only with one categories

If somebody have time can please explain proces.
How can somebody change code table.php if have categories more then 2 to restrict product to sell together.

Have aroand 6 categories, end product in thet categories can't sell together.

16 Oct 2009, 9:05 AM
#27
kobra8 avatar

kobra8

Zen Follower

Join Date:
Mar 2009
Location:
Serbia
Posts:
350
Plugin Contributions:
0

Re: limitlimited shipped methods only with one categories

To have 6 categories, thet product can't sell together, hay modify code table.php ???

https://www.kavanali.com

Dejan

16 Oct 2009, 2:12 PM
#28
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: limitlimited shipped methods only with one categories

Are you saying that ALL orders can only have Products for 1 Category at a time?

Or, are you saying that you need to not have Products from SOME Categories mix with Products from SOME other Categories?

Try to be really precise on this description in describing these limitations ...

16 Oct 2009, 2:59 PM
#29
kobra8 avatar

kobra8

Zen Follower

Join Date:
Mar 2009
Location:
Serbia
Posts:
350
Plugin Contributions:
0

Re: limitlimited shipped methods only with one categories

Ajeh:

Are you saying that ALL orders can only have Products for 1 Category at a time?

Or, are you saying that you need to not have Products from SOME Categories mix with Products from SOME other Categories?

Try to be really precise on this description in describing these limitations ...

I ment:
ALL orders can only have Products for 1 Category at a time?
Can't mix product from other Categories in one order.
One cetegories, one order.

17 Oct 2009, 12:19 AM
#30
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: limitlimited shipped methods only with one categories

This is one method that could be used if this is controlled in the shipping module, but it could also be written more efficiently:

  function table() {
    global $order, $db;

    $this->code = 'table';
    $this->title = MODULE_SHIPPING_TABLE_TEXT_TITLE;
    $this->description = MODULE_SHIPPING_TABLE_TEXT_DESCRIPTION;
    $this->sort_order = MODULE_SHIPPING_TABLE_SORT_ORDER;
    $this->icon = '';
    $this->tax_class = MODULE_SHIPPING_TABLE_TAX_CLASS;
    $this->tax_basis = MODULE_SHIPPING_TABLE_TAX_BASIS;
    // disable only when entire cart is free shipping
    if (zen_get_shipping_enabled($this->code)) {
      $this->enabled = ((MODULE_SHIPPING_TABLE_STATUS == 'True') ? true : false);
    }

    if (!IS_ADMIN_FLAG && $this->enabled) {
      // do not show if products from master_categories_id 22, 23, 24, 25 and 39 are in the cart together
      global $cart;
      $chk_valid = true;
      $chk_cat_22 = $_SESSION['cart']->in_cart_check('master_categories_id','22');
      $chk_cat_23 = $_SESSION['cart']->in_cart_check('master_categories_id','23');
      $chk_cat_24 = $_SESSION['cart']->in_cart_check('master_categories_id','24');
      $chk_cat_25 = $_SESSION['cart']->in_cart_check('master_categories_id','25');
      $chk_cat_26 = $_SESSION['cart']->in_cart_check('master_categories_id','26');
      $chk_cat_27 = $_SESSION['cart']->in_cart_check('master_categories_id','27');
      $chk_cat_28 = $_SESSION['cart']->in_cart_check('master_categories_id','28');
      $chk_cat_29 = $_SESSION['cart']->in_cart_check('master_categories_id','29');
      $chk_cat_30 = $_SESSION['cart']->in_cart_check('master_categories_id','30');
      $chk_cat_31 = $_SESSION['cart']->in_cart_check('master_categories_id','31');
      $chk_cat_32 = $_SESSION['cart']->in_cart_check('master_categories_id','32');
      $chk_cat_33 = $_SESSION['cart']->in_cart_check('master_categories_id','33');
      $chk_cat_34 = $_SESSION['cart']->in_cart_check('master_categories_id','34');
      $chk_cat_35 = $_SESSION['cart']->in_cart_check('master_categories_id','35');
      $chk_cat_39 = $_SESSION['cart']->in_cart_check('master_categories_id','39');
      if ($chk_cat_21 > 0 and ($chk_cat_22 > 0 || $chk_cat_23 > 0 || $chk_cat_24 > 0 || $chk_cat_25 > 0 || $chk_cat_26 > 0 || $chk_cat_27 > 0 || $chk_cat_28 > 0 || $chk_cat_29 > 0 || $chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0)) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_21 > 0 and ($chk_cat_22 > 0 || $chk_cat_23 > 0 || $chk_cat_24 > 0 || $chk_cat_25 > 0 || $chk_cat_26 > 0 || $chk_cat_27 > 0 || $chk_cat_28 > 0 || $chk_cat_29 > 0 || $chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_22 > 0 and ($chk_cat_23 > 0 || $chk_cat_24 > 0 || $chk_cat_25 > 0 || $chk_cat_26 > 0 || $chk_cat_27 > 0 || $chk_cat_28 > 0 || $chk_cat_29 > 0 || $chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_23 > 0 and ($chk_cat_24 > 0 || $chk_cat_25 > 0 || $chk_cat_26 > 0 || $chk_cat_27 > 0 || $chk_cat_28 > 0 || $chk_cat_29 > 0 || $chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_24 > 0 and ($chk_cat_25 > 0 || $chk_cat_26 > 0 || $chk_cat_27 > 0 || $chk_cat_28 > 0 || $chk_cat_29 > 0 || $chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_25 > 0 and ($chk_cat_26 > 0 || $chk_cat_27 > 0 || $chk_cat_28 > 0 || $chk_cat_29 > 0 || $chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_26 > 0 and ($chk_cat_27 > 0 || $chk_cat_28 > 0 || $chk_cat_29 > 0 || $chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_27 > 0 and ($chk_cat_28 > 0 || $chk_cat_29 > 0 || $chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_28 > 0 and ($chk_cat_29 > 0 || $chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_29 > 0 and ($chk_cat_30 > 0 || $chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_30 > 0 and ($chk_cat_31 > 0 || $chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_31 > 0 and ($chk_cat_32 > 0 || $chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_32 > 0 and ($chk_cat_33 > 0 || $chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_33 > 0 and ($chk_cat_34 > 0 || $chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_34 > 0 and ($chk_cat_35 > 0 || $chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      if ($chk_valid && ($chk_cat_35 > 0 and ($chk_cat_39 > 0))) {
        $chk_valid = false;
      }
      $this->enabled = $chk_valid;
    }

    if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_TABLE_ZONE > 0) ) {
      $check_flag = false;
      $check = $db->Execute("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_TABLE_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
      while (!$check->EOF) {
        if ($check->fields['zone_id'] < 1) {
          $check_flag = true;
          break;
        } elseif ($check->fields['zone_id'] == $order->delivery['zone_id']) {
          $check_flag = true;
          break;
        }
        $check->MoveNext();
      }

      if ($check_flag == false) {
        $this->enabled = false;
      }
    }
  }
  /**
   * Enter description here...
   *
   * @param unknown_type $method
   * @return unknown
   */

Another way to do this would be to re-write the display button function that once something is in the cart only products from that master_categories_id can be added to the cart ... this would prevent Products from being added to the cart once 1 Product has been added to the cart and might be more efficient in regard to saving the customer a waste of time adding Products to the cart in the first place ...

But it really would take more customization than I care to do on the forum ... :smile: