MAP Pricing product template

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
I have created a new product template called "ProductSimpleMAP" (which hides the price for products that I must conform to manufacturer "Minimum Advertised Pricing" policies).   So I just change the product template for each product that must conform to this policy and it works fine.

My problem is on previous pages (Home Page, Search, Category Products, etc) when it shows products in a grid - it still shows the price.

So I figured I would modify _ProductBox.cshtml   But then I got pretty lost pretty quick.

Is there a way from within _ProductBox.cshtml I can check the Product.ProductTemplateId to determine if this product should display a price or not?

I was thinking something like this:

@if (Model.ProductTemplateId == 3)    // <<<=== this is what I don't know how to do
{
    <span class="price actual-price">CLICK IMAGE TO SEE PRICE</span>
}
@else
{
   <span class="price actual-price">@Model.ProductPrice.Price</span>
}

But the above doesn't work and I don't know how to access the ProductTemplateId from within the view.

Can anybody point me in the right direction?
7 years ago
There's no easy way, need to pull from database. Not recommended to do it on View, but if you must, here's how:

@{
var productService = EngineContext.Current.Resolve<IProductService>(); // make sure you add the appropriate reference
var product = productService.GetProductById(Model.Id);
var templateId = product.ProductTemplateId;
}
7 years ago
Is there a "nopCommerce preferred method" of doing this?  

Maybe modifying _ProductBox.cshtml is not the place to do it?    

I've thought about copying _ProductBox and creating a custom view (e.g. _ProductBoxMAP.cshtml) and then from other views decide which of the two _ProductBox's to display.   But regardless I'd still have to pull from the database to get the condition to make that decision.  

So unless there is a completely different way (besides modifying the views) for me to not display the price for "some" products on the product grid - I think this is my only option.
7 years ago
Figmo wrote:
Is there a "nopCommerce preferred method" of doing this?  

Maybe modifying _ProductBox.cshtml is not the place to do it?    

I've thought about copying _ProductBox and creating a custom view (e.g. _ProductBoxMAP.cshtml) and then from other views decide which of the two _ProductBox's to display.   But regardless I'd still have to pull from the database to get the condition to make that decision.  

So unless there is a completely different way (besides modifying the views) for me to not display the price for "some" products on the product grid - I think this is my only option.


You can use custom theme. Otherwise custom code.
7 years ago
Figmo wrote:
Is there a "nopCommerce preferred method" of doing this?  

Maybe modifying _ProductBox.cshtml is not the place to do it?    

I've thought about copying _ProductBox and creating a custom view (e.g. _ProductBoxMAP.cshtml) and then from other views decide which of the two _ProductBox's to display.   But regardless I'd still have to pull from the database to get the condition to make that decision.  

So unless there is a completely different way (besides modifying the views) for me to not display the price for "some" products on the product grid - I think this is my only option.


The next logical (and better) way is to do it in code, i.e. the source code. It's cleaner, but requires more setup. :)
7 years ago
Thank you, wooncherk.   I used your code snippet and was able to achieve my goal.

One last question - any way to access the current store from within the view?

Here is why: I have it working now where, for MAP controlled products only, I display "CLICK IMAGE FOR PRICE".  And all the other products display the actual price as normal.

What I would like to change is my display string.  Instead of saying "CLICK IMAGE FOR PRICE" I'd like it to just say "CLICK FOR PRICE" - and have the text itself be a link to the product details page.  

I could build a URL for the <a> tag based on Model.Id if I had the store URL (I am setup for multi-store so I can't hard-code it).
7 years ago
@{
var storeContext = EngineContext.Current.Resolve<IStoreContext>();
var currentStore = storeContext.CurrentStore;
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.