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

Adding custom variables to products (for a gift registry)
 
centuryhouse
Jr. Member
 
Total Posts:  15
Joined:  2009-02-16
 

Upon adding an item from the gift registry to the users cart, I need to set a flag that lets the shopping cart know it is a gift registry item.  I try to do so using the following code (the module is a dupe of the Wishlist):

try {
        $product 
Mage::getModel('catalog/product')->load($item->getProductId())->setRegistryItemId('55');
        
$quote Mage::getSingleton('checkout/cart')
           ->
addProduct($product, (int)$_POST['qty'])
           ->
save();
        
//$item->delete();
    
}

Where 55 is the value I wish to pass to the shopping cart. The variable seems to be set correctly up to the point of actually adding the item to the shopping cart (save()), then it just disappears.

Does anyone have any ideas? Or run into a similar situation?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
centuryhouse
Jr. Member
 
Total Posts:  15
Joined:  2009-02-16
 

I think I may need to add this variable as an attribute.  I’ve added the attribute registry_item_id to the attributes list through admin, but I can’t seem to figure out where/how to add the xml code to add the attribute to the page.

<action method="addAttribute"><attribute>registry_item_id</attribute></action>

I believe that is the correct code I’m supposed to add to one of the .xml files (checkout.xml?)

 
Magento Community Magento Community
Magento Community
Magento Community
 
centuryhouse
Jr. Member
 
Total Posts:  15
Joined:  2009-02-16
 

Bump...still haven’t found a solution to this. Considered doing something in the session but that wouldn’t work if some one left their cart for whatever reason.

 
Magento Community Magento Community
Magento Community
Magento Community
 
centuryhouse
Jr. Member
 
Total Posts:  15
Joined:  2009-02-16
 

Bump for the “How do I” forum

 
Magento Community Magento Community
Magento Community
Magento Community
 
centuryhouse
Jr. Member
 
Total Posts:  15
Joined:  2009-02-16
 

Any suggestions as to where to start at least?

 
Magento Community Magento Community
Magento Community
Magento Community
 
centuryhouse
Jr. Member
 
Total Posts:  15
Joined:  2009-02-16
 

Still trying to figure this one out…

 
Magento Community Magento Community
Magento Community
Magento Community
 
ModifyMage
Sr. Member
 
Avatar
Total Posts:  84
Joined:  2008-10-15
 

Look, I’m new here, but I think you need to add it in an xml file in app/etc/modules to use it on all pages. I have a file called SFA_All.xml (SFA is my namespace) that does this for my custom attributes as well as adding modules, etc. This is the format for adding a custom product attribute:

<?xml version="1.0"?>
<config>
 <
frontend>
    <
product>
      <
collection>
        <
attributes>
          <
registry_item_id/>
        </
attributes>
      </
collection>
    </
product>
  </
frontend>
</
config>

I hope that is what you are asking (or at least helps). Good luck.

EDIT: My (admittedly limited) understanding is that all of the xml files in this folder get loaded, so that you can place that code in one and name it anything (.xml) and it should work.

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