How to validate and pass component value while add to cart.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 年 前
Hi Community Members,

I am new with nop commerce, and we are planning to migrate our business in nop commerce.

I want to add one Drop Down selection of order type, and when a customer clicks on add to cart button, then the customer needs to select any one value compulsory from the drop-down and I want to pass this in the cart and need to store in database as well. So I can check this order type value in the admin side as well.

Can someone help me with how to do this?

I have created one component (Plugin) which provides order type, but I don't know how to validate this and how to store this in Database as well.

Thanks in advance.
3 年 前
Hi,

Do you want product attributes like below ?

https://demo.nopcommerce.com/adidas-consortium-campus-80s-running-shoes

if yes then It's already there you just need to configure from admin.
below is link to demo for configuration.

https://admin-demo.nopcommerce.com/Admin/Product/Edit/25

Thank you.
3 年 前
HI SuperNopCommerce

Thanks for your reply.

I know how to configure attributes and how to validate them.

We have created one plugin in which we bind dropdown which contains 'RX', 'S0', and 'ST', and this all value binds into dropdown as per customer roles.

So from the plugin I want to validate and want to store into the database.
3 年 前
If you use the built-in product attributes, then it will automatically "store into the database".  On the other hand, if you created a widget using custom dropdown, then you will need to customize how you attach the info to the cart item.
3 年 前
New York is right...it will automatically store into db if you use built in attributes.

Still if you want to validate in your plugin, please try to look in event publisher.

you can get updated shopping cart entity from event publisher.

Please check AddToCart method from ShoppingCartService.cs


Thank you.
3 年 前
Hi New York

Thanks for the reply.

Okay, let's go with Product Attributes. Can you give us some ideas on how to bind product attributes conditionally on the product page as per the below example?

Example:
Order Type Contain thee values RX, SO, and ST.

For some customers, we want to display on RX and ST.
For some customers, we want to display on SO and ST.
For some customers, we want to display only ST.

Can we set this kind of logic?
3 年 前
To do that type of logic based on customer role (or similar) would require customization.  You can probably use an Action Filter to remove items from the dropdown (model).
3 年 前
Hi Newyork,

It is possible for you to provide some code examples for the action filter. How to apply this on product attributes
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.