- 9
Boyko,
Thank you for responding so quickly.
What I am trying to achieve is this.
When a product has more than one image, I want to be able to choose which image appears on the site in the different places these images are displayed.
So, for example, the first image would appear in the carousel (I can't change the carousel, so the first, default image will appear there) but in a product panel on the home page (I'm using your Alfresco theme btw) I want another image.
So, to achieve this, I think the simplest way is to use the display order which can be applied to product images. This gives administrators the ability to choose which image appears in each location (although the display number probably needs to be hard coded in the places where this feature is used).
This can be done by passing the display order number to the controller from the view that will display the images
So, for example, on the home page, we have the line:
@Html.Action("HomepageProducts", "Catalog")
This is the default, and will display the first image.
I want to use this instead:
@Html.Action("HomepageProducts", "Catalog", new { productPictureNumber = 2 })
The controller action then looks like this:
protected IEnumerable<ProductOverviewModel> PrepareProductOverviewModels(IEnumerable<Product> products,
bool preparePriceModel = true, bool preparePictureModel = true,
int? productThumbPictureSize = null, bool prepareSpecificationAttributes = false,
bool forceRedirectionAfterAddingToCart = false, int productPictureNumber = 0)
{ ... }
This number is passed to the PictureService.GetPicturesByProductId method which will use it to select the correct image (\WebProject\Libraries\Nop.Services\Media\PictureService.cs line 688)
This should be a simple change to make and would solve my problem.
This additional value would not affect the carousel - it would still get its images.
I don't want to have to create an entirely new action in the catalog controller, and then go through the app and call it whenever I want to use this feature - that's extra work, and would entail maintaining two copies of the action in the controller. One of the major features of modern code like MVC is code reuse, and having to duplicate a method to add an additional OPTIONAL parameter breaks this concept.
So, How do I work around this restriction?
Also, out of curiosity, how do you even do this, force a method to keep the same signature? All the other places that call this controller action are quite happy with it - they do not break at run time, so this 'feature' must have been explicitly encoded. How is this done?
I've got a bit of a deadline to work to here, so I'd really appreciate a quick solution to this.
Thanks & Regards
Adam
Thank you for responding so quickly.
What I am trying to achieve is this.
When a product has more than one image, I want to be able to choose which image appears on the site in the different places these images are displayed.
So, for example, the first image would appear in the carousel (I can't change the carousel, so the first, default image will appear there) but in a product panel on the home page (I'm using your Alfresco theme btw) I want another image.
So, to achieve this, I think the simplest way is to use the display order which can be applied to product images. This gives administrators the ability to choose which image appears in each location (although the display number probably needs to be hard coded in the places where this feature is used).
This can be done by passing the display order number to the controller from the view that will display the images
So, for example, on the home page, we have the line:
@Html.Action("HomepageProducts", "Catalog")
This is the default, and will display the first image.
I want to use this instead:
@Html.Action("HomepageProducts", "Catalog", new { productPictureNumber = 2 })
The controller action then looks like this:
protected IEnumerable<ProductOverviewModel> PrepareProductOverviewModels(IEnumerable<Product> products,
bool preparePriceModel = true, bool preparePictureModel = true,
int? productThumbPictureSize = null, bool prepareSpecificationAttributes = false,
bool forceRedirectionAfterAddingToCart = false, int productPictureNumber = 0)
{ ... }
This number is passed to the PictureService.GetPicturesByProductId method which will use it to select the correct image (\WebProject\Libraries\Nop.Services\Media\PictureService.cs line 688)
This should be a simple change to make and would solve my problem.
This additional value would not affect the carousel - it would still get its images.
I don't want to have to create an entirely new action in the catalog controller, and then go through the app and call it whenever I want to use this feature - that's extra work, and would entail maintaining two copies of the action in the controller. One of the major features of modern code like MVC is code reuse, and having to duplicate a method to add an additional OPTIONAL parameter breaks this concept.
So, How do I work around this restriction?
Also, out of curiosity, how do you even do this, force a method to keep the same signature? All the other places that call this controller action are quite happy with it - they do not break at run time, so this 'feature' must have been explicitly encoded. How is this done?
I've got a bit of a deadline to work to here, so I'd really appreciate a quick solution to this.
Thanks & Regards
Adam