Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2010
    Posts
    319
    Plugin Contributions
    0

    Default help to write function to return qty prices

    hi,
    i have attempted to write this function, i want to return all the qty prices for a product id

    i would like it to list all discounts for a product i have tried this and get 1 qty discount

    PHP Code:
    function zen_get_products_qty_discount($products_id) {
        global 
    $db;
        
    $qtydiscount "select products_id, discount_qty, discount_price
                        from " 
    TABLE_PRODUCTS_DISCOUNT_QUANTITY "
                        where products_id = '" 
    $products_id "' order by discount_price DESC";

          
    $qtydiscount_values $db->Execute($qtydiscount);

          while (!
    $qtydiscount_values->EOF) {
            
    $qtydiscount_array[] = array('qty' => $qtydiscount_values->fields['discount_qty'],
                                       
    'price' => $qtydiscount_values->fields['discount_price']);

            
    $qtydiscount_values->MoveNext();
            }
        return 
    "Buy " $qtydiscount_values->fields['discount_qty'] . " " $qtydiscount_values->fields['discount_price'];
        } 

    and i have tried this which returns the word array

    PHP Code:
    function zen_get_products_qty_discount($products_id) {
        global 
    $db;
        
    $qtydiscount "select products_id, discount_qty, discount_price
                        from " 
    TABLE_PRODUCTS_DISCOUNT_QUANTITY "
                        where products_id = '" 
    $products_id "' order by discount_price DESC";

          
    $qtydiscount_values $db->Execute($qtydiscount);

          while (!
    $qtydiscount_values->EOF) {
            
    $qtydiscount_array[] = array('qty' => $qtydiscount_values->fields['discount_qty'],
                                       
    'price' => $qtydiscount_values->fields['discount_price']);

            
    $qtydiscount_values->MoveNext();
            }
        
    //return "Buy " . $qtydiscount_values->fields['discount_qty'] . " " . $qtydiscount_values->fields['discount_price'];
        
    return $qtydiscount_array;
        } 
    any help appreciated
    bn

  2. #2
    Join Date
    Jun 2005
    Location
    Cumbria, UK
    Posts
    10,262
    Plugin Contributions
    3

    Default Re: help to write function to return qty prices

    Where is this information intended to be rendered? Zencart already has a quantity discount function.
    19 years a Zencart User

  3. #3
    Join Date
    Apr 2010
    Posts
    319
    Plugin Contributions
    0

    Default Re: help to write function to return qty prices

    i am experimenting at the minute with doing away with attributes and just using products with a master product status or sub product status

    here is link to site

    http://catchagrip.co.uk/masterproduc...&products_id=1

    you will see below 2 t shirts qty rates but i really want to show all the rates at the minute it is just showing the cheapest

    thanks
    bryan

  4. #4
    Join Date
    Apr 2010
    Posts
    319
    Plugin Contributions
    0

    Default Re: help to write function to return qty prices

    the below code is doing my job from another post on this forum, except it gives a fixed amount of discounts of 5, any one know how to change this so it only shows the amount of discounts used, some might have 1 some might have more

    thanks
    Bryan

    PHP Code:
    $products_discount_type zen_products_lookup($relatedResult->fields['products_id'], $what_field 'products_discount_type');
    $columns ++;
    $products_id_current = (int)$relatedResult->fields['products_id'];
    $quantityDiscounts = array();
    $products_discount_type_from zen_products_lookup($relatedResult->fields['products_id'], $what_field 'products_discount_type_from');
    require(
    DIR_WS_MODULES zen_get_module_directory(FILENAME_PRODUCTS_QUANTITY_DISCOUNTS));

    // The following lines are my long & heavy but seemingly functional code, I've adapted it from tpl_modules_products_quantity_discounts as I couldn't get the foreach statement to work here

    $discount_level_1 $quantityDiscounts[0];
    $discount_level_2 $quantityDiscounts[1];
    $discount_level_3 $quantityDiscounts[2];// This goes up to 5 discount levels, add more if you have more than 5 levels
    $discount_level_4 $quantityDiscounts[3];// or remove some if you have less than 5 levels
    $discount_level_5 $quantityDiscounts[4];

    if (
    $products_discount_type != 0) {

    // I've adapted the following table style from my custom tpl_modules_product_quantity_discounts, I've made it more vertical to make it fit better, if you want the original horizontal layout you can find the code in tpl_modules_product_quantity_discounts

    //NB the TEXT_HEADER below is for ACTUAL PRICE DISCOUNTS it could be replaced with the alternatives: TEXT_HEADER_DISCOUNT_PRICES_AMOUNT_OFF or TEXT_HEADER_DISCOUNT_PRICES_PERCENTAGE.

    $lc_text '<table style="margin-top: 0.3em; margin-left: 1em; margin-right: 1em; margin-bottom: -1.5em; border:1px solid #94d9f8" cellspacing="0" cellpadding="3">
    <tr style="background: #ECF8FD; font-weight: bold">
    <td colspan="2" align="center">'
    .TEXT_HEADER_DISCOUNT_PRICES_ACTUAL_PRICE.'</font></td> </tr>

    <tr><td align="left">' 
    $show_qty '</td><td>' $currencies->display_price($show_pricezen_get_tax_rate($products_tax_class_id)) . '</td></tr>

    <tr><td align="left">' 
    $discount_level_1['show_qty'] . '</td><td>' $currencies->display_price($discount_level_1['discounted_price'], zen_get_tax_rate($products_tax_class_id)) . '</td></tr>

    <tr><td align="left">'
    $discount_level_2['show_qty'] . '</td><td>' $currencies->display_price($discount_level_2['discounted_price'], zen_get_tax_rate($products_tax_class_id)) .'</td></tr>

    <tr><td align="left">'
    $discount_level_3['show_qty'] . '</td><td>' $currencies->display_price($discount_level_3['discounted_price'], zen_get_tax_rate($products_tax_class_id)) .'</td></tr>

    <tr><td align="left">'
    $discount_level_4['show_qty'] . '</td><td>' $currencies->display_price($discount_level_4['discounted_price'], zen_get_tax_rate($products_tax_class_id)) .'</td></tr>

    <tr><td align="left">'
    $discount_level_5['show_qty'] . '</td><td>' $currencies->display_price($discount_level_5['discounted_price'], zen_get_tax_rate($products_tax_class_id)) .'</td></tr></table>' ;
    } else {
    $lc_text ='';


 

 

Similar Threads

  1. which function or class return the final price of a product?
    By weber in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 24 Mar 2011, 11:58 PM
  2. Replies: 4
    Last Post: 17 Dec 2008, 10:47 PM
  3. Replies: 8
    Last Post: 16 May 2007, 03:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR