Adding a PDF file to a product with a module

Please LogIn to Reply!

Post By: admin | 26-01-2012 06:35 Reply



I’m trying to develop a module that takes some fields as input (such as title and background image) and renders those to a template in PDF format. As soon as the customer is satisfied with the template he can order the customized product. (In fact, the Add to Cart link should be invisible before that, but that’s an issue of later concern).

I’m trying to figure out the correct way to do this. I’ve tried several different options, but can’t make any of them work exactly as I want to.

Some of the stuff I’ve tried:

- Adding a (backend) text attribute to the product and modify this property by modifying the model using observers on the product view page. This didn’t work as the attribute would constantly get reset to the backend defined value.

- Adding a quote/order attribute in the model and as soon as the product gets added to the card catch the checkout_cart_product_add_after event and insert the PDF-file value into the quote. This gets ported to order afterwards. This actually works rather well except for the fact that when a customer adds more than one of the product to his/her cart they get ‘stacked’ in the cart as the product properties are identical. This overwrites the quote attributes with the latest addition, making this a failure as well.

- Adding User Options to a product makes it unique and stops Magento from stacking them together in the Cart, preserving my quote/order attributes for each product. However, I don’t really have User Options except for the options defined in the module resulting in a PDF file. So having a customer fill in an additional User Option field just for the sake of uniqueness of the product wouldn’t make my client very happy. So.. I figured I’d abuse the User Options fields as the inputs for my module, capturing their input with a javascript observer and rendering the PDF file using ajax callbacks on the server. This however has 3 major drawbacks as well:
(1) The User Options fields are very generic; Only the name differs from other options, and the name isn’t very descriptive either (being option_2 and option_3), which makes them very hard to capture in a generic way.
(2) I can’t stick User Options in an Attribute Set, so the options would have to be hand-made for every product being added that uses this module.
(3) The available types for User Options don’t cover all the input features I’m going to need for my module. (I need to add buttons for rotation, scaling, font, etc.). I could stick to some basic fields as User Options and define the rest within my module block on the product page, but this would make the navigation for customers ‘weird’ to say the least.

Actually, probably the best solution would be (I think) is to keep all the inputs within the module block and writing the link to the PDF file to some sort of ‘hidden’ User Option (type text would do, as I can later filter that text line out and proccess it accordingly). This would make the product unique so it won’t get stacked in the Cart, and I don’t have to fuss around with transitions between quote and order as Magento will automagically take care of it, as it does with ‘regular’ User Options.

This however is where my knowledge of Magento leaves me dead in the water… Is this the correct way to do this kind of task? Is there perhaps a much easier (preferred) way of doing this that I totally overlooked? How would I go about and implement the solution?

Any pointers would be greatly appreciated!

`Reply Or Comment!
Please LogIn to Reply!