2010-11-30 73 views
4


我正在一個自定義的忠誠點模塊上。客戶在結賬時可以選擇兌換積分。
在我創建了一個redeem_points eav_attribute模塊設置(它在eav_attribute表存在)和我已經加入了屬性的報價,嗯,有點...
下面是我已經做到了:新屬性添加到Magento的報價/訂單

  • 在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被稱爲點,該方法保存點($數據):

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:在這一刻(在結賬的這一步,只是afetr將其保存到報價),我可以看到redeemed_points屬性,用正確的值。
我的問題是,在下一步該屬性是從報價對象:(
所以我明白我還沒有完全設法將我的redeemed_points屬性包括在報價對象,但我真的不知道我是什麼「M失蹤...
任何thaughts人嗎?

+0

請參閱本http://stackoverflow.com/questions/4315660/alter-table-in-magento-setup -script - 不,使用SQL/4318501#4318501 – 2010-11-30 21:42:21

+0

嗯,這個鏈接介紹瞭如何創建/修改安裝腳本里面的表,但是這不是我的問題就在這裏:在表中創建/修改,我可以看到表/字段在我的分貝。 我的問題是我不能管理包括redeemed_points到報價的對象。那麼,當我在我的Model_Type_Onepage中調用savePoints函數時,它就在那裏,但在下一步中不會消失。 – OSdave 2010-12-01 09:48:02

回答

7

嘗試手動刪除VAR /緩存/ *。DB模式的緩存在那裏,有時Magento的不會拿起你的新表中的列,即使他們都在那裏。另外這似乎並沒有得到在後端使用清除緩存功能,但只有在目錄手動刪除所有清除。

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(); 
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(); 
相關問題