4


我正在开发一个自定义忠诚度积分模块。在结账期间,客户可以选择兑换积分。
在模块设置中,我创建了一个redeem_points eav_attribute(它存在于eav_attribute 表中)并且我已将属性添加到报价中,嗯,有点......
这是我的做法:

  • 在 mysql4-install-0.1.0.php 我调用$installer->installEntities();
  • 在 Namespace_Module_Model_Resource_Eav_Mysql4_Setup(它扩展了 Mage_Eav_Model_Entity_Setup)中,只有 1 个方法公共函数 getDefaultEntities()只返回一个包含(除其他外)的数组:

       'quote' => array(
            'entity_model'  => 'sales/quote',
            'table'         => 'sales/quote',
            'attributes'    => array(
                'redeemed_points'   => array('type' => 'static')
            ),
        ),
    
  • 再次在 mysql4-install-0.1.0.php 我在 sales_flat_quote 表中创建列,如下所示

       //add redeemed_points to quote table
       $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'redeemed_points', 'bigint(20)');
       $installer->addAttribute('quote', 'redeemed_points', array('type'=>'static'));
    

在结帐时,当我兑换积分时,我的类中扩展 Mage_Checkout_Model_Type_Onepage 的方法 savePoints($data) 被调用:

public function savePoints($data)
{
    //save data
    if ($data == 1) {
        $redeemedPoints = Mage::helper('points')->getRedeemablePoints();
        $this->getQuote()->setRedeemedPoints($redeemedPoints['points']);
    } else {
        $this->getQuote()->setRedeemedPoints(0);
    }
    $this->getQuote()->collectTotals()->save();

    $this->getCheckout()
         ->setStepData('points', 'complete', true);
    if ($this->getQuote()->isVirtual()) {
        $this->getCheckout()->setStepData('payment', 'allow', true);
    } else {
        $this->getCheckout()->setStepData('shipping_method', 'allow', true);
    }

    Mage::helper('firephp')->debug($this->getQuote()->debug());

    return array();
}

您会注意到我在 firephp 中调试了报价对象:此时(在结帐的这一步中,只是在将其保存到报价中之后)我可以看到具有正确值的 redempted_points 属性。
我的问题是,在下一步中,这个属性从报价对象中消失了:(
所以我知道我还没有完全设法将我的redeed_points 属性包含在报价对象中,但我真的不知道我错过了什么。 ..
任何人的想法?

4

3 回答 3

7

尝试手动删除 var/cache/*. 数据库模式被缓存在那里,有时即使它们在那里,Magento 也不会选择你的新表列。此外,这似乎并没有通过使用后端中的清除缓存功能来清除,而只能通过手动删除目录中的所有内容来清除。

于 2012-07-17T23:48:20.940 回答
1

以下扩展示例包括程序化缓存清除:

$installer = Mage::getResourceModel('sales/setup', 'sales_setup');

    $installer->startSetup();

    $installer->addAttribute('order', 'new_attribute', array('type'=>'boolean','default'=>0));
    $installer->addAttribute('quote', 'new_attribute', array('type'=>'boolean','default'=>0));


    // Refresh DB table describing cache programmatically

    if (method_exists($this->_conn, 'resetDdlCache')) {
        $this->_conn->resetDdlCache('sales_flat_order');
        $this->_conn->resetDdlCache('sales_flat_quote');
    }

$installer->endSetup();
于 2016-12-13T16:46:27.140 回答
0

有一个最简单的方法,试试这个例子:

$installer = Mage::getResourceModel('sales/setup', 'sales_setup');
    $installer->startSetup();
    $installer->addAttribute('order', 'new_attribute', array('type'=>'boolean','default'=>0));
    $installer->addAttribute('quote', 'new_attribute', array('type'=>'boolean','default'=>0));
$installer->endSetup();
于 2016-02-17T23:43:02.830 回答