Magento Ajax File Upload - ajax

I'm trying to achieve an ajax file upload in Magento, rather than the typical file input provided by adding Custom Options.
I'm looking for insight on how to pull this off. My main stumbling block is how to attach the file back to the product when adding to the cart?
I have an Observer listening for the event "checkout_cart_add_product_complete" I'm trying to add the file information I'm storing to the session, back to the product, so it behaves like a normal file upload within the cart.
I'm looking at Mage::getModel('catalog/product')->addCustomOption() but can't get it to work.
Any insight would be really appreciated.

You need to be adding it to the Item object in the Quote which is stored in Mage::getSingleton('checkout/session'). Each Checkout session has a Quote which is basically the cart state. You can do
foreach(Mage::getSingleton('checkout/session')->getItems() as $item) {
print_r($item->getData());
}
to see all of the items in the cart (but the output will be very messy). So in terms of your 'stumbling block' of getting custom objects saved for that item selection in that person's cart, you need to be editing data on the Item.

Related

How we call "Pages" name in Dropdown in Signup form of PHPfox?

In PHPfox, i want to call "Pages" name in drop-down in Signup form. Reason for calling "Pages", Actually i have created many pages for college name & that are saved in database. So if someone comes for signup, i want to show them college name in drop-down (which are basically "Pages").
Please help me.
Thanks in advance.
You will need 2 plugins, one to show the HTML and one to process what to do with the user input:
1) Make a plugin that fetches the pages, maybe the hook user.component_controller_register_1 or another in that controller would do but otherwise you can always use a low level hook like run_start and check if its the section where you want it.
To show the HTML you have 2 options: include a JS file to populate the sign up form with anything that you want, or if you have a custom template you can just assign the array to the template variable and look through it in your template.
2) Once the html part is showing and working make a plugin for the sign up routine, I think the hook user.service_process_add_1 should be enough given its location.
Dont forget that the input name for the signup is an array, so your drop down needs to look somewhat like this:
<select name="val[my_dropdown]">

Backbone.js - don't render view/template again

In my app I have a list of products and when you click on a product, a Fancybox opens to show the product details.
Now when the user closes the Fancybox, I change the URL back from '#/product-name' to '#' and the list of products is rendered again, even though it is already there.
My question is:
How do I avoid the product list from being rendered again?
So somewhere either in the list action of my controller or the list view I want to check if the product list is already rendered and don't render it again.
It feels like something that should be possible to accomplish quite easily but I can't get it right.
All ideas appreciated!
EDIT: edited for clarification
Have a look at backbone:s saveLocation method. It doesn't trigger a hashchange event.
You only need to change the hash part of your url.
window.location.hash = ""

Paginating a long list of checkboxes in Magento

it would be awesome if someone could help me with this - I've already spent more than a day on it. :(
In a phtml file in Magento, I'm displaying a long list of products with a checkbox next to each. I've already added some code to paginate this list. The problem is, when I move to say page 2, I need to 'remember' which boxes were selected in page 1, and select them when I move back to page 1. I know how to use javascript to detect if a checkbox is checked or not. I was planning to save an array of selected boxes in the magento session - adding to it when more boxes are checked and deleting when boxes are unchecked. But my session-changing code is PHP, and my checkbox-detector is javascript. I know I can't call my session-changing function from javascript - I've been told that I would need AJAX to do this. I don't know any AJAX at all. Is there any other way to do this?
I'd be happy to post relevant snippets of my code if anyone can help me. Thanks!
UPDATE:
Okay, so I decided to use AJAX after all, and I've added a lot of AJAX code already. The problem is, it's not working. Btw, I'm not using jQuery. When I write this in Magento:
xmlhttp.open("POST", 'adjust_session.php', true); xmlhttp.send(params);
exactly where do I need to put my adjust_session.php file? It's not working if I put it in the same folder as my phtml file (where I'm calling the open function).
Thanks!
How are you actually doing the pagination? If you have to make a round-trip to the server for the paginated data anyway, send a list of checked/unchecked with it and toggle in the session. Then, when rendering the new page, either check the boxes in the HTML directly, or just pass a list of currently checked boxes in as JS and parse it on the response.
Alternatively, if you are doing everything on one page (and using AJAX for pagination already), you could also hold onto an array in JS and recheck the boxes after you render them.
Hope that helps!
Thanks,
Joe

Magento : create ajax dropdown populated with labels of 3 product's attributes.

Greetings,
I'm, unluckily in need of having this :
Product has (lets say) 6 attributes with "Yes/No" values.
I need a dropdown on that product's page that will populate with attributes with "yes" value.
attributes are :bundle1,bundle2....,bundle6.
When selection is made - I need to know whats have been selected to pass that to php on that page.
I have no idea what preexists in Magento (in terms of Ajax snippets) that could be used for this, searching for solution...
I used additional request.js and pulled attributes from a newly created table in DB (manually, for 1 product, just for test) and it works.
But, thats not idea, I dont want to do it manually everytime.
Syntax is killling me.
Thank you.
This may not be helpful at all... But I just recently created a module that taps into Magento's ajax autopopulate functionality. What this module does is does an autopopulate of all the manufacturers, depending on the string you are typing in. I know this isn't directly what you are wanting to do, but this may help you get started, at least with the ajax:
/app/etc/modules/Ash_Manufacturers.xml
http://pastie.org/841014
/app/code/local/Ash/Manufacturers/etc/config.xml
http://pastie.org/841017
/app/code/local/Ash/Manufacturers/controllers/IndexController.php
http://pastie.org/841018
/app/code/local/Ash/Manufacturers/Block/Manufacturers.php
http://pastie.org/841020
Look at rows 79-92 on this one:
/app/design/frontend/default/ash/template/catalog/layer/filter.phtml : http://pastie.org/841027

Magento - adding a new field to the product options in admin

I'd like to add a new tab to the 'catalog->manage products->product information' page in the admin. Underneath the 'images' tab, I'd like to add a new tab for video, with a simple text input for adding a video url, which I can then grab for the frontend.
Anyone any ideas where the files are that I need to edit? I've been looking for the last couple hours with no joy. I found the list of current options in Mage_Catalog_Model_Resource_Eav_Mysql4_Setup but can't figure out how to add to them...
Seems it gets some from Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs. If I copy one of the tab sections here and change the title to Video, I can get it to display in the tabs on the left. But how do I then add the options for it?
What you are trying to do, from the sounds of it, is to create a custom field and add it to your catalog data. The good news is that you don't need to muck around in the PHP for that.
Head to Catalog -> Attributes -> Manage Attributes and create a new attribute for yourself called "Video URL" (or something to that effect). This will probably be a text field, and you may want to hide it from comparison on the frontend of the site (select "No" for all those boxes at the bottom of the form).
Once you've created an attribute, you will need to add it to an attribute set. If all your products are of one "type", and if you didn't create any other attribute sets, this should be only one step. Head to Catalog -> Attributes -> Manage Attribute Sets and create a "New Group" called "Video" and drag your new video url attribute into it. Save the attribute set and you should now have your new tab.
The only complication from what I read in your post could be positioning it underneath the images tab. Magento adds several tabs statically (the long way, in the PHP) and doesn't generally obey ordering of the tab groups. Consider the time tradeoff.
Hope that helps. Thanks,
Joe
Per your other comments, for the URLs a simple attribute would work but files would tend to be more difficult. To add a custom tab, as you said, you can edit (or in the case of a plugin, override) Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs::_prepareLayout and add your tab. You'll need to add a block or template to display your tab contents.
After that, you'll need to store the data somewhere. Looking in Adminhtml/controllers/ProductController, you should be able to hook into the catalog_product_prepare_save event to get data from $event->getRequest() and push it onto the product or save another entity as necessary.
I'm not sure how well file saving semantics would work on a product, so you may want to do your own data storage in the extension and then provide something like a getVideoForProduct method to retrieve it.
Then the only thing left to do is modify the catalog/product/view.phtml template file to include your thumbs and create a controller in your extension to provide a modal w/ the video (or do it in JS).
I know that's a bit of a general answer, but it's the rough path you would need to take for tabs. Let me know if any specific part of that is unclear.
Thanks,
Joe

Resources