Inhalte aufrufen

Profilbild

adding new properties to ProductSearchContext from plugin

SmartStore Plugin Development Plugin Development Plugins Plugin Developmen

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

#1 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 11 April 2014 - 10:42

I'm developing new plugin and i need to add a new property in ProductSearchContext and also extend the ProductService to search in this properties in SearchProducts method.... what should i do. 


Sherif Ahmed

Software Engineer

Egypt


#2 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 11 April 2014 - 15:10

Use ProductService.PrepareProductSearchQuery. I've changed the access from protected to public yesterday.
It returns an IQueryable<Product> so no need to extend ProductSearchContext. Simply call ProductService.PrepareProductSearchQuery
and modify the query to your needs.
 
See \SmartStore.Services\Filter\FilterService.cs::AllProducts and its usage as an example how to use it.

  • Sherif Ahmed gefällt das

Marcus Gesing

Smartstore AG


#3 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 12 April 2014 - 14:16

That's great ... it's good for me .. another question?

how to extend or add a new property to the product entity... i need to add a new property to the product entity called 

 

 public virtual ICollection<ProductDeal> ProductDeals
        {
            get { return _productDeals ?? (_productDeals = new List<ProductDeal>()); }
            protected set { _productDeals = value; }
        }

Sherif Ahmed

Software Engineer

Egypt


#4 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1118 Beiträge

Geschrieben: 12 April 2014 - 16:32

I'm afraid the only way to extend existing entities is to modify the core: you can add a new partial Product class which contains your property, furthermore you'll have to define it's database mapping in SmartStore.Data project by extending the class ProductMap the same way. Please consider that all related partial classes must reside within a single project, means your Product partial class has to be coded within the SmartStore.Core project.

 

A better approach would be to use IGenericAttributeService, which enables you to save any data dynamically. Please analyze the source to learn it's usage, it's pretty simple. Advantage is moreover: you encapsulate all your plugin specific code within your plugin.


  • Sherif Ahmed gefällt das

Murat Cakir
SmartStore AG


#5 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 13 April 2014 - 21:32

Hellow again,

 

I'm now trying to add migration for the plugin and I did it successfully but when I'm trying to install the plugin I got that issue

 

Unable to determine the principal end of an association between the types 'SmartStore.Core.Domain.Customers.RewardPointsHistory' and 'SmartStore.Core.Domain.Orders.Order'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

 

any help


Sherif Ahmed

Software Engineer

Egypt


#6 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1118 Beiträge

Geschrieben: 13 April 2014 - 21:57

This should never occur as long as you follow the Migration guidelines for plugins. If you define a plugin private DbContext, then your migration can only refer to this context, not to the core context (SmartObjectContext). Please also read https://smartstore.c...e=Documentation. Did you execute the command add-migration Initial from the NuGet console?


Murat Cakir
SmartStore AG


#7 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 13 April 2014 - 23:29

Enable-Migrations Fires an exception 

Unable to determine the principal end of an association between the types 'SmartStore.Core.Domain.Customers.RewardPointsHistory' and 'SmartStore.Core.Domain.Orders.Order'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.

 

also note, one of my Domain Entities has a relation with the product ..... 

So I have a property 

 

public virtual Product Product { get; set; }

 

Is that a problem


Sherif Ahmed

Software Engineer

Egypt


#8 Murat Cakir

Murat Cakir

    SmartStore AG

  • Administrators
  • 1118 Beiträge

Geschrieben: 14 April 2014 - 17:04

also note, one of my Domain Entities has a relation with the product ..... 

So I have a property 

 

public virtual Product Product { get; set; }

 

Is that a problem

 

Yes, it is :-( Is this domain entity part of your plugin project or part of SmartStore.Core? If the latter is the case, then you have to add a new migration to SmartStore.Data (just ensure that the project is preselected in the NuGet console and execute add-migration MyMigrationName). If the first is the case, then, well, you simply can't enable migrations for this scenario, because Entity Framework Migrations does not support cross-project POCO relations. You have to remove the Product property from your entity and use ProductId::int instead.


  • Sherif Ahmed gefällt das

Murat Cakir
SmartStore AG


#9 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 17 April 2014 - 19:18

Hi,

I'm trying to add partial view in the plugin view ... it's marked as embedded resource and the main view code is like that

 

 @Html.Partial("SmartStore.Plugin.Something.Something.Views.xxxxxx._CreateOrUpdate", Model) 

also I tried to put it like that

@Html.Partial("_CreateOrUpdate", Model) 

but get an error

 

The partial view '_CreateOrUpdate' was not found or no view engine supports the searched locations: ....

is there anything wrong?


Sherif Ahmed

Software Engineer

Egypt


#10 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 17 April 2014 - 20:35

Try by using the full partial view name like this
@Html.Partial("SmartStore.Plugin.Import.Biz.Views.ImportBiz.BackupUploader")
 
SmartStore.Plugin.Import.Biz.... the root namespace of your plugin
Views.ImportBiz... folder and (optional) subfolder of your partial view
BackupUploader... name of your partial view

Marcus Gesing

Smartstore AG


#11 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 17 April 2014 - 21:42

 

Try by using the full partial view name like this
@Html.Partial("SmartStore.Plugin.Import.Biz.Views.ImportBiz.BackupUploader")
 
SmartStore.Plugin.Import.Biz.... the root namespace of your plugin
Views.ImportBiz... folder and (optional) subfolder of your partial view
BackupUploader... name of your partial view

 

 

I Already did that but also the same problem as I said ... and even the one of the search locations which is pointing to it the exception is the place where the view exists ... so is there any thing I should do else ....?


Sherif Ahmed

Software Engineer

Egypt


#12 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 17 April 2014 - 21:53

I tried to publish the site and it seems to work but in the development environment it does not work .. an idea about that? 


Sherif Ahmed

Software Engineer

Egypt


#13 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 18 April 2014 - 11:47

Can I define Areas inside my plugin project?


Sherif Ahmed

Software Engineer

Egypt


#14 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 18 April 2014 - 20:34

Finally I got it works ... Thx GOD ...

but I just need to know how to reference the _AdminLayout.chtml in my plugin admin views


Sherif Ahmed

Software Engineer

Egypt


#15 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 22 April 2014 - 15:14

I would use the built-in configuration page mechanism as an UI entry for your plugin. Pick out a plugin like Payments.PayPalStandard
and see the view Configure.cshtml there, which is served by a get and a post Configure action method. "Post" is optionally used to save plugin configuration.
  • Sherif Ahmed gefällt das

Marcus Gesing

Smartstore AG


#16 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 23 April 2014 - 00:06

Hello again, :)

 

What about if I have more than one page for configuration, by another words. If I have a pages for Create and Edit and I want from the configure page to go to this view .. but the problem is I cannot let the view (Create, Edit) take the same AdminLayout

I will explain you more below:

 

I have a plugin which has a AdministrationArea (New MVC Area) with route different than Admin route ... for example "Administration/Plugins/something/{action}/{id}"

and I have a action for create a new pluginEntity (which is an entity in my plugin) ... so I need to open a pluginView other than the Configure view to let the user enter his data ... 

 

so by default I routed the configure route to the List action to view all the entries which I have, and from the List I have a button for create new ENTITY which is mapped the Create view, but the create view is coming without the admin layout ..

 

and when I modified the create action to point to the configureMiscPlugin with different actionName ... i got an error because the viewengine can not find the Navbar partial view ... also I tried to add a customengineview to point it to the ~/Administration/Views/Shared/{0}.cshtml but nothing .. still the same issue.


Sherif Ahmed

Software Engineer

Egypt


#17 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 23 April 2014 - 12:10

Sounds complicate to me. Some suggestions to try out...

Example for a plugin razor view (embedded ressource) without any layout:
New view in /Views/MyPlugin/Tester.cshtml

@{
	Layout = "";
}

<div>Tester!</div>

New action method:

public ActionResult Tester()
{
	return View("SmartStore.Plugin.Misc.MyPlugin.Views.MyPlugin.Tester");
}

Request through: any-shop.com/Plugins/MyPlugin/Tester

Now using a light backend layout version:

@{
	Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}

@section navbar
{
}

<div class="section-header">
    <div class="title">
        <i class="icon icon-fire"></i>
        Hello world!
    </div>
    <div class="options">
    </div>
</div>

<div>Tester!</div>

  • Sherif Ahmed gefällt das

Marcus Gesing

Smartstore AG


#18 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 23 April 2014 - 22:15

Dear Marcus,

 

I appreciate your help, but the point is can I fully use the whole AdminLayout ... in your example you are using the light weight as you said of the AdminLayout without the navbar .. what about the whole one ... can this be done or not


Sherif Ahmed

Software Engineer

Egypt


#19 Marcus Gesing

Marcus Gesing

    SmartStore AG

  • Administrators
  • 3799 Beiträge

Geschrieben: 24 April 2014 - 10:37

I have never tried this. Remove the @section navbar statement and see what happens.
I don't know any plugin that is doing what you want to achieve.

Marcus Gesing

Smartstore AG


#20 Sherif Ahmed

Sherif Ahmed

    Advanced Member

  • Members
  • PunktPunktPunkt
  • 35 Beiträge

Geschrieben: 24 April 2014 - 15:05

i got an error because the viewengine can not find the Navbar partial view

 

I will explain you what I want to achieve :

I'm doing a plugin which contains 2 mvc areas like below

 

Plugin

  - Areas

     - Administration

     - PublicInfo

 

and I did the plugin configuration route like that:

public void GetConfigurationRoute(out string actionName, out string controllerName, out RouteValueDictionary routeValues)
{
actionName = "List";
ControllerName = "myController";
routeValues = new RouteValueDictionary() { { "Namespaces", "SmartStore.Plugin.Something.Something.Areas.Administration.Controllers" }, { "area", "Administration" } };
}

so I'm trying to access any of the resources or views of the admin I can not because I'm not on the same area which is ("Admin") 

 

so when I removed the Navbar section the view engine will try to find Navbar partial view in my Area => Views | Area => Views => Shared folder ... which is not there ...

 

and also I tried to add customViewEngine as in this article ( I just took the "How do I create a view engine, not the whole article as it's for nopcommerce not for smartstore and also it is not for the purpose I want so I just take that part" )

 

http://www.pronopcom...tom-view-engine

 

and defined there the paths for the partial views to point to the "~/Administration/Views/Shared" and "~/Administration/Views/"

 

and in routeprovider.cs i registered this custom view engine and the route to my administration area in registerroutes methods like that:

public void RegisterRoutes (RouteCollection routes)
        {
            System.Web.Mvc.ViewEngines.Engines.Add(new CustomViewEngine());

            routes.MapRoute("Plugin.Something.Something.Administration",
                 "Administration/Plugins/Something/{action}/{id}",
                 new {controller = "myController"},
                 new[] { "SmartStore.Plugin.Something.Something.Areas.Administration.Controllers" }
            );

        }

the route for my administration controller works fine no issue in that .... but the views are embedded ... and viewengine is not picking the the partial views from "~/Administration/Views/Shared/{0}.cshtml" (although I did that in the customviewengine) he is trying to find them in my views folder not the core views folder

 

I hope you got my point of view in that ..   :)


Sherif Ahmed

Software Engineer

Egypt



Auch markiert mit einem oder mehrerer dieser Schlüsselwörter: SmartStore Plugin Development, Plugin Development, Plugins, Plugin Developmen