I'm working on a custom loyalty points module. During the checkout the customer has the option to redeem his points.
In the module setup I have created a redeem_points eav_attribute (it's present in the eav_attribute table) and I have added the attribute to the quote, well, sort of...
Here is how I've done it:
- in the mysql4-install-0.1.0.php I call $installer->installEntities();
in Namespace_Module_Model_Resource_Eav_Mysql4_Setup (which extends Mage_Eav_Model_Entity_Setup) there is only 1 method public function getDefaultEntities() that only returns an array which contains (amongst other things):
'quote' => array( 'entity_model' => 'sales/quote', 'table' => 'sales/quote', 'attributes' => array( 'redeemed_points' => array('type' => 'static') ), ),
again in mysql4-install-0.1.0.php I create the column in the sales_flat_quote table, like this
//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'));
In the checkout, when I redeem points, the method savePoints($data) from my class which extends Mage_Checkout_Model_Type_Onepage is called:
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();
}
You'll notice that I debug the quote object in firephp: at this moment (in this step of the checkout, just afetr saving it into the quote) I can see the redeemed_points attribute, with the correct value.
My problem is that in the next step this attribute is gone from the quote object :(
So I understand I haven't quite managed to include my redeemed_points attribute in the quote object, but i really don't know what I'm missing...
Any thaughts someone?