Error when using partial view :ProductVariant_SKU_Man_Stock

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 years ago
You can also overload the method in the Catalog controller to call stock availibilty.

Its contained in the following non action


[NonAction]protected ProductModel PrepareProductOverviewModel


I am currently working on the same idea.
11 years ago
Hi

Well I created a partial view as suggested by Creative, but I get the same error as when I tried to use the ProductVariant_SKU_Man_Stock view, being a novice I will post my code in case I have made any glaring errors which someone may see right away.


Creatives code was @model  ProductModel.ProductVariantModel  but that throws an error staright away.

So my view is called _ProductStockLevel with the following code

@model  ProductDetailsModel.ProductVariantModel
@using Nop.Web.Models.Catalog ;
       @*Stock availability*@      
       <div class="stock">
          @T("Products.Availability"): @Model.StockAvailablity
       </div>

I also tried

@model  ProductDetailsModel.ProductVariantModel
@using Nop.Web.Models.Catalog ;
       @*Stock availability*@      
        @Html.Raw(Model.StockAvailablity)      


which does not produce an error.

Then in the  _ProductBox.cshtml

@Html.Partial("_ProductStockLevel", Model.ProductVariantModel)

but @Html.Partial("_ProductStockLevel", Model.ProductVariantModel) gives an error of

'Nop.Web.Models.Catalog.ProductOverviewModel' does not contain a definition for 'ProductVariantModel' and no extension method 'ProductVariantModel' accepting a first argument of type 'Nop.Web.Models.Catalog.ProductOverviewModel' could be found (are you missing a using directive or an assembly reference?)

Thanks
11 years ago
Hi

Its in the Controller.

I'm a novice to to ASP.NET MVC C# the view's are the easy part controller's the hardest.

So far I have the following in bold but It will throw multiple error's throughout the whole Catalog Controller that I'm currently working through


[NonAction]protected ProductModel PrepareProductOverviewModel(Product product, ProductModel.ProductVariantModel productVariant , bool preparePriceModel = true, bool preparePictureModel = true, int? productThumbPictureSize = null)
        {
            if (product == null)
                throw new ArgumentNullException("product");

            var model = product.ToModel();
            //ConcordProductBlock
            model.CCCPack = product.CCCPack;
            model.CCCStockCode = product.CCCStockCode;
            model.CCCRetailPrice = product.CCCRetailPrice;
           model.StockAvailablity = productVariant.StockAvailablity;


Richard
11 years ago
Spire wrote:
Hi

Well I created a partial view as suggested by Creative, but I get the same error as when I tried to use the ProductVariant_SKU_Man_Stock view, being a novice I will post my code in case I have made any glaring errors which someone may see right away.


Creatives code was @model  ProductModel.ProductVariantModel  but that throws an error staright away.

So my view is called _ProductStockLevel with the following code

@model  ProductDetailsModel.ProductVariantModel
@using Nop.Web.Models.Catalog ;
       @*Stock availability*@      
       <div class="stock">
          @T("Products.Availability"): @Model.StockAvailablity
       </div>

I also tried

@model  ProductDetailsModel.ProductVariantModel
@using Nop.Web.Models.Catalog ;
       @*Stock availability*@      
        @Html.Raw(Model.StockAvailablity)      


which does not produce an error.

Then in the  _ProductBox.cshtml

@Html.Partial("_ProductStockLevel", Model.ProductVariantModel)

but @Html.Partial("_ProductStockLevel", Model.ProductVariantModel) gives an error of

'Nop.Web.Models.Catalog.ProductOverviewModel' does not contain a definition for 'ProductVariantModel' and no extension method 'ProductVariantModel' accepting a first argument of type 'Nop.Web.Models.Catalog.ProductOverviewModel' could be found (are you missing a using directive or an assembly reference?)

Thanks


Which version are u using
11 years ago
Hi

Version 2.60


Thanks
11 years ago
Spire wrote:
Hi

Version 2.60


Thanks


The error is coz there is no productvariantmodel in ProductOverviewModel, You need to define all the partial classes within  ProductOverviewModel inorder to use there properties, Currently ProductOverviewModel consist of ProductPriceModel , PictureModel , ProductSpecificationModel And there details are fetched through controller  PrepareProductOverviewModels which is used by view to generate the required details . You have to define partial class in the productoverview model and get the value in controller which can be used by View.
11 years ago
creative3k wrote:

The error is coz there is no productvariantmodel in ProductOverviewModel, You need to define all the partial classes within  ProductOverviewModel inorder to use there properties, Currently ProductOverviewModel consist of ProductPriceModel , PictureModel , ProductSpecificationModel And there details are fetched through controller  PrepareProductOverviewModels which is used by view to generate the required details . You have to define partial class in the productoverview model and get the value in controller which can be used by View.



I had arrived at that conclusion, but was unsure if I was on the correct path, but thank you for confirming I am going the right direction.

It really is a steep learning curve for me as not only am I a MVC novice I am in the VB camp, so C# code is not as easy to read as VB for me.

Thanks
11 years ago
http://msdn.microsoft.com/en-us/library/wa80x488.aspx
11 years ago
Spire wrote:

The error is coz there is no productvariantmodel in ProductOverviewModel, You need to define all the partial classes within  ProductOverviewModel inorder to use there properties, Currently ProductOverviewModel consist of ProductPriceModel , PictureModel , ProductSpecificationModel And there details are fetched through controller  PrepareProductOverviewModels which is used by view to generate the required details . You have to define partial class in the productoverview model and get the value in controller which can be used by View.


I had arrived at that conclusion, but was unsure if I was on the correct path, but thank you for confirming I am going the right direction.

It really is a steep learning curve for me as not only am I a MVC novice I am in the VB camp, so C# code is not as easy to read as VB for me.

Thanks


Just try this, i have not tested it , just a guess :

Add this line to PrepareProductOverviewModels [Nope.WebControllers.CatalogController]

var quantity = productVariant.AllowedQuantities;

after this line
var productVariant = _priceCalculationService.GetProductVariantWithMinimalPrice(productVariants, _workContext.CurrentCustomer, true, int.MaxValue, out minimalPrice); //line248

Now add this line in the ProductOverviewModel
public string quantity { get; set; } it should be included in the partial class
public partial class ProductPriceModel : BaseNopModel

Now call quantity in the _ProductBox.cshtml
like:
@Html.Raw(Model.ProductPrice.quantity)
11 years ago
creative3k wrote:

Just try this, i have not tested it , just a guess :

Add this line to PrepareProductOverviewModels [Nope.WebControllers.CatalogController]

var quantity = productVariant.AllowedQuantities;

after this line
var productVariant = _priceCalculationService.GetProductVariantWithMinimalPrice(productVariants, _workContext.CurrentCustomer, true, int.MaxValue, out minimalPrice); //line248

Now add this line in the ProductOverviewModel
public string quantity { get; set; } it should be included in the partial class
public partial class ProductPriceModel : BaseNopModel

Now call quantity in the _ProductBox.cshtml
like:
@Html.Raw(Model.ProductPrice.quantity)


Hi

Well as you posted the above code I had just worked out that I may be able to get to the Stock Qty by using this line in the productVariant.StockQuantity; at the line in the code u suggested.

However I was still trying to work out how how to get that in to the view, so I followed the code u suggested with a couple of minor changes

priceModel.StockQty = productVariant.StockQuantity; instead of
var quantity = productVariant.AllowedQuantities;

public int StockQty { get; set; } instead of public string quantity { get; set; }

and @Model.ProductPrice.StockQty instead of
@Html.Raw(Model.ProductPrice.quantity)

and it worked :) thank you again for your time and patience, I am begining to learn a little C# and MVC. :)

Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.