我正在尝试更新产品图像标签。我写了一个观察者来捕捉catalog_product_save_before
观察者正在捕捉事件,我能够从函数中回音/消失。
下面是保存标签的函数。

    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时,它也会更新。?
_测试.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,否则必须覆盖保存时的信息。

10-05 21:00
查看更多