I am a developer and I know how hard it is to solve difficult issues while programming in case you did not get any help. I have faced this so many times. That's why I started this blog so that I can share problems and solutions with developer community. In case if you face any issue in programming do check my blog once, it will surely save your time.

Pages

Tuesday, May 26, 2015

Recently I was working on Magento admin where we have to create promotions like Buy 1 Get 1 Free. Initially I had a trouble setting it as I don't know much about Magento admin. So In this blog I am going to explain how to do it in 10 simple steps so it can save your time.

Monday, May 25, 2015

Recently I was working on a project where we were working with MAgento API. There was a requirement to show promotions to user. I have published a post on this. You can check it from here

Now we had another requirement to add items of promo to cart when user purchase an item. Here in this blog I will explain how to do this. Please note this logic will work for Buy X and get Y product free and Buy X and get Y Free logic.

So in API we were passing rule_id. First we will get rule information.

Friday, May 22, 2015

Recently in one of my project we were building mobile app where we have backend as Magento. In this app we have to show all the promotions added in Magento as shopping cart rules. Also there was a requirement to get all the coupons. There is no API for that in default Magento API so I decided to write an API. Here is how to do this.

As you can see in above code we are first getting collection of all the sales rule and then loop trough it and separate offers and coupon. In case of offers like buy 1 get 1 free and percent discount there is no coupon code so coupon_type is set to 1 which means "No Coupon". While for others there are coupons. So just checking by that we populated two different arrays and return it in form of JSON.

Sunday, May 3, 2015

Recently I was working on mobile app where we have APIs return in Laravel. We were handling some date and times on server side. This dates and time from server side was displayed to mobile users. Now mobile users can be in different timezones and so APIs should set timezones and show dates and time according to timezone. Here is how I implemented it. I saved user's timezone in db and for each API request from that user set timezone from database.

First extend a laravel controller with base controller so we don't need to repeat this code everywhere.

This is short and quick blog about how to add global logic to show and hide load mask for each Aajx request in Sencha Touch Application.

In Sencha Touch application Ajax request is used in two ways. Either one can call Ajax request with

Ext.Ajax.request({
})

Or in stores you may have Ajax proxy which will generate Ajax request when store is auto loaded or you call load method. Since this is background process you may want to show loading mask to users. For that you can call setMasked method before Ajax request and you remove that mask in success and failure function. This you have to write everywhere in your code. So it's better to add it to single place.

This how you can do it. Add following code to your launch function in your app.js file.

Since Ext.Ajax is singleton class we have added event handler for beforerequest, requestcomplete and requestexception.

In beforerequest event handler we are setting mask to viewport and in requestcomplete and requestexception handler we are removing it. That's it and the mask will be displayed every time there is a ajax request. Hope this helps you.

This way we get product id in native code and since we returned NO in that delegate, webview will not invoke this url.

Now let's add required library to support in App Purchase. First select project from project explorer and select build phases tab. At bottom where we have linked libraries click on + sign and search for storekit. It will show following framework. Add this to project.

Now open MainViewController.h file and add necessary import statements and delegates. Copy following code.

Here we are checking if product already purchased. If already purchased simply call JavaScript function to consume it else start product request. After we get product information we have to show it to user. Add following code to productRequest delegate.

As you can see we have a buy button there. When user clicks on Buy it will call clickedButtonAtIndex function added in above code and it will start payment process. One payment is done it will call completeTransaction delegate. Add following code to it.