Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

display price per unit (contribution request)


ecoren

Recommended Posts

Ciao! :blush:

 

Do u know any good contributions that display price per unit for each product? (ex. a pack contains 5 cds costs 5 eur so it should be 1 eur / cd) I guess i would need a new row in the products table: items/pack)

 

thx in advance

Link to comment
Share on other sites

Hi,

 

well i tryed to make it on my own but i have a problem. I added a column to tzhe products table : products_items_in_pack, till that everythings works great. :D After i wanted price_per_item to be calculated dinamically (seemed more simple even to to avoid problems with special price) But now in the price per item column i see 0 EUR for every item.

 

I did the followin:

 

added to index.php

 

// create column list
   $define_list = array
                        'PRODUCT_LIST_ITEMS_IN_PACK' => PRODUCT_LIST_ITEMS_IN_PACK,
                        'PRODUCT_LIST_PRICE_PER_ITEM' => PRODUCT_LIST_PRICE_PER_ITEM);

   for ($i=0, $n=sizeof($column_list); $i<$n; $i++) {
     switch ($column_list[$i])
       case 'PRODUCT_ITEMS_IN_PACK':
         $select_column_list .= 'p.products_items_in_pack, ';
         break;

$listing_sql = (...) p.products_items_in_pack
...
     switch ($column_list[$sort_col-1]) ...
       case 'PRODUCT_LIST_ITEMS_IN_PACK':
         $listing_sql .= "p.products_items_in_pack " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;
       case 'PRODUCT_PRICE_PER_ITEM':
         $listing_sql .= "final_price " . ($sort_order == 'd' ? 'desc' : '') . ", pd.products_name";
         break;

 

and to includes/modules/product_listing.php:

 

      case 'PRODUCT_LIST_ITEMS_IN_PACK':
       $lc_text = TABLE_HEADING_ITEMS_IN_PACK;
       $lc_align = 'center';
       break;
     case 'PRODUCT_LIST_PRICE_PER_ITEM':
       $lc_text = TABLE_HEADING_PRICE_PER_ITEM;
       $lc_align = 'center';
       break;

         case 'PRODUCT_LIST_ITEMS_IN_PACK':
           $lc_align = 'right';
           $lc_text = ' ' . $listing['products_items_in_pack'] . ' ';
           break;
         case 'PRODUCT_LIST_PRICE_PER_ITEM':
           $lc_align = 'right';
           if (tep_not_null($listing['specials_new_products_price'])) {
             $lc_text = ' <s>' .  $currencies->display_price($listing['products_price / products_items_in_pack'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</s>  <span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price / products_items_in_pack'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span> ';
           } else {
             $lc_text = ' ' . $currencies->display_price($listing['products_price / products_items_in_pack'], tep_get_tax_rate($listing['products_tax_class_id'])) . ' ';
           }
           break;

 

i thought it might be a data type error but i tryed in phpmyadmin

SELECT `products_price` / `products_items_in_pack` as price_per_item FROM `products` WHERE 1

and that works :

price_per_item

120.000000

265.000000

 

the items_in_pack is integer(5).

 

any ideas ;)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...