Magento update skus (mysql query) - magento

I need to update all configurable products skus, set "-1" in the end. I do not know stucture of magento database, so if anybody can help with query, or which tables have info about skus and type of products.
tnx

This should do the trick:
UPDATE
`catalog_product_entity`
SET
`sku` = CONCAT (`sku`, '-1')
WHERE
`type_id` = 'configurable';
You may need to rebuild your indexes when you are done. Also back-up first your db in case I'm wrong.

I have tried to update "sku" using Marius answer but all of updated products stop showing in PLP and search result. So here are the all queries I have used to resolve this issue.
UPDATE `shared_catalog_product_item` SET sku = CONCAT('ZX-', sku);
UPDATE `sales_order_item` SET sku = CONCAT('ZX-', sku);
UPDATE `quote_item` SET sku = CONCAT('ZX-', sku);
The reason was if you are updating sku from 'catalog_product_entity', you have to update in other tables as well if you application is fully functionality and there is already placed order against that sku.
Hope this help to other as well.

Related

I want to remove bulk related products and then needs to update fresh skus

I have tried using php script to remove the related products. But not the way I wanted things.
Is there a way I can remove the related products links and then update the fresh ones.
to remove all product link relations you could do
DELETE FROM `catalog_product_link` WHERE link_type_id = 1

Which magento table contains product url slug

The problem I'm having is that I import products with Magmi (magento product import open source solution), but I want to change the url slug. I need to know which table in magento database contains slug so that I could maybe feed it somehow directly...
I know this question is old and answer was accepted but for users do not using Magmi is there this answer:
URL Key is stored by EAV model.
You can find value by following query:
SELECT `attribute_id` INTO #urlKeyId
FROM `eav_attribute` WHERE `entity_type_id` = 4 AND `attribute_code` LIKE 'url_key';
SELECT * FROM `catalog_product_entity_varchar` WHERE `attribute_id` = #urlKeyId;
(if you are using table prefix add it to table's names)
The most excellent Magmi will do that for you. I suggest you read every single page of the Magmi instructions slowly and carefully to comprehend the enormous capabilities of this software tool. But the one you want to concentrate on is here.
So if you use a CSV like:
"sku","url_key"
"00085722994075","my-awesome-product-you-will-fail-without-it"
Then Magmi will update all the product 'slugs' for you.
To answer your question: The core_url_rewrite is the main table but it is built from, among other things, the product attribute 'url_key' and the product attributes are in the EAV so it isn't a single table update. That is why we bow to the genius of Dweeves and his magical Magmi code.
i think better idea to load product then update product URL otherwise if you try to do in direct database table. some problems can come out like indexing , magento can stop working.
i means how you do load MAGE class then load product then do this manually

Update All Product Attributes programmatically

How can I set the value of a given attribute to the same value for all products (efficiently)?
By efficient I mean in one transaction, not having to loop through the entire product collection.
In the past I've used Mage_Catalog_Model_Product_Action for bulk updates on products, and it runs pretty fast
Mage::getSingleton('catalog/product_action')
->updateAttributes($productIds, array('some_attribute' => 'some_value'), 0)
But it requires you specify which product ids you're updating, creating a huge WHERE entity_id IN(...) clause in the MySQL statement. Is there a way to do this for everything?
I had same problem before, when I added 11096 product(downloadable products) in my store then client told me to add new attributes in product so i create 1 attribute (Type is Yes/No) and set to attribute set. Now my problem is how can iIedit all product and set that attribute yes or not. If I don't set then value is null so I wrote few line code.
Please check this code may be it'll helpful to you.
$ProductId = Mage::getResourceModel('catalog/product_collection') -
addAttributeToFilter('type_id', Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) -
getAllIds(); //Now create an array of attribute_code => values
$attributeData = array("my_attribute_code" =>"my_attribute_value");
//Set the store to affect. I used admin to change all default values
$storeId = 0;
//Now Update the attribute for the given products.
Mage::getSingleton('catalog/product_action') ->updateAttributes($ProductId, $attributeData, $storeId);
It was work for me.I hope it'll work for you
Amasty "Mass Product Actions" will allow you to edit product attributes in a variety of ways. This is what we use and it's going to be a life saver once we get the Configurable Products pricing tier working properly.
http://amasty.com/mass-product-actions.html

Magento 1.6, allow SKU's to be used in catalog promotion rules

I'd like to set up catalog price rules discounts based on SKU.
However when I go to 'manage attributes' and try to edit SKU to 'use in Promo Rules: yes'. I get an error saying that SKU is a system reserved atrribute.
I have already changed the SKU attribute to user_defined=1 under eav_attribute table, but the message still appears.
It seems this was possible in earlier version of magento but not 1.6?
Any help is much appreciated.
I took a guess and managed to fix my own problem.
I had set SKU attribute to user_defined=1 under eav_attribute table earlier on along with every other attribute. I had assumed setting them all to '1' would make life easier in the future. However, setting SKU user_defined to 0 via phpmyadmin, actually allowed me to make the changes I wanted.

Manually adding custom options to existing products

I'm trying to add some custom options to already existing products in Magento. Seems to work fine, I added the needed rows in the following tables:
catalog_product_option
catalog_product_option_title
catalog_product_option_type_value
catalog_product_option_type_price
catalog_product_option_type_title
I also updated has_options and required_options for the right product, in the following tables:
catalog_product_entity
catalog_product_flat_1
catalog_product_flat_2
catalog_product_flat_3
When I open the product, the options doesn't show, actually, it shows less. The button to order it disappears. When I open the edit page, it does show the options. After saving, it appears on the front-end too.
What am I missing?
Update:
After manually going through literally every query that was executed after a save action, I discovered what I was missing. When a product has options, it has to display them in a different template (or whatever it's called in Magento). To do this, you'll have to change the value for the attribute options_container.
So, there's a really easy fix for that. Just look up the attribute_id in the table eav_attribute. Then just run the following query for each product:
UPDATE `catalog_product_entity_varchar` SET `value` = 'container1' WHERE `attribute_id` = 836 AND `entity_id` = $productId;
That'll do the trick! :)
After manually going through literally every query that was executed after a save action, I discovered what I was missing. When a product has options, it has to display them in a different template (or whatever it's called in Magento). To do this, you'll have to change the value for the attribute options_container.
So, there's a really easy fix for that. Just look up the attribute_id in the table eav_attribute. Then just run the following query for each product:
UPDATE `catalog_product_entity_varchar` SET `value` = 'container1' WHERE `attribute_id` = 836 AND `entity_id` = $productId;
That'll do the trick! :)
You really shouldn't be accessing the database directly for any reason. This undermines the power and resourcefulness of using an EAV system.
Extend Mage.php if outside of magento (disregard if not)
Make a collection of whatever entities you want to manipulate
Use said collection to write/read data
Save yourself headaches down the road!

Resources