How to convert quotation mark attribute to order in Magento?

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!

+4
source share
2 answers

In Magento 1.6.2.0, orders are saved to sales_flat_order, and quotes are stored in sales_flat_quote. They no longer use the eav AFAIK structure, so I would say that everything is fine. You should take a look at the Mage_Sales_Model_Convert_Quote class and add the debug code:

 public function toOrder(Mage_Sales_Model_Quote $quote, $order=null) { if (!($order instanceof Mage_Sales_Model_Order)) { $order = Mage::getModel('sales/order'); } /* @var $order Mage_Sales_Model_Order */ $order->setIncrementId($quote->getReservedOrderId()) ->setStoreId($quote->getStoreId()) ->setQuoteId($quote->getId()) ->setQuote($quote) ->setCustomer($quote->getCustomer()); Mage::helper('core')->copyFieldset('sales_convert_quote', 'to_order', $quote, $order); Mage::dispatchEvent('sales_convert_quote_to_order', array('order'=>$order, 'quote'=>$quote)); //I add my debug code here using Mage::log, you can debug using your own method Mage::log($order->getData()); return $order; } 

To find out if the modules_job_id and module_channel_id are installed.

+6
source

Please check the following codes that worked for me (however my Magento installation is 1.7.0.2). I think the problem is with your model resource.

Application / code / local / Final / Test / etc. /config.xml

 <?xml version="1.0" encoding="UTF-8" ?> <config> <modules> <Final_Test> <version>0.0.1</version> </Final_Test> </modules> <frontend> <routers> <test> <use>standard</use> <args> <module>Final_Test</module> <frontName>test</frontName> </args> </test> </routers> </frontend> <global> <models> <test> <class>Final_Test_Model</class> <resourceModel>test_resource</resourceModel> </test> <test_resource> <class>Final_Test_Model_Resource</class> <deprecatedNote>test_mysql4</deprecatedNote> </test_resource> </models> <resources> <test_setup> <setup> <module>Final_Test</module> <class>Final_Test_Model_Resource_Setup</class> </setup> </test_setup> </resources> <fieldsets> <sales_convert_quote> <final_test1> <to_order>*</to_order> </final_test1> <final_test2> <to_order>*</to_order> </final_test2> </sales_convert_quote> <sales_convert_order> <final_test1> <to_quote>*</to_quote> </final_test1> <final_test2> <to_quote>*</to_quote> </final_test2> </sales_convert_order> </fieldsets> </global> </config> 

Your installer should be an instance of Mage_Sales_Model_Resource_Setup, so I created my own class that just extends the above class

Application / Code / Local / Final / Test / Model / Resource / Setup.php

 <?php class Final_Test_Model_Resource_Setup extends Mage_Sales_Model_Resource_Setup{ } ?> 

Finally, my script installer looks like this:

Application / code / local / Final / Test / SQL / test_setup / installation-0.0.1.php

 <?php $installer=$this; $installer->startSetup(); $entitiesToAlter = array('quote','order'); $attributes = array( 'final_test1' => array( 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, 'default' =>5 ), 'final_test2' => array( 'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, 'default' =>0 ) ); foreach ($entitiesToAlter as $entityName) { foreach ($attributes as $attributeCode => $attributeParams) { $installer->addAttribute($entityName, $attributeCode, $attributeParams); } } $installer->endSetup(); ?> 

You can refer to the module files Mage_Sales_Model_Resource_Setup and Mage_Sales under its sql folder to better understand what is happening.

+1
source

All Articles