Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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 更新Magento 1.9中的产品图像标签_Php_Mysql_Magento - Fatal编程技术网

Php 更新Magento 1.9中的产品图像标签

Php 更新Magento 1.9中的产品图像标签,php,mysql,magento,Php,Mysql,Magento,我正在尝试更新产品图像标签。我写了一个观察者来捕捉catalog\u product\u save\u,然后再 观察者正在捕捉事件,我可以从函数中进行回声/死亡 下面是保存标签的函数 public function catalog_product_save_before($observer) { // $product = $observer->getProduct(); // $product_id = $product->getId(

我正在尝试更新产品图像标签。我写了一个观察者来捕捉
catalog\u product\u save\u,然后再

观察者正在捕捉事件,我可以从函数中进行回声/死亡

下面是保存标签的函数

    public function catalog_product_save_before($observer)
    {

//        $product = $observer->getProduct();
//        $product_id = $product->getId();

        $conn_write = Mage::getSingleton('core/resource')->getConnection('core_write');
        if (isset($_POST['Media'])) {
            $post = $_POST['Media'];
            foreach ($post as $value_id => $item) {
                $sql = "UPDATE catalog_product_entity_media_gallery_value SET `label` = '" . addslashes($item['label']) . "' WHERE  value_id = " . (int)$value_id;
                if (isset($item['position'])) {
                    $sql = "UPDATE catalog_product_entity_media_gallery_value SET `label` = '" . addslashes($item['label']) . "', `position` = " . (int)$item['position'] . " WHERE  value_id = " . (int)$value_id;
                }
                $conn_write->query($sql);
            }
        }

        return $this;
    }
下面是$sql的回声

UPDATE catalog_product_entity_media_gallery_value SET `label` = 'Test Label Text' WHERE value_id = 8441
当我在工作台上运行这个时,标签会更新, 当我运行_test.php时,它也会更新

_test.php:
require_once "app/Mage.php";
Mage::app();
$conn_write = Mage::getSingleton('core/resource')->getConnection('core_write');
$item = ['label'=>'123456798'];
$value_id = 8441;

$sql = "UPDATE catalog_product_entity_media_gallery_value SET `label` = '" . addslashes($item['label']) . "' WHERE  value_id = " . (int)$value_id;
$conn_write->query($sql);

die("COMPLETE");
有人能解释一下为什么不允许更新行吗

有没有办法从MySQL获得一些反馈?

(代表OP发布)

谜团已经解开了。。。呸


使用
catalog\u product\u save\u after
而不是before,否则必须覆盖save上的信息。

感谢您将问题标记为已解决。要做到这一点,最好的方法是创建答案并自我接受(通过单击勾号)。我们不希望将答案合并到这里的问题中(除非因为它们已经关闭而不可避免)。谢谢