relation schema for dealer locator mysql and php - php

I have a project where there is a dealer locator which is supposed to locate the dealers in the area.
The dealers supply multiple brands of different items(example: cement bricks etc.).
These items have subcategories and may also have a variable length sub categories.
Under the sub categories are the brands. Brands are lowest level of that product , meaning there is no end product, all these put together is the product
These dealers have a location which is used to map them on google maps.
The locator must have filters where one can select the category and then a sub category and if exists a sub sub category . Also one can select the brand and quantity of the product.
I have tried different ways to create the database , but have failed.
I am having difficulty in accessing products which have to be displayed after selecting each filter option.
My questions:
Should I create a table for every product , if so what will be the
attribute?
How to handle the variable length sub categories ?
How can I access each product based on category or sub category or brand.
Sample schema:
table:categories(Parent_ID | Category_ID | Category_Name);
table:product (Dealer_ID| Brand_ID|Quantity); - table for each product
table:brands(brand_ID|Category_ID|Brand_Name);
table:Dealer(dealer_ID|lat|long|name ...etc.);
When the page loads all dealers are shown in the map based on location.
On selecting each option the page reloads and displays the dealers based on the selection.
With my current schema I am unable to access them based on selection.

I would create a single products table, and create an entry for each unique product (not one for each categorical permutation). So Cement Brick, Shovel, Hammer, etc.
For the categories, I would create a category map table that would have the following fields:
product_id(int), parent_category_id(int), child_category_id(int)
Both of those fields would map to a category table that would look something like: id(int), name(text), status_id(int), created_at(timestamp), updated_at(timestamp), deleted_at(timestamp)
This implementation would allow you to have as many sub-categories as you wish, and would allow for easy lookups since you'd just need to see if the child_category_id matched one in the requested filter.
As for the brand question, it really depends on how detailed you need to be concerning brand. If you don't need anything other than .. say a name, you could use First Normal Form and put the brand on the product entry itself (as a column on your products table). If you need some more details, and / or need to associate a single brand with multiple products.. you could use a basic xref.

Related

Show Filters by Category

Does anyone have any previous experience or ideas on how to proceed in the product filtering section by category on the e-commerce site?
Because the filter field in the left menu will vary according to the product category. The memory filter should appear in the phone category, but the body (S,M,L) filter should appear in the t-shirt category. The project was built in Laravel. Options and option values models are available. Should the option_id be added to the category table and set accordingly or manually?
Thanks in advance.
You can use pivot table for this purpose. If each category has its own filters and you have a filter table (you name it option here), you must create a pivot table like category_option to store categoty_id and option_id. This will help you when building filter menu in category page. Next use another table to store product_id, option_id and value for that option to store values for each individual product.

Selecting Categories to display products using PHP and MySQL

Hi is there a tutorial or some sort of resource that can help me work out how to actually select products from a database based on the category i selected, mind you the category is not just 1 tier, it will consist of a 3 tier category navigation.
meaning it should only load the page for a list of products that i have selected if i click on the third tier in that particular category, not the first or second tier, all i have the first and second tier doing is displaying a list of the child categories in that tier.
I have my categories sorted by using parent_id's in a database and i list them using PHP, i just don't know how i would go about selecting the products for a particular category, and i was wondering if i could get some resources that could assist me or help with the database side using MySQL and PHP side of things. thanks.

Catalog - place the product into categories

I am building a catalog of products and need to assign the exact categories to the item.
There are f.ex. 10 main categories with subcategories, stored in a MySQL database.
What should be a good way to allow user to go accross categories from the highest level to the lowest and select the right one? Especially if you can select more than one category for the product?
Example:
I have a banana and need to save it into:
Categories
-- colors
--- yellow
and also to
Categories
-- Fruits
--- Exotic
Currently I have two selectboxes - one selexts fro mthe main categories and the second from the subcategories. But it is a bit complicated, non user friendly and also works just with JS enabled.
Is there a ncier way how to do that? The amount of subcategories is in hundreds.
Thanks in advance.

How to include manufacturer description without using a product attribute in Magento Community Edition? PHP / XML / MySQL

In a normalized database schema, the manufacturers would have their own attributes like, for example, name, description, address, phone number.
The manufacturer description is something that is useful for the product pages. Many ecommerce sites show a manufacturer description on every product page.
As far as I know, in Magento you would have to create a product attribute, "Manufacturer description" or something like that. If, for example, ABC Corporation has 1,000 products, you would have to update all 1,000 every time you changed your description for ABC Corporation.
Is that the only reasonably easy way to do it?
Or is there a more database normal way of doing it, where a single, atomic update would result in all the manufacturer's items showing an updated value on the front end?
Create a module with the following contents:
setup script that creates a manufacturer table like desired
model and resource model classes for manufacturer
grid to manage the manufacturers (this is quite complicated, you should follow a tutorial like this or copy the basics from another module)
manufacturer block and template to render HTML for manufacturer info. You will use it as frontend model for the manufacturer_id attribute (see below)
setup script that adds a product attribute manufacturer_id
source model for the manufacturer id, so you can select the manufacturer from a dropdown instead of typing in the id
To display manufacturer description on product page without using product attribute you need to create new table "manufacturer_info" and this table contains information of manufacturer id as well as description.
Table is something like this
manufacturer_id | description
To add description, you need to create new module which will display all the shop brand s and description in grid. When you edit manufacture one form will appear and in that form add description and save it to database.
After saving description, You can display it on product page based on manufacture_id.
To get current manufacture use following code
$_product = $this->getProduct();
$manufacturerName = $_product->getAttributeText('manufacturer');
$manufacturerId = $_product->getManufacturer();
Use manufacturer_id for getting description from newly created table
I hope this helps.

eBay like database structure

I'm trying to get my head around eBay like structural database.
Given that each type of products has different columns I had to get products table then products descriptions table which is a meta table with key and value columns with product_id as foreign key for Products table
I've also got Specifications table which is hasAndBelongsToMany relationship with Subsubcategory table (which has belongsTo with Subcategory and then belongsTo Category relations)
So I've got joining table for Specifications Subsubcategory then also got Specification_Category which Specifications table belongsTo.
Now. I want my users to select a product with all those specifications of the product when they want to create a product selling page or have an option to create their custom product then enter those specific details into the Product Detail Meta Table based on pre-defined columns that are read from Specifications of that Subsubcategory.
To give you an example:
I'm now adding Specification using Scaffolding feature of Cakephp and I have a form with Name ie - 1TB, Specification Category - Hard Drive Capacity (belongsTo) and Subsubcategory - ie. Laptops, Desktops (hasAndBelongsTo)
Is this the correct way to structure something like this?

Categories