在 Magento 1.9 中更新产品图片标签

Update product image label in Magento 1.9

我正在尝试更新产品图片标签。我写了一个观察者来捕捉catalog_product_save_before.

观察者正在捕捉事件,我可以从函数中echo/die。

这里是保存标签的函数。

    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

当我 运行 这个在 Workbench 标签被更新时, 当我 运行 _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_product_save_after,否则必须覆盖保存时的信息。