Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 脚本生成多个描述,而不是一个_Php_Mysql_Magento - Fatal编程技术网

Php 脚本生成多个描述,而不是一个

Php 脚本生成多个描述,而不是一个,php,mysql,magento,Php,Mysql,Magento,我在Magento 1.7中使用了简短描述生成器插件,但它的工作原理有点错误。以下代码来自ProductController.php: getRequest->getParam“产品” foreach ($pIds as $pId) { $obj = Mage::getModel('catalog/product'); $_product=$obj->load($pId); $attribs=$_product->getAttr

我在Magento 1.7中使用了简短描述生成器插件,但它的工作原理有点错误。以下代码来自ProductController.php:

getRequest->getParam“产品”

    foreach ($pIds as $pId) {
        $obj = Mage::getModel('catalog/product');
        $_product=$obj->load($pId);
        $attribs=$_product->getAttributes();
        $i=0;
        foreach ($attribs as $attrib) {

            if ($attrib->getUsedInProductListing() && $attrib->getIsUserDefined()) {

                $prodAttrVal=$attrib->getStoreLabel().': ';
                $pa=$attrib->getFrontend()->getValue($_product);
                //$pa=$_product->getAttributeText($attrib->getAttributeCode());
                if ($pa==null) $pa='не указано';
                $prodAttrVal.=$pa;
                if ($i % 2==0) $str.=' '.$prodAttrVal.' | ';
                else $str.=' '.$prodAttrVal.'.';
                $i++;
            }

        }
        if ($i % 2!=0) $str.=' ';
        $str.=' ';
        $_product->setDescription($str);
        $obj->save();
    }
    Mage::dispatchEvent('catalog_product_massupdate_after', array('products'=>$pIds));
    $this->_redirect('adminhtml/catalog_product/index/', array());
}
}

当我在catalog中选择N个产品并选择generateshortdescription时,脚本通过以下模式生成简短描述:Attr1:blah。属性2:废话。Attr3:废话。属性1:废话。属性2:废话。属性3:废话在某些产品中重复N次,但在其他产品中,它只做一个描述,因为它必须在正确的情况下。产品名称或SKU的相似性不取决于


有什么问题吗?

我认为这方面有问题

$obj = Mage::getModel('catalog/product'); //this line

   foreach ($pIds as $pId) {

        $_product=$obj->load($pId);
        $attribs=$_product->getAttributes();
        $i=0;
        foreach ($attribs as $attrib) {

            if ($attrib->getUsedInProductListing() && $attrib->getIsUserDefined()) {

                $prodAttrVal=$attrib->getStoreLabel().': ';
                $pa=$attrib->getFrontend()->getValue($_product);
                //$pa=$_product->getAttributeText($attrib->getAttributeCode());
                if ($pa==null) $pa='не указано';
                $prodAttrVal.=$pa;
                if ($i % 2==0) $str.=' '.$prodAttrVal.' | ';
                else $str.=' '.$prodAttrVal.'.';
                $i++;
            }

        }
        if ($i % 2!=0) $str.=' ';
        $str.=' ';
        $_product->setDescription($str);
        $_product->save();
    }
    Mage::dispatchEvent('catalog_product_massupdate_after', array('products'=>$pIds));
    $this->_redirect('adminhtml/catalog_product/index/', array());
}

如果您有疑问,请告诉我

对不起,但它不起作用。现在的情况更糟了:现在描述中重复的属性是从目录中选择的不同产品中混合而来的。例如:三星Galaxy SIII红色和三星Galaxy SIII白色SKU在简短描述中相同,有:颜色:红色。。。。跳过其他属性…颜色:白色;。。。。。