0

We use magento 1.8.1

I already have 3 different storeviews in 3 different languages.

Now I would like to have a 4th storeview, but with the product description of storeview 1 and 2 combined together.

This new storeview is going to be used for displaying items in a app. And I can't change the code of that.

We have over 13000 sku in our store, so manually doing this isn't an option.

Is there a way to automatically do this? This could also be done on the items which are visible and Searchable. (Around 2000sku)

Resumé What i would like to have, in magento backend (not front end)

Description storeview 1 (Code: nl) (also standard scope) and description storeview 2 (Code: en) copied and merged to the new storeview 4 (dutch + english combined, Code: mobile)

Does anyone have a solution for this? Can i do this in sql? Or has anyone an other solution?

EDIT 28-05-2016: The script blow works great, but now i want to only do this with products with an product id of 25000 and newer. How to do that?

2

You cannot using the standard product's model approach because the store view is bonded to the product itself during the load.

But you may try a "lower level" approach by accessing the resource model:

Mage::getResourceModel('catalog/product')
  ->getAttributeRawValue($productId, 'my_attribute_name', $storeId);

Just pass the $storeId to get the value you need from the store view you need.

So you can use this script I made for you:

<?php
require_once 'abstract.php';

class Mage_Shell_DescMerge extends Mage_Shell_Abstract
{
    const STORE_ID_1 = 1; // Replace this with correct value
    const STORE_ID_2 = 2; // Replace this with correct value
    const STORE_DESTINATION = 3; // Replace this with correct value

    public function run()
    {
        $catalogResourceModel = Mage::getResourceModel('catalog/product');
        $catalogAction = Mage::getSingleton('catalog/product_action');


        $collection = Mage::getModel('catalog/product')->getCollection();
        foreach ($collection as $product) {
            $productId = $product->getId();

            echo "Updating product $productId\n";

            $descrStore1 = $catalogResourceModel
                ->getAttributeRawValue($productId, 'description', static::STORE_ID_1);

            $descrStore2 = $catalogResourceModel
                ->getAttributeRawValue($productId, 'description', static::STORE_ID_2);


            $attrs = array(
                'description' => $descrStore1.'<br />'.$descrStore2,
            );

            $catalogAction
                ->updateAttributes(array($productId), $attrs, static::STORE_DESTINATION);
        }
    }
}

$shell = new Mage_Shell_DescMerge();
$shell->run();

NOTE:

This script must be placed in a PHP file inside shell path of your magento

You can run it from shell using the following command:

cd /yourmagentopath/shell
php -q scriptname.php

I created a shell script because this operation may take a long time, so you'dd beter to run via shell to avoid web timeouts.

WARNING:

Make a full database backup before running this script to make sure it is working in the way you expect.

  • I don't want to display it in a normal store. I would like to have the product description te be copied from 2 storeviews to a new storeview. – Ronny Feb 22 '16 at 22:31
  • You can do it, I added an implementation example to my answer. See if it fits your needings. – Phoenix128_RiccardoT Feb 22 '16 at 22:37
  • Will this generate THE description in THE backend? (I updated my question too) – Ronny Feb 22 '16 at 22:39
  • My script can merge the description from store1 and store2 and merge them in store3 (or 4 if you like). Is is not intended to run in frontend, it is an update script you can run from shell if you like. Descriptions on store3 will be merged both for frontend and backend. Is this what you need? – Phoenix128_RiccardoT Feb 22 '16 at 22:47
  • 1
    I updated my answer with a full PHP shell script. Please make a DB backup before running it. Just make sure it is working as expected. – Phoenix128_RiccardoT Feb 23 '16 at 13:34

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.