1

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!

axel wolf
  • 1,446
  • 3
  • 18
  • 29

1 Answers1

1

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!

olegtaranenko
  • 3,722
  • 3
  • 26
  • 33
  • That is working but: Now I need both versions working. The _normal_ sencha version on one store and my _extended_ version on another store. But I can only achieve to have working either _normal_ or _extended_. `Ext.define('lib.data.reader.Json', { extend: 'Ext.data.reader.Json', alias : 'reader.json', ... });` – axel wolf Oct 10 '12 at 07:44
  • got it figured out: `reader: { type: 'magentojson', rootProperty: 'items' }` needs to reference to the _extended_ class – axel wolf Oct 10 '12 at 16:00