2

I have a problem on my Magento store. I have multiple stores (for different languages, let's say English and German). I also have configurable products, which work ok. My problem is that when I create new simple product from within configurable product (on associated products tab) the simple product is only created for default store (0), and the appropriate name, description, eg. is not copied to it from configurable product.

So if I create a product like this, go to check in german store, the title, desc. etc. is still in default language (eng).

I went to investigate how these products are created and discovered that it is done by these function:

public function quickCreateAction() Which is located in app\code\core\Mage\Adminhtml\controllers\Catalog\ProductController.php, around line 984.

So my question, how to rewrite these function, so that it would save product for all stores?

1

I've tried to implement such change several times using event observers but never managed to do it without rewriting the controller, here is how I achieved it by creating a new module:

app/code/local/My/Module/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <My_Module>
            <version>0.0.1</version>
        </My_Module>
    </modules>

    <admin>
        <routers>

            <adminhtml>
                <args>
                    <modules>
                        <My_Module before="Mage_Adminhtml">My_Module_Adminhtml</My_Module>
                    </modules>
                </args>
            </adminhtml>

        </routers>
    </admin>
</config>

app/code/local/My/Module/controllers/Adminhtml/Catalog/ProductController.php:

<?php

require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml').DS.'Catalog'.DS.'ProductController.php';

class My_Module_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
{
    public function quickCreateAction()
    {
        // Here you copy/paste the content of the original quickCreateAction function and make your modifications directly into it
        // When you update Magento, ensure that if the original controller has been changed, you add the modifications to yours
    }
}

app/etc/modules/My_Module.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <My_Module>
            <active>true</active>
            <codePool>local</codePool>
        </My_Module>
    </modules>
</config>

Regarding the modification you're trying to achieve I reckon this is the part of the function you need to change:

$product->setWebsiteIds($configurableProduct->getWebsiteIds());

You'll have to change it so it applies to every website you want the product to be created for.

  • Thank you, I allreay implemented it in to my custom module and it is working from there (the usual way)...So if I understand you correctly, the secret is in .. ->setWebsiteIds(....)? – JureW Jan 25 '16 at 14:05
  • Yes, so basically if your configurable product is assigned to website 1 and website 2, the simple products will also be assigned to this website. You can basically replace the $configurableProduct->getWebsiteIds() with an array of website ids – Raphael at Digital Pianism Jan 25 '16 at 14:10
  • Hello again, i tried with setWebsiteIds, but no success, still the product only saves to default store. As I checked the database, I noticed that in allmost all of product tables, there is a field store_id, so it is probably saving based on store id. If I check in, lets say catalog_product_entity_varchar I can see different language in value field (for older products) where entity_id: 12345 and than for the same atribute id (example 71) and different store_id (lets say 1 and 3)...I hope you know what I mean. – JureW Jan 26 '16 at 9:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.