MySQL unique record selection approach - php

i have a huge product table, this is its simplified structure:
ID|SHOP|...|MPN|PRICE|CLICKS
i can have the same product coming from different shops, every shop have its own product ID, but (if the shop support it) the MPN for same products is the same.
when i query the database for products, order them by clicks, and if there is the same product from multiple source it is showed twice.
Since im ordered by clicks, the two "equal products" can be far from each other, so its quiete intensive to elaborate it at runtime (consider also the result are paginated and the two equals could be in differente pages).
i was thinking about a query that (if there are multiple result of the same mpn) duplicate some columns as needed (but them how my software can know about the dynamically created columns), i was thinking about SELF JOIN but i don't know how many shop can carry the same product (maybe i can assume all the shop i use...)
My main problem is in search (or category) result where i have a list of products with the "BUY AT SHOP FOR PRICE" button that redirect to the shop... my goal is to have more button to BUY if the product (equal by MPN) have duplicate.
I can keep clicks aligned for both product when a user click on the buy button and maybe it would help
Product detail page is not a big deal, since i have a single product i can get all other instances of it by MPN and it is quiete easy
Any suggestion?

to clarify a bit more i just added this:
https://www.db-fiddle.com/f/61MMDBX4aRqtUFcwVk7Ujw/5#&togetherjs=oO3r8FlaAJ
it shows a simplified versione of my database structure (at the moment products with same MPN can have different click number, but i can keep them in sync)
this is a sample of frontend
https://www.puredesign.it/catalog/male-Scarpe/
my goal is to have multiple "ACQUISTA SU" button if the product can be found in more shop (i.e. same MPN on different product)

Related

Jquery refresh select lists each second

I am working on an e-commerce project and I would like to set up 2 dropdown lists linked in ajax. The first list contains the products and the second one contains the quantity of each product.
There is a problem when a user selects a product and then a quantity, and, in the same time another user selects a product and then a quantity => the quantities are not correct. I will try to explain what I mean.
Imagine a first product named "A" with 2 quantities.
A first user choses this product and selects 1 quantity.
there is one quantity left for this product.
At this same very moment, if another user selects the same product, the quantities show "2" ! It is difficult to explain but I wonder if a timeout function should fix this.
You could use setTimeout to update the quantity drop down items every so often based on the product the user has currently selected however I think this a bit overkill.
You would also have to set and store on the server the quantity values every time the user changed their selection.
It is do-able but I would just re-validate the quantity the user has selected is still available once they submit the form.

Mass import custom attributes Magento

I was wondering if anybody has ever tried to mass import custom attributes into a Magento Database before? My client has a Magento store that specialises in selling musical instruments, and wishes to add a Google Shopping Feed (using the extension of that name by Rocket Web) to sell the products on Google Shopping. The problem is that i need both an MPN (Manufacturer Product Number) and a Brand (so for instance Gibson) for the shopping feed to work, both of which are not automatically uploaded by the stores POS system.
The way that the POS system currently works is when a product is added, the title / SKU number / description / price etc are all uploaded to the Magento store, which means the client does not need to add the product twice. The problem is that as MPN and Brand aren't necessarily out of the box attributes, the POS system does not upload either of these to Magento, and therefore I now have 1,000 products without them and they are apparently crucial to the Google Shopping Feed extension.
I'm currently working on getting a table of each of the products SKU, MPN and Brands from the local database of the POS system (of which each of the products has all 3), but once i have it my question is this: is there a simple way for me to reference the products currently in the Magento database (most likely by SKU, as both databases contain the same SKU for each of the items) and apply two custom fields to each of the products: MPN and Brand? I've created custom 'MPN' and 'cat-brand' attributes (which i can use the Google Shopping Feed to map to the custom attributes) and looked inside the Magento database but i cant find them anywhere, but i found a table called 'catalog_product_flat_1', which i imagine is a flat DB used for indexing or something, but it looks perfect for achieving what i want, in that i could easily search for SKU and apply two custom attributes as columns for each product. Something tells me it isn't going to be that easy though.
Any thoughts would be a great help, thanks for your time.
Magento uses an EAV data model, which means your attributes are broken up into multiple tables. Take a look at any tables with 'entity', 'eav', 'attribute', or 'value' in their name if you want an idea of how it all works.
What you're probably looking for is catalog_product_entity_varchar or catalog_product_entity_text. In those tables, entity_id is your product ID number (different from SKU, but you can link a product_id to a SKU) and attribute_id corresponds to the eav_attribute table.
In short, what you want to do is look at your eav_attribute table, pull the entity_type_id, attribute_id fields for your MPN and cat-brand attributes you made, and then you can insert your data into catalog_product_entity_varchar. (or _text if your attributes use that instead)

How to add sub-products to a main product in Magento

I am designing a website for wedding cards with Magento.
Each wedding card which a user buys may come with few additional sub products like a Reply Card, an Additional Insert, etc.
For Example:
There is a wedding card named “A”. Now there is a minimum quantity check that we have put over this product. This product comes with 2 complementary inserts per product.
In addition to these 2 complementary inserts a user can buy additional inserts. The user should select the number of additional inserts from a drop down menu. According to whatever number is selected, additional inserts should be generated.
Now suppose he selected 2, so there would be 2 additional inserts. Each additional insert would have a minimum quantity linked to it. And there would be a fixed cost per additional insert.
I am stuck at this position. How can this be achieved in Magento?
This feature can be handled by the "configurable item type".
Make configurable item, select EAV attribute which connect that type selection.
This is way how you present an empty default product visible (with name image price) and after this you can make variables by another simple product with other prices store ammounts etc...
The same way is bundled item (there is no price, and is counted by sum of prices or selected sub-items by customer), magento shows "price starts by ...."

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.

Camouflage product id's on website

I'm currently building a retail e-shop for a jewellery manufacturer which also sells wholesale to other shops and I'm looking for an efficient way to "hide"/"camouflage" the product id's for all products so that other competitors wont be able to see the product's barcodes and find out that the manufacturer is doing direct sales at lower prices.
All products on the website have a 4-5 digit id which is also the name of the products' images, ie for Product #1234 image filename is 1234.jpg
One thought was to add a 3-digit random int before and after the product ID that would make it quite hard for someone to figure out the product id. Another thought would be to reverse the id's or perform some sort of scrambling. This would work fine for all the links within the site and all i'd have to do would be to strip off the first and last 3 digits off the product id's or de-scramble before using in the queries but what can I do when it comes to displaying product images? I don't want visitors to be able to see the filenames, that would completely blow the cover for a ll product id's.
Suggestions and ideas are very welcome.
You shouldn't allow direct access to your images like that. Instead, use a php wrapper which translates your fake product id to the actual image file and return that.
Ie http://.../getimage.php?fakeid=1337 which translates that into the actual product id 123 and then readfile("/path/to/123.png");
The products don't need to be identified by barcode - you could use a meaningless identifier for the products, and only look up the barcode when you actually need it. Example:
product_barcode | product_identifier
7310791268002 | deadbeef01234cafe
Then, you'd use deadbeef01234cafe both for identifying the product in the store, and for the image name.

Categories