我想从脚本中更新所有产品的元标题,元描述和元关键字。

元标题=产品名称

元描述=产品的简短描述

meta关键字是我从产品类别中放入的meta关键字。

我可以循环获取要更新的信息(描述的meta关键字除外),之后如何在循环内进行更新?

谢谢

<?php require_once 'app/Mage.php';
umask(0);

set_time_limit(0);                   // ignore php timeout
ignore_user_abort(true);             // keep on going even if user pulls the plug*
while(ob_get_level())ob_end_clean(); // remove output buffers
ob_implicit_flush(true);             // output stuff directly
//error_reporting(E_ALL);

/* not Mage::run(); */
Mage::app('default');

// get product collection (All product)
$storeId = Mage::app()->getStore()->getId();
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG);

$_productCollection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('visibility', $visibility)
    ->setStoreId($storeId)
    ->addStoreFilter($storeId);

foreach ($_productCollection as $pro) { // loop each product

   $meta_title = $pro['meta_title'];
   $meta_description = $pro['meta_description'];

   $name = $pro['name'];
   $short_description = $pro['short_description'];

    // I want to update the meta_title, meta_description, meta_keywords

    // meta_description = short_description
    // meta_title = name
    // meta_keywords = meta keywords from the category of the product

}

?>

===============>>#1 票数:0

您可以使用标准设置器轻松设置关键字和描述。

foreach循环内部只需使用:

foreach ($_productCollection as $pro):

   $product = Mage::getModel('catalog/product')->load($pro->getId());   
   $product->setMetaTitle('Product Title')
   ->setMetaKeyword('Product keywords') 
   ->setMetaDescription('Product Description')
   ->save();

endforeach;

===============>>#2 票数:0

尝试这个,

foreach ($_productCollection as $pro):
    $product = Mage::getModel('catalog/product')->load($pro->getId());
    $cats = $product->getCategoryIds();
    $meta_keys = '';
    foreach ($cats as $category_id) {
    $_cat = Mage::getModel('catalog/category')->load($category_id) ;
    if($_cat->getMetaKeywords())
    $meta_keys .= $_cat->getMetaKeywords().', ';
    }
       $product->setMetaTitle($pro->getName())
       ->setMetaKeyword($meta_keys) 
       ->setMetaDescription($pro->getShortDescription())
       ->save();

    endforeach;

  ask by Brian Millot translate from so

未解决问题?本站智能推荐: