Combine same attributes with different slug - Woocommerce - php

I have multiple product attributes with the same name and same terms but different slugs. That's a result of a migration from Shopify to Woocommerce. For example, attribute 'Μέγεθος'('Size' in Greek) entered 2000 times for each product. Now i don't know how to combine those to one attribute with all terms like S,M,L,XL,44,45,56 etc.
Unless i edit product attributes one by one, is there a most sufficient option? Any suggestion?
Screenshot

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.

Convert WooCommerce Custom Product Attributes into Defined Product Attributes

I am trying to filter ~30,000 products in a WooCommerce store using WooCommerce's Layered Nav attribute filter sidebar widget. This requires the use of a pre-defined product attribute taxonomy, as opposed to using custom attributes on a per-product basis.
Each product in the store has an imported custom 'Brand' attribute. Prior to importing products, I created an attribute taxonomy called 'Brand' (pa_brand) in wp-admin. However, imported products have not had their Brand attribute (and term name) added to the Brand (pa_brand) taxonomy. Instead, all of the products have a custom attribute called 'Brand' not linked to the pa_brand taxonomy.
Does anyone know how to convert custom product attributes into defined attributes within the pre-defined taxonomy (with terms not yet created)?
I assume that I'd need to run a PHP script which does the following, but don't know if I've missed any steps out:
Obtain an array of ID's for all of the products in the database
Loop over each of the product ID's (foreach)
get_attributes() from each product ID - this will return the custom 'Brand' attribute (there are no pa_brand assignments yet)
Check: If the brand term already exists in the pa_brand taxonomy, do nothing; if it doesn't, add the term to the pa_brand taxonomy
Assign the product to the term within the pa_brand taxonomy
Delete the old custom Brand product attribute
I'm not sure how best to execute this, so any help would be very much appreciated.
PS: to illustrate the distinction between 'custom attributes' and attributes defined in a taxonomy, I have added 2 screenshots below of how they differ when editing a product in WooCommerce. Note how the name of the attribute can be altered if not from the defined taxonomy.
Attributes defined in taxonomy:
Custom attributes:
Thanks
It looks like someone has done this before - https://gist.github.com/birgire/0ed300ae4436fcaf508c
just to help anyone that comes to this page sharing the same problem. Custom attribute to global (taxonomy), variations, etc...
How we solved it easily:
We created the same name of the Custom Attribute as a Global Attribute (Brand => Brand). No need to add terms, just attribute Name.
Downloaded (Export) all the products as CSV file on the All Products table page.
On the CSV file (opened on Excel) make sure to set Attribute n global (n is the number of attribute, 1, 2, etc...) to 1 (when it's custom it will show 0). Do this on all rows that have the attribute you are converting.
To make sure Variations also saved and that attribute can be used make sure that Attribute n visible is also set to 1 on all rows.
Save the file.
Next go back to your All Products page and click on Import.
Choose the file and check the box that says "Existing products that match by ID or SKU will be updated. Products that do not exist will be skipped.".
Next click on Run the importer button.
This will convert all the custom attributes with their terms into global, and also keep all the variations. No need for any coding or hard work.
For the steps 3 and 4 you can use formula like this one =IF(AN2="Flavors","1","") for the first line and copy paste it to all rows to do it automatically for a specific attribute if needed.
Hopefully this will help you.

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 multiple different types of product to cart

I am creating a shopping cart where I am trying to add different types of product e.g. Mobiles, clothes etc.
I have created a add_to_cart method and added products to session, then at last I save all products to database table.
But now I am confused how to add different product because parameter for different products are different e.g.
1. product_id, quantity, price for mobile.
2. product_id, quantity, price, size for cloths.
....
should I create different add_to_cart() method for different types of products.
In your scenario it would be better to have the product options sent as a JSON string and then decode it on the server side so that you don't have to worry about the different options for each product.
So product one might have options like:
{color: "black", size: "large"}
And product two might have:
{memory: "2 GB", harddisk: "750 GB"}
etc.
As long as products have at least some common fields, writing different methods is not entirely justified.
The other attributes can simply be passed as key-value pairs.
When writing the data into a database, you could apply EAV modeling.
you can keep using the add_to_cart()
instead, you'll add an array parameter, say, "attributes" or "extra" and
add there specific/unique product valued keys.
then in database you create an "attributes" column of variable size eg. VARCHAR(128)
and add those attributes encoded as JSONs
you can still search for any product then using "LIKE '%"attribute" :%'" (json)
this doesnt forcing you to create additional columns for every new product attribute.
You can keep basic common things in primary array and specification in specification array as follows
Products[mobile] =>array(name => 'test1', price =>'20' specification=array('color'=>red,model=>'N70' etc....))
Products[cloths] =>array(name => 'test1', price =>'30' specification=array('size'=>'XL',color=>'yello',etc......))

Magento specific attribute per category

I want to only display specific attribute to specific type of product. For example I have Shoes and a footID. footID will only be available in Shoes product page and not any other. In time I'll also have a few more similar attributes for example tennisID that only applies to tennis Products.
In order to achieve this you first have to create all the different attributes you need. (Such as footID and tennisID)
After that you have to create multiple attribute sets. In your example you would have to create two attribute sets called "Shoes" and "Tennis".
In each of these attribute sets you add the attributes that belong to them. (Example when creating the attribute set tennis you have to add (drag) the tennisID attribute to it. (same goes for the shoes attribute set)
These attributes will only be visible (both frontend and backend) for the attribute sets they have been added too.
Regards,
Kenny

Categories