Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 2 of 2
php arch. made to orer module
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

Table
Sales Flat Quote Item

Contains the ‘user_input’ field that is successfully recording the input from the order (yay, half way there).

I don’t see the user_input attribute for sales items however (table eav_attribute?)

I’m checking for sales item input in this table:  sales_order_entity_varchar

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

Well, your code looks correct.  Are you sure it’s not adding anything?  I mean, if it was having a problem, you should get some notice.

NOTE:  A cheap way of cheating and making magento re-run your module install is to remove the entry for you module from the core_resources table.  In this case it would be an entry for mto_setup, just delete that row and it’s like your module was never installed.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

I did find an error in my event listener function, but I’m fairly sure that I should be seeing a user_input attribute in table eav_attribute and a value in table sales_order_entity_varchar .

I’m not sure I’ll see any errors because the data is being pulled and sent via magic getter / setter methods.

Thanks for that tip.

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

Check sales_flat_order_item for a user_input column

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

the quote_item and order_item tables are both flat tables.  No EAV involved

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

ok cool - so sales_flat_order_item and sales_flat_quote_item both have user_input.

sales_flat_quote_item is recording input as it should.

sales_flat_order_item has ‘NULL’ as a value :(

So, it looks like we need to move onto our events/observers.

I have my event handlers in a Helper class (via phparchitect, even though it looks like they should be a model rather than a helper :shrug: )

//Called from "sales_convert_quote_item_to_order_item" event
    static function attachSpecialOrderAttribs($observer)
    
{
        $event 
$observer->getEvent();
        
$orderItem $event->getOrderItem();
        
$quoteItem $event->getItem();
        
        
$orderItem->setUserInput($quoteItem->getUserInput());
    
}

from my config.xml :

<frontend>
        <
routers></routers>
        <
events>
            <
sales_quote_save_before>
                <
observers>
                    <
my_cart_checker>
                        <
type>singleton</type>
                        <class>
Fido_Mto_Helper_Event</class>
                        <
method>cartBeforeSave</method>
                    </
my_cart_checker>
                </
observers>
            </
sales_quote_save_before>
            <
sales_convert_item_to_order>
                <
observers>
                    <
my_order_attribs>
                        <
type>singleton</type>
                        <class>
Fido_Mto_Helper_Event</class>
                        <
method>attachSpecialOrderAttribs</method>
                    </
my_order_attribs>
                </
observers>
            </
sales_convert_item_to_order>
        </
events>
        <
translate></translate>
        <
layout></layout>
    </
frontend>
 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

I used mage’s debugging (Mage::log()) to test if the events were being fired (by logging user_input values).

It looks like the 2nd event there where it records the sales_convert_item_to_order is not getting fired :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

looks like (according to the wiki) I should be using either of these events:
sales_convert_quote_to_order
or
sales_convert_quote_item_to_order_item

instead of this event:
sales_convert_item_to_order\

EDIT: sales_convert_quote_item_to_order_item is the winner

I now have successful recording of custom user input.

Now I need to get that to show up in the backend for orders. That will be an interesting problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

This might interest you as well

<config>
   <global>
      <
fieldsets>
         <
sales_convert_quote_item>
                <
user_input><to_order_item>*</to_order_item></user_input>
         </
sales_convert_quote_item>
      </
fieldsets>
   </global>
</
config>
 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

Funny.

In your post with the event handler code, the comment above the code has the correct event name.  I used that to look it up and didn’t notice you have another event name in the XML config.

Anyway, the XML I posted in my last response is the Magento way to copy the fields.  Either way works (I think), but the XML is less code needed.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 
Lee Saferite - 24 September 2008 09:43 AM

Funny.

In your post with the event handler code, the comment above the code has the correct event name.  I used that to look it up and didn’t notice you have another event name in the XML config.

Anyway, the XML I posted in my last response is the Magento way to copy the fields.

lol, yeah it’s always the small things.

So that XML version should work as well? That’s very interesting (and easier)

EDIT: Is that tag correct in the fieldset? “Sales_Convert_Quote_Item” ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
LeeSaferite
Guru
 
Avatar
Total Posts:  322
Joined:  2007-08-31
Lake City, FL
 

I’m assuming it will work (yikes).  If Magento is merging your config.xml with the one from teh Sales module, it should work.

Look here:
/magento/app/code/core/Mage/Sales/Model/Convert/Quote.php:237
/magento/app/code/core/Mage/Core/Helper/Data.php:323
/magento/app/code/core/Mage/Sales/etc/config.xml:167

EDIT:
The * in the XML is saying ’use the same field name‘, you could also replace the * with the name of the destination field as well.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

Yes, I see what you’re saying. I do have my module set as dependent on <Mage_Sales /> (if that’s a factor) so that could work just as well as code. Def something to keep in mind.

Thanks again!

 
Magento Community Magento Community
Magento Community
Magento Community
 
herve@wsa
Member
 
Avatar
Total Posts:  48
Joined:  2008-07-22
United Kingdom
 

Ho both, thanks for your insights with this issue.. I am at the stage now where my quote has the user input value stored correctly.

I tried the 2 methods you mention and claim as correct. unfortunately, neither seem to trigger the event at all.

I suppose you have it working and you won’t see any obvious error straight away. Is there anybody stuck on the same thing?

Herve

Here is my last xml config..

<?xml version="1.0"?>
<config>
    <
modules>
        <
Untitled_Mto>
            <
version>0.1.0</version>
        </
Untitled_Mto>
    </
modules>
    
    <
frontend>
        <
events>
            <
sales_quote_save_before>
                <
observers>
                    <
my_cart_checker>
                        <
type>singleton</type>
                        <class>
Untitled_Mto_Helper_Event</class>
                        <
method>cartBeforeSave</method>
                    </
my_cart_checker>
                </
observers>
            </
sales_quote_save_before>            
        </
events>
    </
frontend>

    <global>
        <
fieldset>
            <
sales_convert_quote_item>
                <
user_input><to_order_item>*</to_order_item></user_input>
            </
sales_convert_quote_item>
        </
fieldset>
        <
models>
            <
Untitled_Mto>
                <class>
Untitled_Mto_Model</class>               
            </
Untitled_Mto>
        </
models>
        <
blocks>
            <
Untitled_Mto><class>Untitled_Mto_Model</class></Untitled_Mto>    
            <
catalog>
                <
rewrite>
                    <
product_view>Untitled_Mto_Block_ProductView</product_view>
                </
rewrite>
            </
catalog>            
        </
blocks>
        <
resources>
            <
mto_setup>
                <
setup>
                    <
module>Untitled_Mto</module>
                    <class>
Untitled_Mto_Model_Mysql4_Setup</class>
                </
setup>
                <
connection>
                    <use>
default_setup</use>
                </
connection>
            </
mto_setup>
            <
Untitled_Mto_write>
                <
connection>
                    <use>
default_write</use>
                </
connection>
            </
Untitled_Mto_write>
            <
Untitled_Mto_read>
                <
connection>
                    <use>
default_read</use>
                    </
connection>
            </
Untitled_Mto_read>
        </
resources>
    </global>
</
config>
 
Magento Community Magento Community
Magento Community
Magento Community
 
herve@wsa
Member
 
Avatar
Total Posts:  48
Joined:  2008-07-22
United Kingdom
 

sorted.. I missed the “s” for fieldset. Thanks again

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 2 of 2