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

PHPArchitects’ Magento book in v1.1.1
 
ylibrach
Sr. Member
 
Total Posts:  78
Joined:  2008-07-06
 

I’m having some trouble getting one of the sample modules in PHPArchitects’ Programming in Magento book to work with v1.1.1. Specifically, in the Made to Order module, the book refers to creating a new front-end attribute called mto_length which is supposed to save to the Sales Quote when the user adds a product to the cart. The book says that this attribute will be saved in a table called sales_quote_item_varchar, however this table no longer exists in v1.1.1. Does anyone know where such values are stored now?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ylibrach
Sr. Member
 
Total Posts:  78
Joined:  2008-07-06
 

Noone has any idea what happened to sales_quote_item_varchar in 1.1.1? I can’t find documentation of the change anywhere. This is a pretty big change…

 
Magento Community Magento Community
Magento Community
Magento Community
 
bytestorm
Magento Team
 
Total Posts:  91
Joined:  2008-04-02
 

sales_quote_item_* tables were removed, as i remember
all the data related to quote items now being stored in sales_flat_quote_item table

 
Magento Community Magento Community
Magento Community
Magento Community
 
ylibrach
Sr. Member
 
Total Posts:  78
Joined:  2008-07-06
 

Thanks for your response. I have tried looking in this table, and I see a key/value array, but it’s not displaying the correct information. For example, I have the following Observer function which gets triggered on the sales_quote_save_before event:

static function cartBeforeSave($observer{
    $event 
$observer->getEvent();

    
$req Mage::app()->getRequest();
    
$items $event->getQuote()->getItemsCollection();
    
$mto_length $req->get(’user_length’);
    
$product_id $req->get(’product’);

    if (!
$mto_length && !$product_id{
        
//only run if the user is submitting
        // data to the cart controller.
        
return;
    
}

    
foreach ($items as $item{
        
if ($item->getProductId() === $product_id{
            
if(!$item->getMtoLength()) {
                $item
->setMtoLength($mto_length);
                break;
            
}
        }
    }
}

mto_length is an attribute. Magento is storing values into the table you mentioned with the key of user_length, not mto_length. Do you know why this would happen?

 
Magento Community Magento Community
Magento Community
Magento Community
 
ylibrach
Sr. Member
 
Total Posts:  78
Joined:  2008-07-06
 
bytestorm - 31 July 2008 09:52 AM

sales_quote_item_* tables were removed, as i remember
all the data related to quote items now being stored in sales_flat_quote_item table

bytestorm, this can’t be the table for storing custom quote attributes as the sales_flat_quote_item table is not an EAV table. It is a regular flat table with pre-defined columns for all the information about quotes.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ylibrach
Sr. Member
 
Total Posts:  78
Joined:  2008-07-06
 

This is going to be my last attempt at getting some sort of answer from someone (hint hint, Magento team). There was a change in the handling of Quotes in 1.1.1 which seems to have broken some functionality. I have been breaking my head over the code the last few days, and I need some clarification on something.

In v1.0, I could write something like this:

// $item is of type Mage_Sales_Model_Quote_Item
$item->setMtoLength($mto_length);

And $item would receive an attribute of mto_length with whatever value I give it. In turn, Magento would save the value of mto_length into sales_quote_item_varchar, so that that attribute would then be reloaded when the customer is checking out (or converting the Quote to a Sales Order), and could be referenced.

However, in v1.1.1, there is no sales_quote_item_varchar table, or anything even remotely close to it, and it seems that custom attributes like this can no longer be stored for retrieval later.

HOWEVER, the new table structure in v1.1.1 has a table called sales_flat_quote_item_option, which has a ‘value’ column which stores additional data about each quote item. This ‘value’ is automatically populated, and includes custom input fields on the product page and their values. Is THIS the new method to store custom information about products in v1.1.1?

Can someone please confirm if this is the only way to do it now?

 
Magento Community Magento Community
Magento Community
Magento Community
 
bytestorm
Magento Team
 
Total Posts:  91
Joined:  2008-04-02
 

you may store your own attributes in sales_flat_quote_item table too

to do this you should add an attribute to quote_item attribute set (i.e. Mage\Sales\sql\sales_setup\mysql4-upgrade-0.9.11-0.9.12.php)
after installing your upgrade you will find `your_attribute_name` column in sales_flat_quote_item table
then your attribute will be stored in sales_flat_quote_item table

 
Magento Community Magento Community
Magento Community
Magento Community
 
ylibrach
Sr. Member
 
Total Posts:  78
Joined:  2008-07-06
 

Thanks for your reply bytestorm. In the meantime I had actually come up with an alternate solution that doesn’t require modification of the database structure. I’m wondering what your opinion of it is:

I noticed that in sales_flat_quote_item_option table, you store custom data “options” here. For example, you store info_buyRequest here, which is an array of all the Request variables at the time of adding the product to the shopping cart. I simply added another row with a code of mto_length to this table along with info_buyRequest.

Also, when the user completes checkout of the shopping cart, I utilized the event that fires when quote items are converted to order items. Specifically, I took the mto_length value from the quote item and appended it to the product_options array in the sales_flat_order_item table (which also stores the info_buyRequest information).

So which method does Magento recommend? I didn’t want to make modifications to the database structure because it requires changes both to quote tables as well as order tables. Also, it seems like the product_options column in the sales_flat_order_item table is meant for storing custom attributes, no?

Please tell me what you think.

 
Magento Community Magento Community
Magento Community
Magento Community
 
bytestorm
Magento Team
 
Total Posts:  91
Joined:  2008-04-02
 

sales_flat_order_item and sales_flat_quote_item are supposed to store core quote/order item attributes and custom attributes too…
i think you should create your own attribute… that means you will not change db, you will add an attribute…
i.e.
now you have attribute named `info_buyRequest` (actually i can’t remember such attribute for core quote/sales items)
in the next version of some module behavior of this attribute will be changed… then your module will not work as intended…
i think that you haven’t understand that eav functionality is being emulated for quote/order items just to store data in one table

 
Magento Community Magento Community
Magento Community
Magento Community
 
ylibrach
Sr. Member
 
Total Posts:  78
Joined:  2008-07-06
 

bytestorm, I understand the eav functionality, but that’s the whole problem: in 1.1.1, the sales_quote_item and sales_order_item tables became “flat” hence removing the eav functionality. As you said, the only way to do it now would be to add columns to the flat tables. Or am I missing something?

Also, I’m using Magento core functions to put this data in the tables, so I don’t see how in future versions this wouldn’t work. For example, here is the code to put mto_length into sales_flat_quote_item_option:

$event $observer->getEvent();
        
        
$req Mage::app()->getRequest();
        
$items $event->getQuote()->getItemsCollection();
        
$mto_length $req->get('user_length');
        
$product_id $req->get('product');
        
        if (!
$mto_length && !$product_id{
            
return;
        
}
        
        
foreach ($items as $item{
            
if ($item->getProductId() === $product_id{
                $item
->addOption(array(
                    
'product_id' => $product_id,
                    
'product' => $item->getProduct(),
                    
'code' => 'mto_length',
                    
'value' => $mto_length
                
));
            
}
        }

And here is the code to when converting from a quote to a sale:

$event $observer->getEvent();
        
$orderItem $event->getOrderItem();
        
$quoteItem $event->getItem();
        
        if (!
is_null($quoteItem->getOptionByCode('mto_length'))) {
            $options 
$orderItem->getProductOptions();
            
$options['mto_length'$quoteItem->getOptionByCode('mto_length')->getValue();
            
            
$orderItem->setProductOptions($options);
        
}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Ngo Minh Tuan
Jr. Member
 
Total Posts:  1
Joined:  2008-09-14
 

Thanks ylibrach for your find out.

I have a same need to save custom attribute to order item and I follow that book too. I am working on Magento 1.2.0.1, and don’t see any thing at sales_order_entity_varchar.

Then I try your way, saving through $orderItem->setProductOptions($options), then I got what I need now: order item’s custom data is saved and then show in admin report. It’s great.

- Tuan Ngo.

 
Magento Community Magento Community
Magento Community
Magento Community
 
satru
Jr. Member
 
Total Posts:  1
Joined:  2009-05-12
 

Heartedly thanks, Iwas going through same book and process and facing the problem

Thanks a lot

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top