axel wolf
axel wolf

Reputation: 1478

Nested JSON-response from Magento-REST in Sencha Touch 2's Store

I'm having a hard time using my product-store's proxy on a response coming from magento 1.7

The response looks like this:

{
 "1":
   {"entity_id":"1","type_id":"simple","sku":"dress_test","status":"1","visibility":"4","tax_class_id":"2","weight":"1.0000","price":"1500.0000","special_price":"1000.0000","name":"Wedding dress","url_key":"dress","country_of_manufacture":"AO","msrp_display_actual_price_type":"2","gift_message_available":"1","news_from_date":"2012-03-21 00:00:00","news_to_date":"2012-03-24 00:00:00","special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"White wedding dress"},
 "2":
   {"entity_id":"2","type_id":"simple","sku":"black_sunglasses","status":"1","visibility":"4","tax_class_id":"2","weight":"0.2000","price":"500.0000","special_price":"300.0000","name":"Sunglasses","url_key":"sunglasses","country_of_manufacture":"AR","msrp_display_actual_price_type":"2","gift_message_available":null,"news_from_date":null,"news_to_date":null,"special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"Black sunglasses"}
}

But the input expected from sencha (I think) should look like this:

{
 {"entity_id":"1","type_id":"simple","sku":"dress_test","status":"1","visibility":"4","tax_class_id":"2","weight":"1.0000","price":"1500.0000","special_price":"1000.0000","name":"Wedding dress","url_key":"dress","country_of_manufacture":"AO","msrp_display_actual_price_type":"2","gift_message_available":"1","news_from_date":"2012-03-21 00:00:00","news_to_date":"2012-03-24 00:00:00","special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"White wedding dress"},
 {"entity_id":"2","type_id":"simple","sku":"black_sunglasses","status":"1","visibility":"4","tax_class_id":"2","weight":"0.2000","price":"500.0000","special_price":"300.0000","name":"Sunglasses","url_key":"sunglasses","country_of_manufacture":"AR","msrp_display_actual_price_type":"2","gift_message_available":null,"news_from_date":null,"news_to_date":null,"special_from_date":"2012-03-21 00:00:00","special_to_date":"2012-03-24 00:00:00","description":"Black sunglasses"}
}

How can I change the behaviour of the proxy to be able to store the loaded data into my store?

Many thanks in advance!

Upvotes: 1

Views: 442

Answers (1)

olegtaranenko
olegtaranenko

Reputation: 3880

To customize your own response you have to subclass Ext.data.reader.Reader Reader or in your case Json class converts data from the response to result set is accepted by Sencha's Model/Proxy/Store.

Cheers, Oleg

add

Ext.define('lib.data.reader.Json', { 
    extend: 'Ext.data.reader.Json', 
    alias : 'reader.magentojson', ... 
})

than use later reference on the reader: 'magentojson'

and you keep original reference to 'json' reader!

Upvotes: 1

Related Questions