Inhalte aufrufen

Profilbild

SmartStore Web API Get all categories and images

bestätigungsmail plugin sofortüberweisung

  • Bitte melden Sie sich an, um eine Antwort zu verfassen.
6 Antworten zu diesem Thema

#1 Jefferson

Jefferson

    Advanced Member

  • Members
  • 30 Beiträge

Geschrieben: 13 June 2014 - 03:18

Hello guys,

 

I would like to know how can i get all categories and their images (with URL) using the OData CategoriesController in the right way.

 

There's any pattern that i have to follow to keep the code right?

if so, could you share the links?

 

I'm still studying the Web API and i see the folders name as OData and API and i don't know where should i make the "joins"  to the category and picture entities and call the PictureService to return the images path.

 

regards

 

Jefferson

 

 

 



#2 Jefferson

Jefferson

    Advanced Member

  • Members
  • 30 Beiträge

Geschrieben: 13 June 2014 - 04:25

I'm asking here because, i'm afraid to wrote bad code using poor techniques, i am reading about "Odata Query options" but make joins and filters by there seens to be wrong and   to complex.

 

thanks for the support  :)



#3 Jefferson

Jefferson

    Advanced Member

  • Members
  • 30 Beiträge

Geschrieben: 13 June 2014 - 16:19

Any example about  Passing multiple or complex parameters to a GET handler



#4 Jefferson

Jefferson

    Advanced Member

  • Members
  • 30 Beiträge

Geschrieben: 13 June 2014 - 18:49

I mean how could i return the categories and their URL path using OData?

 

Should i need to change the return type of  method to something as a DTO? 

 

protected override IQueryable<Category> GetEntitySet()
{
var query =
from x in this.Repository.Table
where !x.Deleted
select x;
 
return query;
}


#5 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3367 Beiträge

Geschrieben: 13 June 2014 - 19:10

The "More examples" section shows some of the OData options like $filter and $select.
 
Because of category entity has no navigation link for the picture relation you need separate requests
for both entities. I do not know if OData supports another way of joining picture data with the category request,
but I don't think so. Probably the best approach would be to request a paged list ($skip, $top) that is reduced
to required properties ($select) and filtered (if possible).
 
If you want to extend the API by your own logic I would take a look at OData actions.

Schöne Grüße aus Düsseldorf,
Marcus Gesing


#6 Jefferson

Jefferson

    Advanced Member

  • Members
  • 30 Beiträge

Geschrieben: 20 June 2014 - 18:38

So i extended the api creating my own logic, above there's a Get action and it's working okay using the client tools 

 

 [WebApiQueryable(PagingOptional = true)]
 public IQueryable<ProductResult> GetProductsByCategoryId()
 {
      // Here a lot of stuff
 }
 
But i need to pass an argument in this action, like this
 
 [WebApiQueryable(PagingOptional = true)]
 [HttpPost] 
 public IQueryable<ProductResult> GetProductsByCategoryId(int categoryId)
 {
      // Here a lot of stuff
 }
 
But when i try to do this it's not even calling could you help me with this?
 
 


#7 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3367 Beiträge

Geschrieben: 20 June 2014 - 19:38

See "ODataActionParameters parameters" in OrdersController.PaymentPaid for example.
 
string paymentMethodName = parameters.GetValue<string, string>("PaymentMethodName");

POST /odata/v1/Orders(145)/PaymentPaid
{"PaymentMethodName":"Payments.Sofortueberweisung"}
Or use "int key" if "key" is the key identifier for entities handled by your OData controller. Example: CategoriesController.GetAppliedDiscounts(int key)
 
Do not forget configuration of OData actions. See AddActionsToOrder or AddActionsToProduct in WebApiConfigurationProvider.

Schöne Grüße aus Düsseldorf,
Marcus Gesing



Auch markiert mit einem oder mehrerer dieser Schlüsselwörter: bestätigungsmail, plugin, sofortüberweisung