Magento Ajax cart - the correct way - magento

I have created an Ajax cart in magento although it is a little hacky. It's not in a module or that. All I'm doing is using a script in the root of app that initialise mage and works with it.
What would be the correct way in implementing this? Ie how can I get my Ajax calls to interact wiu magento through a my module?

You should define a module, first and foremost. Once you've done that, you need to create controllers and actions such that they return the data you're looking for, but not the frame of the page. Since you get to define layout of the page, this shouldn't be too bad.
At that point, wiring the JS to the new actions should be as simple as changing URLs to your new, cleaner URLs.

Related

Oxid eShop event handlers

I am trying to create some tracking events on OXID eShop Framework on a custom module but I can't find any event handlers or something to put the code on some custom pages, without editing the core files. What I want is to make some custom API calls if I am on product page, category page, basket, etc.
Is there any way I can handle this in a custom module?
OXID has no such events or hooks you might know from magento or shopware. You have two options:
1) For running server side php code you need to extend OXID's functions, e.g. render() function for the pages you want to track.
For the product page it would be "details" -> applications/controllers/details.php
category page is "alist.php" and basket is basket.php
2) Make client side api calls with simple JS. You could appent all your js code to a tempalte block (e.g. in header oder footer) and create some if-else logic for different controller classes.
Like here: https://github.com/OXID-eSales/oxideshop_ce/blob/b-5.3-ce/source/application/views/azure/tpl/layout/base.tpl#L32
You could also have a look at any tracking module for google analytics or piwik, they are pretty similar to what you want to do.
I can give you more examples if you want.

How to load custom post data into a sidebar using ajax?

I have a list of custom posts, and I want to have a sidebar, wherein the information associated with a post selected from the list to load.
If you insist on using ajax to do this then you will need an API for your WordPress site to call back into. Take a look at http://wp-api.org/. It won't necessarily be easy, but you should be able to get it setup and running and then put a piece of JavaScript in a widget to make the call and display the data.
Be careful, that plugin is under active development.
IMO, it would be easier to do this without ajax. Off the top of my head I would say that you could define a shorttag in your functions.php file and then put it in your widget. If the widget appears on a page with a post, pick up the post id, fetch the meta data, and display it.
Cheers!
=C=

Magento Block for in CMS pages to display links associated with that page (set in admin)

So I would like to be able to add a block to certain CMS pages, which would display links for that page.
I am thinking it will use a common (custom) template, to display the links on each page in the same manner, but I need to be able to set the links in the admin side.
I had initially thought about using a widget. which seems to make sense, and wouldn't be too hard to be able to edit in the admin side and add to a page.
But I am not sure how I could create a widget which allows for the addition of multiple links, tied to that page.
Ideally, I could add a block in the cms layout xml, perhaps check if the url path is correct, and displays the links for that page in a block.
As I write this, I realize I am not sure what the best way to accomplish this would be.
I would rather not have it be editable in the content. But I am not sure how else to make it easy to add links to a page.
Is there some way I could create a module or something where you could choose the page in the admin side, set as many links as you want (with label and URL). and then on that page, the block would load the links into the block template?
Any direction, or even a place to start would be VERY helpful. Thanks!

Load content via ajax in plone page

I'm working on a website which has been developed in plone. Now I'm facing an issue, I would like to load certain content from a template via an ajax call on normal Plone page(on some event trigger).
Do I need to create any python script??If yes where has it to be placed? and moreover how do I integrate it with TAL(I guess that would be needed) but I'm not sure how.
Could anyone guide me on this with necessary pointers/docs that I should look into?It would of great help to come over my issue and get things rolling.
Thanks,
Avinash
In the "Plone Developer Documentation" there's a section for Javascripting in Plone that perfectly fits your needs
Your question is a bit vague:
From your question, it seems that you just want your ajax call to return html to populate data on the page somewhere then?
Also, it sounds like you want to do the development TTW in the ZMI? Most developers would would use an add-on product and return your ajax response.
However, you can do it TTW with page templates just fine.
Create the new page template
populate it with the template code that gives you the desired output when called within the context of content on a site. For example, http://mysite.com/plone/page/my-template
in your javascript, use a url that in the ajax call: $.ajax({url: 'http://mysite.com/plone/page/my-template', success: function(data){ $('#content').append(data);}})
It's not really anything special to do ajax within plone--just use the tools available and piece it together.

ExtJs Back Fwd Buttons

In the past I have developed large extjs single page applications. Many users get frustrated for not being able to use the Back or Fwd buttons or reload the page.I would also like to warn the user if they navigate away from a page without completing a work flow, and enable users to directly access particular views.
For the next application, I am thinking of using the Codeigniter php MVC framework. It is possible to something similar to this example. I am stucked thinking about the navigation. If I load the ExtJs for each view, that is a significant slowdown.
How best to approach this?
Have a look at the Ext.History class (Ext.util.History on Ext4). With it you can register listeners for changes to the hash:
Ext.History.on('change', function( token ) {
console.log('token changed to: ', token);
});
The Ext.History singleton includes forward() and back() methods for triggering navigation from within the client-side code.
By having only the hash part of the URL change the browser stays on the same page, thus eliminating the need to reload the Ext library.
How this would integrate with your PHP framework I cannot say. I am not familiar with CodeIgniter and your example link goes to a dead page.
Also, do note a caveat with History in that under Ext3 at least it may give you issues with newer browsers. If this is the case an alternative is to code your own History-like solution using the 'hashchange' browser event as illustrated in this answer.

Resources