I am working on a user module for loyalty points. During the check, the client has the opportunity to redeem his points.
In the module setup, I created redeem_points eav_attribute (it is present in the eav_attribute table), and I added the attribute to the quote, well, sort of ...
Here is how I did it:
- in 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 public function getDefaultEntities () method that returns an array containing (among 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 a 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 control, when I redeem points, the savePoints ($ data) method 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 will notice that I am debugging the quote object in firephp: at this point (at this stage of the check, just storing it in the quote), I can see the redeemed_points attribute with the correct value.
My problem is that in the next step this attribute will disappear from the quote object :(
Therefore, I understand that I was unable to include the redeemed_points attribute in the quote object, but I really don't know what I am missing ...
Does anyone beat someone?
source share