Forums / Setting Up Categories, Products, Attributes / Display how many times a product has been purchased?

Display how many times a product has been purchased?

Views: 4,939

Results 1 to 20 of 30
14 Jan 2010, 6:35 AM
#1
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Display how many times a product has been purchased?

I now this information is available in the admin section in the Products Purchased Report, but I do not know how to display it in the store. I would like to display how many times a product has been purchased so the customer can see how many have been sold. Any thoughts on how to do this?

14 Jan 2010, 2:40 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: Display how many times a product has been purchased?

In the products table the field products_ordered holds the number of Products Ordered since the last reset ...

There is a function that could be used for this in the ```
functions_lookups.php file:

  • Return any field from products or products_description table
  • Example: zen_products_lookup('3', 'products_date_added');
    */
    function zen_products_lookup($product_id, $what_field = 'products_name', $language = '') {

Just send the products_id and the field that you want to obtain the value ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

14 Jan 2010, 4:00 PM
#3
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

Thanks Ajeh!
I hate to trouble you further, but I know just enough about php to be dangerous. Could you give me an idea of how to code that into the product listing? I would probably want to see it near the product price or "add to cart" button. I know how to do the css formatting if the php is coded correctly.

14 Jan 2010, 4:54 PM
#4
ajeh avatar

ajeh

Oba-san

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

Re: Display how many times a product has been purchased?

You could customize the Product Listing to show the number of products sold by copying the file:
/includes/modules/products_listing.php

to your templates and overrides directory and change the code:

        $lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '<br />' : '') : '');

to read:

        $lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '<br />' : '') : '');

        $lc_text .= '<br />' . 'Sold: ' . zen_products_lookup($listing->fields['products_id'], 'products_ordered');

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 Jan 2010, 1:15 AM
#5
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

Thanks! I have tried your suggestion, and it seems logical, but nothing displays. My client has also requested the same thing appear in the Featured Product listings on the main index page. I have tried that same code there, but nothing displays there either. Any thoughts?

27 Jan 2010, 4:17 PM
#6
ajeh avatar

ajeh

Oba-san

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

Re: Display how many times a product has been purchased?

Do you see the word Sold: at all?

Make sure that you named your templates and overrides directory correctly for:
/includes/modules/your_template_dir

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

27 Jan 2010, 5:05 PM
#7
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

I have double checked, I am placing the file in the correct directory. I also made sure I "purchased" the item, to make sure it will show that the item has sold. The sold item also shows up in the admin section where it is supposed to.

Entering the new code into the product_listing.php, nothing at all displays in the store. When I tried placing it into the featured products file, I received the word "Sold" but no quantity appeared after it.

27 Jan 2010, 5:11 PM
#8
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

I could be a bit embarrassing however, to have show up in your store.


"This product has been purchased "0" times".*****

... not a very inspirational message to give to customers.

I would even be wary if it said


"This product has been purchased "10" times".***

... only 10 times? There are 6 billion people in the world? howcome only 10 ever got sold? Can't be that good.

And sadly. if it said:


"This product has been purchased "10,000,000" times".***

... Wow... must be for common folk, not unique individuals like me... Can't be very special if every idiot is buying it!

:D

20 years a Zencart User

1 Feb 2010, 8:12 PM
#9
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

Additional thoughts, anyone?

1 Feb 2010, 9:57 PM
#10
ajeh avatar

ajeh

Oba-san

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

Re: Display how many times a product has been purchased?

In the file:
/includes/modules/product_listing.php

that you copied to your directory:
/includes/modules/your_template_dir/product_listing.php

You should have code such as:

        $the_button = $lc_button;
        $products_link = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . ( ($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : $_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id'])) . '&products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
        $lc_text .= '<br />' . zen_get_buy_now_button($listing->fields['products_id'], $the_button, $products_link) . '<br />' . zen_get_products_quantity_min_units_display($listing->fields['products_id']);
        $lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '<br />' : '') : '');
[B]        $lc_text .= '<br />' . 'Sold: ' . zen_products_lookup($listing->fields['products_id'], 'products_ordered');
[/B]
        break;

Try adding to the file:

        $the_button = $lc_button;
        $products_link = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . ( ($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : $_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id'])) . '&products_id=' . $listing->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
        $lc_text .= '<br />' . zen_get_buy_now_button($listing->fields['products_id'], $the_button, $products_link) . '<br />' . zen_get_products_quantity_min_units_display($listing->fields['products_id']);
        $lc_text .= '<br />' . (zen_get_show_product_switch($listing->fields['products_id'], 'ALWAYS_FREE_SHIPPING_IMAGE_SWITCH') ? (zen_get_product_is_always_free_shipping($listing->fields['products_id']) ? TEXT_PRODUCT_FREE_SHIPPING_ICON . '<br />' : '') : '');
[B]        $lc_text .= '<br />' . 'Sold: ' . zen_products_lookup($listing->fields['products_id'], 'products_ordered');
[/B]        
echo 'I AM THE PRODUCTS_LISTING!' . '<br>';
         break;

and see if you see that repeat a number of times in your Product Listing when you click on a Category of products ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

2 Feb 2010, 6:12 AM
#11
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

Thanks Ajeh! Success!

The client also wants to see it on the product info display and on the featured products that appear on the main page. I have been trying to figure out how to do it based on what you have shown me but am not having much luck. Can I trouble you once again for assistance?

2 Feb 2010, 2:08 PM
#12
ajeh avatar

ajeh

Oba-san

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

Re: Display how many times a product has been purchased?

The basic idea here is that to get the Sold quantity to show on the Product Listing you use the reference to the products_id as:

$listing->fields['products_id']

'Sold: ' . zen_products_lookup($listing->fields['products_id'], 'products_ordered');

For the Product Info page on the tpl_product_info_display.php you need a different reference to the products_id and use:

(int)$_GET['products_id']

'Sold: ' . zen_products_lookup((int)$_GET['products_id'], 'products_ordered');

For the Featured Listing you would use in the featured_products.php module:

$featured_products->fields['products_id']

'Sold: ' . zen_products_lookup($featured_products->fields['products_id'], 'products_ordered');

So, each file has a reference to the products_id that is unique to that file ... once you find it, then you can add the code where you want it to appear ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

3 Feb 2010, 10:02 PM
#13
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

Thanks Ajeh, partial success!

It is working in the product display, but not in the featured products. I am not sure exactly what goes where in the featured_products.php. I have tried it several ways and I either get no featured products at all on the home page, or I see the normal display without the word Sold or the number quantity. Can you be a little more specific on the code and where it goes?

4 Feb 2010, 12:20 AM
#14
ajeh avatar

ajeh

Oba-san

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

Re: Display how many times a product has been purchased?

On the home page, that is not the Featured Page ... the home page is using a different file:
/includes/modules/featured_products.php

You are using the:
$featured_products->fields['products_id']

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

4 Feb 2010, 2:53 AM
#15
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

I was already editing the modules/featured_products.php file and not having any success. Can you be more specific on the code and where it goes?

4 Feb 2010, 3:10 AM
#16
ajeh avatar

ajeh

Oba-san

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

Re: Display how many times a product has been purchased?

    $list_box_contents[$row][$col] = array('params' =>'class="centerBoxContentsFeatured centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
    'text' => (($featured_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' . $productsInCategory[$featured_products->fields['products_id']] . '&products_id=' . $featured_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $featured_products->fields['products_image'], $featured_products->fields['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT) . '</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' . $productsInCategory[$featured_products->fields['products_id']] . '&products_id=' . $featured_products->fields['products_id']) . '">' . $featured_products->fields['products_name'] . '</a><br />' . $products_price . '<br>' . 'Sold: ' . zen_products_lookup($featured_products->fields['products_id'], 'products_ordered'));

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

4 Feb 2010, 4:47 AM
#17
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

Thanks Ajeh, that worked perfectly!

I had tried exactly that, but had left off a parenthesis. Thanks again for all of your help.

4 Feb 2010, 5:26 AM
#18
ajeh avatar

ajeh

Oba-san

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

Re: Display how many times a product has been purchased?

You are most welcome ... glad that this worked for you ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

12 Feb 2010, 1:15 AM
#19
straightarrow avatar

straightarrow

New Zenner

Join Date:
Jan 2010
Posts:
10
Plugin Contributions:
0

Re: Display how many times a product has been purchased?

What we have done so far is perfect and I thought we had this taken care of, but the client has now asked for more. The site is for a fund raising effort. There will be two shirts, no other product. They have asked to have the total number of shirts, which would be the equivalent of adding together the two quantities we generated above, then display this sum in the header of the home page.

They have also asked if visitors can only see the total number of shirts header display after logging in. Is any of this even possible?

16 Feb 2010, 5:44 AM
#20
ajeh avatar

ajeh

Oba-san

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

Re: Display how many times a product has been purchased?

More or less, you should be able to get the result with this where products_id 12 and 11 are the ones being counted ...

global $db;
$sql = "SELECT sum(products_ordered) as total_sold from " . TABLE_PRODUCTS . " WHERE products_id in (12,11)";
$total_sold = $db->Execute($sql);

if ($_SESSION['customer_id'] > 0) {
  echo 'Total Sold: ' . $total_sold->fields['total_sold'];
}

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!