0

I have many products that have no description but all have short descriptions How can I copy from short description if description is empty?

0

You will need to change this file template/catalog/product/view/description.phtml like this:

<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
    <h2><?php echo $this->__('Details') ?></h2>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
    </div>
<?php else: //adding short description?>
    <h2><?php echo $this->__('Short Details') ?></h2>
    <div class="std">
        <?php echo $_helper->productAttribute($this->getProduct(), $this->getProduct()->getShortDescription(), 'short_description') ?>
    </div>
<?php endif; ?>

This should give you short description if description is empty.

UPDATE

If you want to save short description as description if it is empty in backend then I would suggest to run a simple function like this:

$products = Mage::getModel('catalog/product')->getCollection();
foreach($proudcts as $product){
    if(!$product->getDescription() && $product->getShortDescription()){
        $product->setDescription($product->getShortDescription())->save();
        Mage::getSingleton('adminhtml/session')->addSuccess($this->__($product->getId(). "'s description is saved."));
    }
}

Now, how to run this code? You can create a simple module and place above code in indexAction(), then call it.

PS I would still stick with first solution that I provided. That works with not having description in the product. This helps you to know which product doesn't have description and can save later if needed for each product.

2
  • Hello and thanks for the response. I want to copy it in the backend if description does not exist – Costas Saloubardos Feb 7 '17 at 0:44
  • Check my update. – Adarsh Khatri Feb 7 '17 at 0:55
0

I would recommend filtering the collection for performance's sake, and I would put this code into a file in your Magento root (maybe setDescription.php) and run it from either from the command line (php setDescription.php) or the browser (http://yourdevurl/setDescription.php).

<?php

require_once 'app/Mage.php';
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);


$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('short_description')
    ->addAttributeToSelect('description')
    ->addAttributeToFilter('description', array('neq' => NULL));

foreach ($productCollection as $product) {
    $product->setDescription($product->getShortDescription());
    $product->save();
}

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.