Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Display PRICE PER ITEM


ecoren

Recommended Posts

I need a new contrib to display price per item. (i sell packages with more items in each) 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.

 

I added a column to the products table : products_items_in_pack, till that everythings works great. 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'])) . ' ';
          }

 

i thought it might be a data type error but i tryed in phpmyadmin CODESELECT `products_price` / `products_items_in_pack` as price_per_item FROM `products` WHERE 1and 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

i found that

$listing['products_price / products_items_in_pack'

gives the zero value i guess the expression cannot be interpreted. i might do it by adding a column to products and specials (products_price_per_item and define the default value in the data entry file as price/items_in_pack) but is it the only way?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...