Magento configurable product - update associated products? - magento

So here's my scenario:
I have a configurable product with ~50.000 associated products.
This needs to be synced on a periodic basis with ERP. (So the ERP sends info about which simple products should be associated to configurable product)
The number of associated products that need to be synced is too large to use the usual Magento function for this:
$product->setConfigurableProductsData($data);
Where $data is the array of products that should be associated to configurable $product.
Anybody aware of a way/function to (programmatically) insert new associations (as opposed to above functions which resets all existing ones) and delete existing associations where needed?

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)

How to change in the Magento DB the prices of the product

I've troubles to figure out how to change the prices of a product in the magento DB.
I tryed to change the prices in the catalog_product_index_price table but the price doesn't change.
There is a website here that explains it in more detail, but the short answer is that you need to change the price in the catalog_product_entity_decimal table and then reindex Product Prices in the backend (and potentially Product Flat Data as well)
Magento uses variety of indexing and caching methods that make simply changing the value directly in the database not a good idea.
If you look, you can see the prices are also defined in the Price Index tables:
catalog_product_index_price_idx
And also the flat tables (if you use them):
catalog_product_flat_1 (number 1 depends on store)
If you're trying to mass update prices, I recommend either using a tool such as Magmi or the built in Magento import methods to update prices. Directly modifying the database is generally not a good idea with Magento, given it's complex database structure.

Remove a Magento attribute from configurables and associated simple products

I have some configurable products that have many associated simple products, each with many custom options. The configurables use three attributes. My client has now decided that they want to remove one of the attributes. I have used the SQL method to remove one of the attributes, but this is now affecting the custom options when the remaining attributes are selected. The custom options no longer show up. I am assuming this because the attribute is still part of the associated simple products.
Is there a way to remove the attribute from the associated simple products as well, so that the custom options will show correctly when the remaining attributes are chosen?
The attribute, which you are trying to remove is part of each configurable super product, not associated products, as far as I know. Check 'catalog_product_super_attribute' table in db, remove all rows, which have 'attribute_id' set to id, which you want to remove.
Clean the cache, reindex and see, if it works.
To remove one super product attribute from all configurable products, you could execute this SQL query in the database:
DELETE FROM catalog_product_super_attribute WHERE attribute_id = <id>;
The table catalog_product_super_attribute links products to super product attributes.

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

How to set Minimum Order Quantiy (MOQ) for a category in magento?

How to add Minimum Qty Allowed in Shopping Cart for a category.
In Magento (ver. 1.6.2.0) backend, System > Configuration > Inventory > Product Stock Options tab, you can set the 'Minimum Qty Allowed in Shopping Cart' but for Customer Group; not for Category.
We have lots of categories having absolutely different kinds of items and need different MOQs for specified category.
How would I force a minimum of 6 products from the jewellery category and 7 dozen from the bra category?
Thanks, Shaman
What you describe would not be natively possible with Magento. Magento natively provides a 1:many relationship with categories and products,
Ie. A product can be in many categories
What you propose would induce a race condition for a product whereby there could be 2 possible critera for a product's inventory controls if the product exists in more than one category.
Eg. If you set Category A to have a MOQ of 6, and Category B to have a MOQ of 10 and Product C exists in both - which rule does it inherit (highest/lowest)?
As a result, this isn't going to be natively possible, but you could build a custom module to achieve it.
Either ...
Via a category->save() observer
You could create a custom attribute for the category - MOQ, then have your module 'listen' to the category save, and iterate through all products accordingly to set the MOQ for said products.
Advantages - More granular control per product, no speed impact/overheads for frontend
Disadvantages - Slow to save category
Or
By modifying the isSaleable() function
You could rewrite the standard function which determines if a product is saleable. In your modified function, check categories of said product, obtain the MOQ (highest/lowest - whichever) then return true; or return false; accordingly.
Advantages - Less administration hanging around, stops having to continually update indexes at a product level needlessly
Disadvantages - Slower to check if product is saleable (frontend would seem slower)
Either way, you need to build a custom module, or seek a professional to make one for you.

Resources