Jump to content
Sign in to follow this  
naiadomare

Related Products by Categories - I need help!

Recommended Posts

Hi all,

 

I need some help to get something I'm working on to work. It's based on the Optional Related Products (ORP) contribution and I think it could be the start of a contribution that would be useful for more people. I'm just hacking the living daylights out of it to get it to work so there's a lot of redundant, unnecessary code still in it and I've probably done some horribly ugly coding. I'm no expert, I'm what I would call a suck-it-and-see programmer. Sorry about that in advance.

 

Due to unforeseen personal circumstances, we are supposed to launch our new on-line clothes shop in TWO DAYS!!!! It's all organised into collections meaning that everything in "Short dresses > Collection X" is related to "Accessories > Collection X", etc., for example.

 

What I'm trying to do is associate whole categories and then display a selection of the products from related categories in a new page when the customer clicks on a "related products" link.

 

I've already modified the ORP back-end system to associate whole categories instead of products. It is organised in the same way by category ID master and slave ; for example:

 

Master - Category A (ID 1)------------> Slave - Category B (ID 2)

Master - Category A (ID 1)------------> Slave - Category C (ID 3)

 

So, the idea is to put a link next to each product (using it's parent category ID as "Master") that would send people to a page with a random selection of products from the "Slave" categories.

 

Does anyone have any idea of how I could go about doing this? I was thinking of modifying the product_listing.php but I'm not really sure how.

 

I think that I'd have to first make the link from the product identify its parent category to the file that would generate the listing and then fetch first its slave categories from the db and then a selection of products from these category IDs to display.

 

Any ideas? Do you even understand what I'm talking about?

 

I'm going to be in front of the computer 24 hours a day for the next few days if anyone has any ideas or if you would like specific information about anything. I would truly, really, genuinely, whole heartedly appreciate any help anyone could give me!

 

Thanks and kind regards to all,

 

Joseph

 

PS. The shop is http://www.naiadomare.com but it's just an intro page at the moment.

Share this post


Link to post
Share on other sites

Or maybe I need to use a modified version of the code that displays the related products in the product_info page?

Share this post


Link to post
Share on other sites

I've been thinking about this and I think that the most difficult thing to do is display products from multiple categories. I have absolutely no idea how to go about doing this.

 

I mean, the link would from the product would have to pass its parent category ID and then have the destination file get that IDs slave categories from the db. Up to that point I think I could probably hack together somehow but.... How could I get it to display a selection of products from various specified categories??????? The products listing page uses cpath cat_subcat1_subcat2... that doesn't work for this. I'd need something like... well, I don't know really.

 

I'M DESPERATE!!!!!!! I'm not getting paid to do this but it's for the Mrs. and she advertised that it would open in 2 days!

 

Thanks a million for anything at all, even words of encouragement!!!

 

Joseph

Share this post


Link to post
Share on other sites
I've been thinking about this and I think that the most difficult thing to do is display products from multiple categories. I have absolutely no idea how to go about doing this.

 

I mean, the link would from the product would have to pass its parent category ID and then have the destination file get that IDs slave categories from the db. Up to that point I think I could probably hack together somehow but.... How could I get it to display a selection of products from various specified categories??????? The products listing page uses cpath cat_subcat1_subcat2... that doesn't work for this. I'd need something like... well, I don't know really.

 

I'M DESPERATE!!!!!!! I'm not getting paid to do this but it's for the Mrs. and she advertised that it would open in 2 days!

 

Thanks a million for anything at all, even words of encouragement!!!

 

Joseph

 

 

How are you with MySQL? I think you need to create some new tables in mySQL to set up the correspondences between parents and slave categories. The way oscommerce does it is rather convoluted in that each subcategory has an identifiier for the immediate parent and moves up the chain.

 

So basically don't bog yourself down with how oscommerce handles subcategories. By oscommerce definition a product can only have one parent categories. What you want is a different parent- ie a related gorups parent. EG: If I sell clothes, my normal categories are Women, Men, children.

I may have subcategories of each main Category :

Women->summer,

Women->Fall, sub, sub etc

 

But what if I want a new grouping of products for all clothes that look good with sandles- ie beach wear? So some products will be members of the category Women, ->summer. But also Women-> Beach wear

 

 

You need a new link button for this new category class.

This link to related products would then trigger the loading of the sql data for the chosen parent. So a new products info page would open with this sublist of products.

 

You need to really plan out carefully and understand how each step of the shopping process sends and receives data from sql. The good news is your modfication doesn't need to be concerned with the shopping cart at all. You need to focus on the actual catalog/index.php file. The section where it spit out a products list with images. Notice in the url there is a cPath get parameter. You'll need a new GET parameter, call it rPath (for related products). A new branch in the index.php needs to check if a value is assiged to rPath and if so, select the child products of rPath and display them.

 

Good luck

Edited by aspiringdeveloper

Share this post


Link to post
Share on other sites

Hi, thanks for replying :rolleyes: ,

 

How are you with MySQL? I think you need to create some new tables in mySQL to set up the correspondences between parents and slave categories. The way oscommerce does it is rather convoluted in that each subcategory has an identifiier for the immediate parent and moves up the chain.

 

I know the bare minimum to get by. I studied some MySQL briefly about 8 years ago but I can muddle through sometimes!

 

I've actually already made a way to associate parent and slave categories based on the Related Optional Products contribution. I have an admin section where you can associate one category or subcategory to any other(s) you want. The database table has Master ID, Slave ID and an auto-incrementing association ID. I just modified the ORP code to work with Category instead of Product IDs and changed the admin drop down menus to Category Tree instead of a list of products.

 

So basically don't bog yourself down with how oscommerce handles subcategories. By oscommerce definition a product can only have one parent categories. What you want is a different parent- ie a related gorups parent. EG: If I sell clothes, my normal categories are Women, Men, children.

I may have subcategories of each main Category :

Women->summer,

Women->Fall, sub, sub etc

 

In my shop, the products are all for women (we're going to do separate men and children's shops later). It's organised into main categories like Clothes, Lingerie, Footwear, Accessories, Swimwear... Then each one has subcategories for the different kinds of products within that (eg. Clothes>Long Dresses, Short Dresses, T-Shirts, Trousers, Long Skirts, etc...) AND THEN (very important) ach of these subcategories is organised into collections OF A PARTICULAR STYLE. The stuff we've got in these "collections" are what I want to display all together when someone clicks a "related products" or "more from this collection" link. Ideally, ordered randomly so that people would see different things all the time.

 

But what if I want a new grouping of products for all clothes that look good with sandles- ie beach wear? So some products will be members of the category Women, ->summer. But also Women-> Beach wear

 

Sorry if I'm not following too well but I think that is just putting products in multiple categories. I suppose that I could then exclude these general categories from the category listing somehow but I prefer it to be more dynamic in case we change the structure.

 

You need a new link button for this new category class.

This link to related products would then trigger the loading of the sql data for the chosen parent. So a new products info page would open with this sublist of products.

 

I'm afraid you've lost me!!!

 

You need to really plan out carefully and understand how each step of the shopping process sends and receives data from sql. The good news is your modfication doesn't need to be concerned with the shopping cart at all. You need to focus on the actual catalog/index.php file. The section where it spit out a products list with images. Notice in the url there is a cPath get parameter. You'll need a new GET parameter, call it rPath (for related products). A new branch in the index.php needs to check if a value is assiged to rPath and if so, select the child products of rPath and display them.

 

From my limited understanding (or what I think I understand from my fidddling) of what OsCommerce does to display the contents of a category is use its cPath to identify it (cPath=1_2_3 if you have "category 1", "sub-category_2" ans "sub-sub-category 3") and then request each product under said category or sub-category from the database. I could have a look to check but I imagine that each product will have a category ID in its database entry and OsCommerce uses a loop to get those products that have the same Category ID as the cPath.

 

So, an "rPath" could display something other than the contents of a selected category??? I'm going to look into what the GET parameter actually is (as you can tell, I'm pretty ignorant) and see if I can get a better handle on what you're saying.

 

So, what I want to do (if I can) is put a link in the product listing that will send the parent category ID of the selected product to a piece of code that will return all of this category's "Slave Category IDs" and then display the products within all of these slave categories (preferably randomly sorted!!).

 

That's what I'm thinking but having not understood very well your suggestion for doing this, I may be on the wrong track (although I like the fact that this way I can relate the categories as I wish.

 

 

Good luck

THANKS!!!!!!!!!

 

 

Really, thanks for getting back to me on this. It's helpful even just to talk about it to see if any light bulbs come on!

 

My problem is that I'm really not that experienced with this stuff at all and how to implement it is a bit beyond me. Until I learn some more anyway!

 

Regards,

 

Joseph

 

http://www.naiadomare.com (not live yet but if someone's interested in helping, I could PM you a link and password if you promise not to try and buy anything yet!!)

Share this post


Link to post
Share on other sites
So, what I want to do (if I can) is put a link in the product listing that will send the parent category ID of the selected product to a piece of code that will return all of this category's "Slave Category IDs" and then display the products within all of these slave categories (preferably randomly sorted!!).

 

 

Let me see if I understand better now with an example.

 

Suppose I am in the category: Womens clothes->Summer->Skirts.

 

All skirts would be displayed. Skirts is the immediate category and its parent is 'Summer'. When I click on this new link on a given product in the skirts page, the parent 'Summer' is sent to a new code. The new code will look at the 'Summer' category and find all Slave Categories of 'Summer' and therefor display a consolidated page of all products that are descendants of 'Summer'?

 

Is that what you want to do?

Share this post


Link to post
Share on other sites
Let me see if I understand better now with an example.

 

Suppose I am in the category: Womens clothes->Summer->Skirts.

 

All skirts would be displayed. Skirts is the immediate category and its parent is 'Summer'. When I click on this new link on a given product in the skirts page, the parent 'Summer' is sent to a new code. The new code will look at the 'Summer' category and find all Slave Categories of 'Summer' and therefor display a consolidated page of all products that are descendants of 'Summer'?

 

Is that what you want to do?

Hello again,

 

Sorry. I should have given a decent example before. I think the short answer is "Yes, I think we're on the same page" but I'll put an example in my own words too to make sure...

 

 

Let's say that this is one product displayed in the listing for the category "Ibiza Collection(1)":

 

Clothes>Trousers>Ibiza Collection(1)>Product X

 

I have a database table in which "Ibiza Collection(1)" is the Master and the following categories are Slave (each Master>Slave relationship is a separate database entry):

 

Accessories>Belts>Ibiza Collection(2)

Foootwear>Boots>Ibiza Collection(3)

 

 

In the listing item for Product X I would like to have a button to associated products. This link could either send its parent category ID or its own ID to the new code. This code should then somehow get all of the products from the slave categories and display them. I've got the idea of displaying them in random order because that's one of the options of the ORP contrib.

 

The Optional Related Products contribution displays related products in the product_info page below the product information by calling a list from optional_related_products.php. This doesn't work for me even if I could adapt it to show the contents of various categories as I've done away with the product_info page . I've got everything in the product listing (attributes, product description, tell a friend, enlarge image, etc...). However, I don't know if the code it uses to display the related products might be a good starting point if it then gets put into into a new .php file to display a list there instead of in the index.

 

Here it is:

 

<?php
/*
 $Id: optional_related_products.php, ver 1.0 02/05/2007 Exp $
   variation to support contribution: Graphical Borders 2.1
 Copyright © 2007 Anita Cross (http://www.callofthewildphoto.com/)

 Part of Contribution: Optional Related Products Ver 4.0

 Based on code from Optional Relate Products, ver 2.0 05/01/2005
 Copyright © 2004-2005 Daniel Bahna (daniel.bahna@gmail.com)

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Released under the GNU General Public License
*/
 $orderBy = 'ORDER BY ';
 $orderBy .= (RELATED_PRODUCTS_RANDOMIZE)?'rand()':'pop_order_id, pop_id';
 $orderBy .= (RELATED_PRODUCTS_MAX_DISP)?' limit ' . RELATED_PRODUCTS_MAX_DISP:'';
 $attributes = "
        SELECT
        pop_products_id_slave,
        products_name,
        products_model,
        products_price,
        products_quantity,
        products_tax_class_id,
        products_image
        FROM " .
        TABLE_PRODUCTS_RELATED_PRODUCTS . ", " .
        TABLE_PRODUCTS_DESCRIPTION . " pa, ".
        TABLE_PRODUCTS . " pb
        WHERE pop_products_id_slave = pa.products_id
        AND pa.products_id = pb.products_id
        AND language_id = '" . (int)$languages_id . "'
        AND pop_products_id_master = '".$HTTP_GET_VARS['products_id']."'
        AND products_status='1' " . $orderBy;
 $attribute_query = tep_db_query($attributes);

 if (mysql_num_rows($attribute_query)>0) {
 $count = 0;
?>
   <tr>
     <?php echo mws_header(TEXT_RELATED_PRODUCTS); ?>
     <td align="center" class="productListing-data">
       <table border="0" cellspacing="0" cellpadding="2" width="100%" align="center">
       <tr>
<?php
   while ($attributes_values = tep_db_fetch_array($attribute_query)) {
     $products_name_slave = ($attributes_values['products_name']);
     $products_model_slave = ($attributes_values['products_model']);
     $products_qty_slave = ($attributes_values['products_quantity']);
     $products_id_slave = ($attributes_values['pop_products_id_slave']);
     if ($new_price = tep_get_products_special_price($products_id_slave)) {
       $products_price_slave = $currencies->display_price($new_price, tep_get_tax_rate($attributes_values['products_tax_class_id']));
     } else {
       $products_price_slave = $currencies->display_price($attributes_values['products_price'], tep_get_tax_rate($attributes_values['products_tax_class_id']));
     }
     echo '<td class="productListing-data" align="center">' . "\n";
     // show thumb image if Enabled
     if (RELATED_PRODUCTS_SHOW_THUMBS == 'True') {
       echo '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">' . "\n"
            . tep_image(DIR_WS_IMAGES . $attributes_values['products_image'], $attributes_values['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT, 'hspace="5" vspace="5"').'</a><br>' . "\n";
     }
     $caption = '';
     if (RELATED_PRODUCTS_SHOW_NAME == 'True') {
       $caption .=  '<p>' . $products_name_slave . '</p>' . "\n";
       if (RELATED_PRODUCTS_SHOW_MODEL == 'True') {
         $caption .= '<p>' . $products_model_slave . '</p>' . "\n";
       }
     } elseif (RELATED_PRODUCTS_SHOW_MODEL == 'True') {
       $caption .=  '<p>' . $products_model_slave . '</p>' . "\n";
     }
     if (RELATED_PRODUCTS_SHOW_PRICE == 'True') {
       $caption .= '<p>' . sprintf(RELATED_PRODUCTS_PRICE_TEXT, $products_price_slave) . '</p>' . "\n";
     }
     if (RELATED_PRODUCTS_SHOW_QUANTITY == 'True') {
       $caption .= '<p>' . sprintf(RELATED_PRODUCTS_QUANTITY_TEXT, $products_qty_slave) . '</p>' . "\n";
     }
     echo '<a href="'
                       . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products_id_slave) . '">'
                       . $caption . '</a>' . "\n";
     if (RELATED_PRODUCTS_SHOW_BUY_NOW== 'True') {
       echo '<a href="'
                       . tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action'))
                       . 'action=rp_buy_now&rp_products_id=' . $products_id_slave) . '">'
                       . tep_image_button('button_rp_buy_now.gif', IMAGE_BUTTON_RP_BUY_NOW) . '</a>';
     }
     echo '</td>' . "\n";
     $count++;
     if ((RELATED_PRODUCTS_USE_ROWS == 'True') && ($count%RELATED_PRODUCTS_PER_ROW == 0)) {
       echo '</tr><tr>' . "\n";
     }
   }
?>
       </tr></table>
     </td>
     <?php echo mws_footer(''); ?>
   </tr>
<?php
}
?>

 

 

 

Regards from Madrid,

 

Joseph

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×