I spent two days on it, I feel like I tried everything, but I still hold on to the wall.
I have two attributes (module_job_id, module_channel_id) that I would like to add to the quote and order. Where I managed to get the quote attributes working fine, I can see that they are stored in the database, and they can be retrieved in order.
It remains only to move the values from the quote to the order. What am I doing wrong?
Here is my module configuration file:
<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Company_Module> <version>0.1.9</version> </Company_Module> </modules> <global> <fieldsets> <sales_convert_quote> <module_job_id> <to_order>*</to_order> </module_job_id> <module_channel_id> <to_order>*</to_order> </module_channel_id> </sales_convert_quote> </fieldsets> <resources> <company_module> <setup> <module>Company_Module</module> <class>Mage_Sales_Model_Mysql4_Setup</class> </setup> <connection> <use>core_setup</use> </connection> </company_module> </resources> </global> </config>
Installation file sql / company_module / mysql4-install-0.1.0.php:
<?php $installer = $this; $installer->startSetup(); $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'module_job_id', 'VARCHAR(255) NULL DEFAULT NULL'); $installer->getConnection()->addColumn($installer->getTable('sales/quote'), 'module_channel_id', 'VARCHAR(255) NULL DEFAULT NULL'); $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'module_job_id', 'VARCHAR(255) NULL DEFAULT NULL'); $installer->getConnection()->addColumn($installer->getTable('sales/order'), 'module_channel_id', 'VARCHAR(255) NULL DEFAULT NULL'); $installer->addAttribute('order', 'module_job_id', array('type' => 'varchar')); $installer->addAttribute('quote', 'module_job_id', array('type' => 'varchar')); $installer->addAttribute('order', 'module_channel_id', array('type' => 'varchar')); $installer->addAttribute('quote', 'module_channel_id', array('type' => 'varchar')); $installer->endSetup();
I tried all possible combinations of addAttribute and addColumns in the installation file. As a result, I have both attributes as columns in sales_flat_quote and sales_flat_order. However, none of the attributes are in eav_attribute. I'm not sure if this is normal.
Another thing I've tried is to set the order attribute values explicitly in the sales_convert_quote_to_order observer. It did not help:
public function salesConvertQuoteToOrder($observer) { $order = $observer->getEvent()->getOrder(); $order->setModuleJobId('123'); $order->setModuleChannelId('456'); }
I do not know if this is important, but these are entity types in my system (only order, no quote ...):
mysql> SELECT entity_type_id, entity_type_code FROM eav_entity_type; +----------------+------------------+ | entity_type_id | entity_type_code | +----------------+------------------+ | 3 | catalog_category | | 4 | catalog_product | | 7 | creditmemo | | 1 | customer | | 2 | customer_address | | 6 | invoice | | 5 | order | | 8 | shipment | +----------------+------------------+
In addition, eav_entity is empty. I hope and OK.
mysql> select * from eav_entity; Empty set (0.00 sec)
This is on Magento 1.6.2.0. Thanks heaps!