【问题标题】:How to edit a products custom options in the observer如何在观察者中编辑产品自定义选项
【发布时间】:2016-09-15 13:13:42
【问题描述】:

我对 Magento 1.9.2.4 有疑问

我需要做的是,当我添加产品时,我需要对正在添加的产品自定义选项进行一些自定义验证。 此外,在验证后,我需要编辑这些选项。

我已经尝试过这些事件

catalog_product_type_prepare_full_options
controller_action_predispatch_checkout_cart_add

但是没有结果,在谷歌上研究之后我也尝试编辑请求并设置我的参数但仍然没有结果。

有人有解决办法吗?或者也许我可以使用另一个事件?

【问题讨论】:

    标签: magento events request


    【解决方案1】:

    在这里找到解决方案Add events for before/after a action of a controller in Magento。 我使用了错误的事件。需要使用predispatch

    【讨论】:

      【解决方案2】:

      也许您应该尝试观察产品模型本身? 此事件将允许您比较旧产品和新产品的价值:

      catalog_product_save_before
      

      你可以在保存产品之前做任何你想做的事情

      catalog_product_save_after
      

      您甚至可以通过抛出异常来阻止实际更新数据库数据,如下面的核心代码所示 ($this->_afterSave())

      /* Mage_Core_Model_Abstract */
      try {
              $this->_beforeSave();
              if ($this->_dataSaveAllowed) {
                  $this->_getResource()->save($this);
                  $this->_afterSave();
              }
              $this->_getResource()->addCommitCallback(array($this, 'afterCommitCallback'))
                  ->commit();
              $this->_hasDataChanges = false;
              $dataCommited = true;
      } catch (Exception $e) {
              $this->_getResource()->rollBack();
              $this->_hasDataChanges = true;
              throw $e;
      }
      
      catalog_product_save_after
      

      如果您想确保您的产品已保存并且您想做一些额外的工作,试试这个:

      catalog_product_save_commit_after
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-31
        • 1970-01-01
        • 2013-03-01
        • 1970-01-01
        • 2014-07-15
        • 2011-04-14
        • 2023-04-08
        • 2023-03-21
        相关资源
        最近更新 更多