0

Scenario:

  • Established Magento store (Store A) with 2 store views languages, English and French.

  • Large number of products (10k +)

  • New store (Store B) has been created (same Magento Installation), and carries all the same products as Store A

Problem:

When assigning all existing products from Store A to Store B, you are prompted for where the default information will come from. This only covers one store view (English).

Desired result: enter image description here

How do you populate all the descriptions from Store A (French) to Store B (French)

  • Are you trying to mass change the descriptions? If not, every product has a description that can be changed per store view. – mbalparda Dec 23 '14 at 14:52
  • Can't you just do a mass action and select Use default in the second store view? Sorry if im not getting this right, the question is not really clear. – mbalparda Dec 23 '14 at 15:07
  • That is the problem, you can only "Use default" for 1 store view not both. – SR_Magento Dec 23 '14 at 15:56
  • If the secondary store views is only for language: magento.stackexchange.com/questions/615/… – B00MER Dec 23 '14 at 19:03
  • Thank you for your input but this is not feasible for me. I need full translations. They already exist, I need to know how to link them OR another solution that gives me the same end result. CSV files aren't going to cut it. – SR_Magento Dec 23 '14 at 21:42
2
+50

Maybe an observer will do the job?

E.g:

class My_Awesome_Model_Observer 
{
    public function syncDescriptions($observer)
    {
        $productId = $observer->getProduct()->getId();

        $storeAEnId = 1; //store view Id for English store A 
        $storeBEnId = 2; //as above for store B
        $storeAFrId = 2; //store A French view's id
        $storeBFrId = 4; //French store B
        //of course replace above with real store Ids

        $descAEn = Mage::getModel('catalog/product')->setStore($storeAEnId)->load($productId)->getData('description');

// Now we check if description in store B is up-to-date with store A's, if not, if yes, we leave, if not, it is updated
        if ($descAEn != Mage::getModel('catalog/product')->setStore($storeBEnId)->load($productId)->getData('description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBEnId)
                    ->load($productId)
                    ->getData('description', $descAEn)
                    ->save();
            }

        $shortDescAEn = Mage::getModel('catalog/product')->setStore($storeAEnId)->load($productId)->getData('short_description');

// Same check for short description
        if ($shortDescAEn != Mage::getModel('catalog/product')->setStore($storeBEnId)->load($productId)->getData('short_description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBEnId)
                    ->load($productId)
                    ->getData('short_description', $shortDescAEn)
                    ->save();
            }

        $descAFr = Mage::getModel('catalog/product')->setStore($storeAFrId)->load($productId)->getData('description');


// same for French view
        if ($descAFr != Mage::getModel('catalog/product')->setStore($storeBFrId)->load($productId)->getData('description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBFrId)
                    ->load($productId)
                    ->getData('description', $descAFr)
                    ->save();
            }

        $shortDescAFr = Mage::getModel('catalog/product')->setStore($storeAFrId)->load($productId)->getData('short_description');


// same for French short description
        if ($shortDescAFr != Mage::getModel('catalog/product')->setStore($storeBFrId)->load($productId)->getData('short_description'))
            {
                Mage::getModel('catalog/product')->setStore($storeBFrId)
                    ->load($productId)
                    ->getData('short_description', $shortDescAFr)
                    ->save();
            }
    }
}

Of course, you should then declare an observer for catalog_product_save_after event choosing your Observers class and method in your module's config.xml. E.g:

<global>
    <events>
        <catalog_product_save_after>
            <observers>
                <awesome_observer>
                    <type>singleton</type>
                    <class>My_Awesome_Model_Observer</class>
                    <method>syncDescriptions</method>
                </awesome_observer>
            </observers>
        </catalog_product_save_after>
    </events>
</global>

It is just quite basic idea for solving the problem, as I don't know which descriptions you use (you may also want to put short_description there), but I hope it will help you creating your own solution. :)

P.S.: Beware of observers' loops.

| improve this answer | |
  • I prefer this solution to my own below! Very elegant. – John Tranter Dec 29 '14 at 8:14
  • I really like this approach, I'm looking to synch both short description and descriptions. I guess I will need to create a module for this? – SR_Magento Dec 29 '14 at 12:58
  • @sr_magento Indeed, you'll need. Or add the observer to existing custom module if you have any (but it might create a little mess with time). I'll update my answer to include short descriptions too. – talonkingvskg Dec 29 '14 at 13:33
  • Additionally, here's interesting thing on observers, although it'll require more research to optimize solution suggested by me, if needed. E.g.: disabling running the observer method on product saved by observer itself. – talonkingvskg Dec 30 '14 at 9:07
1

I imagine you'll have to write your own syncing module, that schedules a nightly import of information from Store A French to Store B French.

Use the 'Updated_At' field for products to minimise the amount of work you need to do.

pseudo code

  • Schedule cron job to run nightly
  • Scan through each product
  • For each product that has been updated since the last time the job ran, copy information from Store A (French) to Store B (French)
  • Log the time the job ran

This is assuming you don't need immediate synch of products.

A tip would be to make sure your indexing model isn't set to 'update on save'

| improve this answer | |
1

'Mass Attribute Update' functionality doesn't allow to apply values from one store view to another due to the logic restrictions. Magento applies only default values to the newly assigned store views.

Try to use the pure SQL workaround.

INSERT INTO `catalog_product_entity_text` (`entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) 
SELECT `entity_type_id`, `attribute_id`, '<target_store_id>' as `store_id`, `entity_id`, `value` 
FROM `catalog_product_entity_text` as `source`
WHERE `attribute_id` IN (
    SELECT  `attribute_id` 
    FROM  `eav_attribute` 
    WHERE  `entity_type_id` = 10 /* catalog_product */
    AND  `attribute_code` IN ( 'description', 'short_description' )
)  
AND store_id = '<source_store_id>'
ON DUPLICATE KEY UPDATE `value` = `source`.`value`;

The script copies values of 'description' and 'short_description' attributes from '<source_store_id>' store view to '<target_store_id>' store view.

Replace '<target_store_id>' and '<source_store_id>' constants and run this script for each store view separately.

Use 'INSERT IGNORE ... ' syntax instead of 'INSERT .. ON DUPLICATE KEY UPDATE' if you'd like to preserve already existent values.

If you'd like to copy some other attribute values you just have to modify the script accordingly.

| improve this answer | |
  • Usually I don't mind modifying the db directly, but in this case with the amount of products I don't want to take a chance. Really appreciate your answer though! – SR_Magento Dec 29 '14 at 13:09

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.