Zen Cart Logo
Forums / All Other Contributions/Addons / Merging Dual Pricing Mod and Group Pricing Mod

Merging Dual Pricing Mod and Group Pricing Mod

Views: 1,085

Results 1 to 7 of 7
7 Dec 2013, 4:44 PM
#1
dewaltdave avatar

dewaltdave

New Zenner

Join Date:
Dec 2013
Location:
UK
Posts:
3
Plugin Contributions:
0

Merging Dual Pricing Mod and Group Pricing Mod

Hi, I have successfully merged 99% of both the Dual Pricing Module and the Group Pricing Module which basically gives me 4 Group prices per product and as many wholesale prices as I wish to enter, I can also add more groups later should I wish - this all works as expected except I am having some trouble with the very last part of the integration where the prices are displayed - The problem is in the functions_prices.php file under

// computes products_price + option groups lowest attributes price of each group when on

If I enter the code from either the Dual Pricing Module or the Group Pricing Module into this section the relevant part works as expected - I don't believe the issue is that it won't work and more that I am very inexperienced with PHP coding and that I am not editing it correctly.

Any help would be gratefully appreciated - and please without wishing to sound rude I really don't want this to turn into a debate about the right and wrong way to price products - I have read so many forum posts about the pricing mods and they always seem to turn into heated debates as to how pricing should and shouldn't be done.

If I can sort this small issue I am sure others would be able to make use of this new super mod so to speak as it gives many different pricing options per product and it only shows sale prices to group (or retail) customers and not to wholesale customers.

Please don't be too harsh - whilst I have reasonable experience with Zen Cart my knowledge with PHP is sadly lacking.

This is how I have coded it - (I should say one of the ways I have tried - having spent a fair few hours editing this section of code)

////
// computes products_price + option groups lowest attributes price of each group when on
//Dual Pricing
  function zen_get_products_base_price($products_id) {
    global $db;
    
    if($_SESSION['customer_id']){
       $customer_group_query = "select gp.group_name
                                 from " . TABLE_CUSTOMERS . " cu
                                 left join " . TABLE_GROUP_PRICING . " gp on cu.customers_group_pricing=gp.group_id
                                 where cu.customers_id = " . $_SESSION['customer_id'];
        if($customer_group = $db->Execute($customer_group_query)) {
          $customers_group=$customer_group->fields['group_name'];
        }
     }

     $product_check = $db->Execute("select products_price, products_price_w, products_group_a_price, products_group_b_price, products_group_c_price, products_group_d_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

// is there a products_price to add to attributes
		if($customers_group) {
        if($customers_group == GROUP_PRICE_PER_ITEM1 && $product_check->fields['products_group_a_price'] != 0) {
          $products_price = $product_check->fields['products_group_a_price'];
        } elseif($customers_group == GROUP_PRICE_PER_ITEM2 && $product_check->fields['products_group_b_price'] != 0) {
          $products_price = $product_check->fields['products_group_b_price'];
        } elseif($customers_group == GROUP_PRICE_PER_ITEM3 && $product_check->fields['products_group_c_price'] != 0) {
          $products_price = $product_check->fields['products_group_c_price'];
        } elseif($customers_group == GROUP_PRICE_PER_ITEM4 && $product_check->fields['products_group_d_price'] != 0) {
          $products_price = $product_check->fields['products_group_d_price'];
       	} elseif ($_SESSION['customer_whole']) {
		if ($_SESSION['customer_whole'] != '0') {
			$i = (int)$_SESSION['customer_whole'];
			$i--;			
      		$products_price_array = $product_check->fields['products_price_w'];
			$productsprice = explode("-",$products_price_array);
			$products_price = (float)$productsprice[$i];
			if ($products_price == '0' || $products_price == '') {
				$products_price = (float)$productsprice[0];
			}
			
			if ($products_price=='0'){
				$products_price = $product_check->fields['products_price'];
			}
			
		} else {
      		$products_price = $product_check->fields['products_price'];
		}

} else {
	$products_price = $product_check->fields['products_price'];
   }
  }
 }

And here are the two sections of code I have been trying to integrate

Original code from Dual Pricing module

////
// computes products_price + option groups lowest attributes price of each group when on
//Dual Pricing
  function zen_get_products_base_price($products_id) {
    global $db;
      $product_check = $db->Execute("select products_price, products_price_w, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

// is there a products_price to add to attributes
//Dual Pricing start
if ($_SESSION['customer_whole']) {
		if ($_SESSION['customer_whole'] != '0') {
			$i = (int)$_SESSION['customer_whole'];
			$i--;			
      		$products_price_array = $product_check->fields['products_price_w'];
			$productsprice = explode("-",$products_price_array);
			$products_price = (float)$productsprice[$i];
			if ($products_price == '0' || $products_price == '') {
				$products_price = (float)$productsprice[0];
			}
			
			if ($products_price=='0'){
				$products_price = $product_check->fields['products_price'];
			}
			
		} else {
      		$products_price = $product_check->fields['products_price'];
		}

} else {
	$products_price = $product_check->fields['products_price'];
}
      // do not select display only attributes and attributes_price_base_included is true
      $product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, options_values_price_w, attributes_display_only, attributes_price_base_included, round(concat(price_prefix, options_values_price), 5) as value from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id, value");

//Dual Pricing end
      $the_options_id= 'x';
      $the_base_price= 0;
// add attributes price to price
      if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) {
        while (!$product_att_query->EOF) {
          if ( $the_options_id != $product_att_query->fields['options_id']) {
            $the_options_id = $product_att_query->fields['options_id'];
//Dual Pricing start
            if ($_SESSION['customer_whole']) {
		if ($_SESSION['customer_whole'] != '0') {
			$i = (int)$_SESSION['customer_whole'];
		$i--;		
		$option_price_array = $product_att_query->fields['options_values_price_w'];
		$optionprice = explode(",",$option_price_array);
		$options_values_price = (float)$optionprice[$i];
		
		if ($options_values_price=='0' || $options_values_price==''){
			$options_values_price = (float)$optionprice[0];
		}
      		$the_base_price += $options_values_price;
				if ($options_values_price=='0'){
			$the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
	  	  }
		} else {
      		$the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
		}

} else {
  $the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
}
          }
//Dual Pricing end
          $product_att_query->MoveNext();
        }

        $the_base_price = $products_price + $the_base_price;
      } else {
        $the_base_price = $products_price;
      }
      return $the_base_price;
  }

And the original code from Group Pricing module

////
// computes products_price + option groups lowest attributes price of each group when on
  function zen_get_products_base_price($products_id) {
    global $db;

     if($_SESSION['customer_id']) {
       $customer_group_query = "select gp.group_name
                                 from " . TABLE_CUSTOMERS . " cu
                                 left join " . TABLE_GROUP_PRICING . " gp on cu.customers_group_pricing=gp.group_id
                                 where cu.customers_id = " . $_SESSION['customer_id'];
        if($customer_group = $db->Execute($customer_group_query)) {
          $customers_group=$customer_group->fields['group_name'];
        }
     }

     $product_check = $db->Execute("select products_price,  products_group_a_price, products_group_b_price, products_group_c_price, products_group_d_price, products_priced_by_attribute from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");

// is there a products_price to add to attributes
		  $products_price = $product_check->fields['products_price'];
      if($customers_group) {
        if($customers_group == GROUP_PRICE_PER_ITEM1 && $product_check->fields['products_group_a_price'] != 0) {
          $products_price = $product_check->fields['products_group_a_price'];
        } elseif($customers_group == GROUP_PRICE_PER_ITEM2 && $product_check->fields['products_group_b_price'] != 0) {
          $products_price = $product_check->fields['products_group_b_price'];
        } elseif($customers_group == GROUP_PRICE_PER_ITEM3 && $product_check->fields['products_group_c_price'] != 0) {
          $products_price = $product_check->fields['products_group_c_price'];
        } elseif($customers_group == GROUP_PRICE_PER_ITEM4 && $product_check->fields['products_group_d_price'] != 0) {
          $products_price = $product_check->fields['products_group_d_price'];
        }
      }
      // do not select display only attributes and attributes_price_base_included is true
      $product_att_query = $db->Execute("select options_id, price_prefix, options_values_price, attributes_display_only, attributes_price_base_included, round(concat(price_prefix, options_values_price), 5) as value from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and attributes_display_only != '1' and attributes_price_base_included='1'". " order by options_id, value");

      $the_options_id= 'x';
      $the_base_price= 0;
// add attributes price to price
      if ($product_check->fields['products_priced_by_attribute'] == '1' and $product_att_query->RecordCount() >= 1) {
        while (!$product_att_query->EOF) {
          if ( $the_options_id != $product_att_query->fields['options_id']) {
            $the_options_id = $product_att_query->fields['options_id'];
            $the_base_price += (($product_att_query->fields['price_prefix'] == '-') ? -1 : 1) * $product_att_query->fields['options_values_price'];
          }
          $product_att_query->MoveNext();
        }

        $the_base_price = $products_price + $the_base_price;
      } else {
        $the_base_price = $products_price;
      }
      return $the_base_price;
  }
7 Dec 2013, 6:53 PM
#2
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Merging Dual Pricing Mod and Group Pricing Mod

You may want to peek at the source of Twitch Wholesale with Attributes http://www.zen-cart.com/downloads.php?do=file&id=1771

The wholesale filter is easier to work with and it correctly calculates attributes pricing for retail/wholesale.

I am currently integrating each default ZenCart v1.51 module to work with it, starting with Specials, SaleMaker and Discount Coupons.

12 Dec 2013, 6:35 PM
#3
dewaltdave avatar

dewaltdave

New Zenner

Join Date:
Dec 2013
Location:
UK
Posts:
3
Plugin Contributions:
0

Re: Merging Dual Pricing Mod and Group Pricing Mod

twitchtoo:

You may want to peek at the source of Twitch Wholesale with Attributes http://www.zen-cart.com/downloads.php?do=file&id=1771

The wholesale filter is easier to work with and it correctly calculates attributes pricing for retail/wholesale.

I am currently integrating each default ZenCart v1.51 module to work with it, starting with Specials, SaleMaker and Discount Coupons.

Thanks for that - do you know if it would be possible to integrate group pricing into twitch wholesale?

12 Dec 2013, 6:43 PM
#4
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Merging Dual Pricing Mod and Group Pricing Mod

dewaltdave, ZC default Group Pricing does work with Twitch Wholesale pricing. I am testing it with Twitch Wholesale Attributes now :)

13 Dec 2013, 1:07 AM
#5
dewaltdave avatar

dewaltdave

New Zenner

Join Date:
Dec 2013
Location:
UK
Posts:
3
Plugin Contributions:
0

Re: Merging Dual Pricing Mod and Group Pricing Mod

I have installed the Twitch Wholesale mod (I will never need the attributes for this shop), it is mostly working except for when I try to view a product I get Warning! An error occurred - after checking the logs this is the actual error generated - I believe that some fields are missing in the database - I have found some snippets of code in the installation instructions but is there a complete sql code that will add all the required fields for this mod?

P]

[13-Dec-2013 01:47:27] PHP Fatal error:  1054:Unknown column 'p.products_base_cost' in 'field list' :: select p.products_type, p.products_id, pd.products_name, p.products_quantity,                                        p.products_image, p.products_price, p.products_price_w, p.products_base_cost, p.products_list_price, p.products_date_added,                                        p.products_last_modified, p.products_date_available,                                        p.products_status, p.products_model,                                        p.products_quantity_order_min, p.products_quantity_order_units, p.products_priced_by_attribute,                                        p.product_is_free, p.product_is_call, p.products_quantity_mixed, p.product_is_always_free_shipping,                                        p.products_quantity_order_max, p.products_sort_order                                 from products p, products_description pd, products_to_categories p2c                                 where p.products_id = pd.products_id                                 and pd.language_id = '1'                                 and p.products_id = p2c.products_id                                 and p2c.categories_id = '27' order by p.products_sort_order, pd.products_name limit 0, 10 in

 

Thanks.

13 Dec 2013, 1:16 AM
#6
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Merging Dual Pricing Mod and Group Pricing Mod

I recommend installing Twitch Base Cost and Twitch List Price to properly correct the issue... or you could add the missing field from Twitch Base Cost:

ALTER TABLE `products` ADD `products_base_cost` DECIMAL(15,2) NOT NULL DEFAULT '0.00';
13 Dec 2013, 1:24 AM
#7
twitchtoo avatar

twitchtoo

Totally Zenned

Join Date:
Apr 2007
Location:
Ontario, Canada
Posts:
1,733
Plugin Contributions:
14

Re: Merging Dual Pricing Mod and Group Pricing Mod

Separately, I did not include a grouped SQL code list to prevent people from installing the SQL first without following the steps. **Why? **While producing the installation instructions I would randomly 'check to see what it did' before everything was properly installed... not recommended.