Magento Forum

Adding (free text) attributes to the shopping cart? 
 
panne#
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2008-08-12
 

Hi out there! =)

I’m Panne from germany and very new to Magento and it’s community - of course, I hope to become an expert in a pretty short time… wink

But at this point, I have a big problem implementing some features in a Magento modul:
I have to get some attributes to be shown in the product list, and also in the shopping cart. I spend much time searching for a proper solution here in this forum, and found many threads about how to add attributes to the product list, but that’s all different from my own problem…

Most information I found in this thread, and showing the (also custom) attributes from the database seems to be no problem. So I tried to get things work with the same scheme, but in the shopping cart - adding to app/design/frontend/myshop/default/layout/checkout.xml the following lines:

[...]
    
<checkout_cart_index>
        
[...]
        
<reference name="content">
            <
block type="checkout/cart" name="checkout.cart">
                <!-- 
edit pannemore attributes to the cart -->
                <
action method="setCartOrders"/>
                <
action method="setCartModes"/>
                <
action method="setCartCollection"/>
                <
action method="addAttribute"><code>my_attribute</code></action>
                <!-- 
end edit panne -->
                
[...]
            
</block>
        </
reference>
    </
checkout_cart_index>
[...]

But, the data for my_attribute isn’t in the database, it’s filled in by a customer while he’s searching my shop.

For an example let’s use the T-shirt shop:

say, the customer can type in some text on my shop to print on a shirt, can choose font, fontcolor, color of shirt and so on.
Adding colors and fonts as configurable products should be no problem, but: how could I get a free text field working best, and take it’s data through the whole shopping process with my customer to the cart?
And how to add these attributes to the cart, to be shown with the product?

I also edited the app/design/frontend/myshop/default/template/checkout/cart.phtml, to change the cart table of products to get new columns, for example I added the following line after line 65 (same code, just other text to be shown):

<th rowspan="<?php echo $mergedCells; ?>"><?php echo $this->__('T-Shirt Text'?></th>

This adds the new table header column - but how do i add the table data?
Do I have to change (or overload) the getItems() and/or the getItemsHtml($_item) methods, and if so, where do I find them?
Or is something wrong with my configs in the .../layout/checkout.xml? (and when these are corrected, should the data be shown without more changes?)

I want to do this within Magento’s rules of programming - but I’m not sure, how it’s the right way… =/
(And also I’m not sure, if all my changes are the correct ones!)

Which more files do I have to edit (and what functions or configs are required there)?

Would be happy about any hints, links to read more information, and of course I’ll be very happy about exact instructions to do this. wink

thanx a lot for any help!

 
Magento Community Magento Community
Magento Community
Magento Community
 
markl
Member
 
Total Posts:  39
Joined:  2008-04-18
 

Hi Panne,

Please forgive me if I’m missing your point completely, but continuing your T-shirt example, could you add a custom field to each T-shirt product called “T-shirt slogan”? I do something similar on my site, where the customer enters their full name and a start date into a simple text field.

If you need to charge extra for printing on the shirt, could you create a simple product called “Add slogan to T-shirt” with a custom field for the slogan to be entered, then make your actual T-shirts configurable products and add the “Add slogan to T-shirt” as an associated product, so that you can enter the price to add on for the privilege of having their slogan printed on the shirt.

Again, you seem to know what you’re talking about so I suspect that I may have missed the point of your question. If so, let me know where I’ve picked you up wrongly and I’ll see if I have any other bright ideas.

Thanks,

Mark

 
Magento Community Magento Community
Magento Community
Magento Community
 
panne#
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2008-08-12
 

hi Mark,

first, thanx for your reply.

My point at this moment is to get these fields shown in the cart - I already have got some fields to get this needed data from my customer, but I’m not able to show these in the shopping cart.

In app/design/frontend/myshop/default/template/checkout/cart.phtml, there is build a table, with table headers hard coded - adding there one (or more) more columns is no problem.
But: the table body is build by a foreach-loop:

[...]
<tbody>
     
<?php foreach($this->getItems() as $_item): ?>
          <?php 
echo $this->getItemHtml($_item?>
     <?php 
endforeach ?>
</tbody>
[...]

So, I thought, the additional attributes should be shown if my configs in app/design/frontend/myshop/default/layout/checkout.xml were the right ones (plz see my first post for them). Unfortunately, they don’t. Now, I’m not sure, if my configs were wrong, or do I have to do some more hacking anywhere?

BTW, you said “you seem to know what you’re talking about” - uhm… does anyone really know, what he’s talking about, when he’s talking ‘bout Magento? ;D
hehe, just kidding, but of course I’ll have to learn a lot more before I would say I know about Magento...

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

Read some more documentation (I don’t know where to tell you to look) about getting Magento to know to use your version of a layout or template instead of the default. You have to tell it to load it, somehow.
(I know I read it somewhere, but I didn’t need it at the time...)

 
Magento Community Magento Community
Magento Community
Magento Community
 
panne#
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2008-08-12
 

@joyously: thanx, but I think, this is what would be called “redundant information"… wink

When you remember where you did read these things, plz post it and I’ll luckily read it.

To update the state of my problem: at the moment I’m trying if the Event-Observer-Method is a good way to solve my quest…
(My Magento-Version btw is 1.1.1)

 
Magento Community Magento Community
Magento Community
Magento Community
 
raffi vitis
Jr. Member
 
Total Posts:  11
Joined:  2008-08-26
 

#panne, i was wondering if you found out where the information in the checkout table is coming from. i have a different problem (i want to change the place some of the fields in the table…

 
Magento Community Magento Community
Magento Community
Magento Community
 
raffi vitis
Jr. Member
 
Total Posts:  11
Joined:  2008-08-26
 

and 12 minutes late i got the answer: template/checkout/cart/item/default.phtml is where the td in the cart table come from.

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