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

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

Related

Magento: Deleting archived products - Will the products inside orders be affected?

I have a lot of archived products that I would like to delete.
But I am using a function in the frontend where users can see their old orders and what products were bought:
$orders = Mage::getResourceModel('sales/order_grid_collection')
->addFieldToFilter('store_id', $storeId)
->load();
Some of the products in the orders are already archived.
When I delete all archived products, can the products inside the orders still be accessed? Or will I lose those products?
As answered by Marius:
"Normally, the orders don't have only references to the order products, but they also keep product values (that might seam redundant) because you want to see a snapshot of the product you ordered at the time you ordered it.
This way you avoid seeing new prices or descriptions.
The order history section that magento offers by default works even if you delete ordered products.
but if you have a custom code that loads a product collection or a product to get additional info, it will be affected if you delete the products.
If the only code you use is the one you shown in the question you should be save.
I suggest trying to delete the products first on a staging server then do it on live.
and backup before doing anything."
(If you want to upvote, please consider upvoting his answer too)

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

Magento update skus (mysql query)

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.

How does Magento store deleted products in database

I'm running a script that exports magento products in an xml. I do the query using SQL connections and selecting all attributes. It there a way or how can I find information of deleted products in a magento database?
only way to find out is to have a list of all existing products or products that have existed and compare them against current dataset. Other way would be never delete a product but mark them as out of stock or inactive

Magento: Add a "fake" product to cart/quote

I understand how to programmatically create a product and also add to cart. I know this might sound dumb but is it is possible to generate a product on the fly and add that to the cart/quote but never actually save it in the database.
We want to create a made to order interface and I was thinking at the end it could add a bundle product with all the selections but that bundle product wouldn't actually exist in the backend.
I figured as long as you can make sure the quote and order has what it needs in terms of the product it would be ok, but obviously there is probably a lot that is tied to looking up stuff in the db on a specific sku or ID. I know that if you delete a product and then look at an order in the admin that causes issues, at least it did for this one scenario I was dealing with.
I was thinking of creating a giant bundle product that had like 6 different bundle items and each item could potentially have like 500 products and then based on what the user selects I programmatically add the bundle to cart. But then I wasn't sure if there would be a negative affect with having a gigantic bundle product like that as well.
UPDATE:
I don't think this will work, obviously there are a lot of information tied to the product in the database and we setup a test and right away we get an error for $item->getProduct(). We are moving forward with creating a giant bundle product and also the generic product with adding custom options on the fly, which Anda pointed out below. Any other suggestions will be greatly appreciated.
I'm not sure that clockworkgeek's approach is going to work. On every page load, Magento loads the items from the cart to make sure that they are still valid (in-stock, prices correct, etc), and amends the cart to reflect those values. My understanding of the system in the past has been that a product in the cart needs to have a corresponding database value to survive this process.
The "giant bundle product" approach is a pain, but in the past has been the best approach I have found. Attempting to change the values of the product (such as price or attributes) will be overridden by the cart checks, so you need a product w/ maximal flexibility, such as an overly-customized bundle product or configurable product.
Hope that helps!
Thanks,
Joe
Why not create a generic product in db and then set the product customization as custom options (additional_options) on the fly depending on the user selection. You can add custom options to the product (actually to the quote item) without having to save them in the database. I did this once for a website that sells glasses with prescription. The prescription was added as an option.
You can programmatically create Mage_Sales_Model_Quote_Items and add them to the cart. You've noticed it needs a product to match it's product ID but it needn't be a useful one. It could be a blank, disabled product, also created in code. All that's needed is a stub.
The necessary stuff for the cart is stored in the quote item - fields like name, value and quantity. Those fields are then copied directly to the order without using a product.
Mage::getModel('catalog/product')
creates a new product. you can add it to a cart, by doing something like this:
$cart = Mage::getSingleton('checkout/cart');
$product = Mage::getModel('catalog/product')
->setStoreId($storeid)
->setTypeId($type_id)
->setQty($quantyty)
->setWhatAttributYouWant($attribute);
$cart->addProduct($product);
product attributes you can find in the DB in tables that start like catalog_product_... or take an already created product, and see what attributes it has in the _data array (with debugger or just print_r($product->getData))

Resources