Rank: Advanced Member
Groups: Authorized User, Developers Joined: 5/30/2020(UTC) Posts: 125
Thanks: 14 times Was thanked: 3 time(s) in 3 post(s)
|
Is there an example somewhere in the codebase of a Widget that sets it's parameters at runtime? We are trying to tie in our inventory system stock status. We want to be able to show it on the product page, cart, and during checkout. In order to show the status, the widget would need the product id and the options selected (if it has options). In the Product Widgets Code:PageHelper.GetProductId()
is used extensively. Based on what I'm seeing, I have this feeling that we will have to copy controller actions and views and create custom "Buy Product Dialog", "Shopping Cart", etc controls for anything related to variants instead of being able to drop in widgets.
|
|
|
|
Rank: Advanced Member
Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System Joined: 10/11/2018(UTC) Posts: 110
Thanks: 19 times Was thanked: 18 time(s) in 18 post(s)
|
Quote:Based on what I'm seeing, I have this feeling that we will have to copy controller actions and views and create custom "Buy Product Dialog", "Shopping Cart", etc controls for anything related to variants instead of being able to drop in widgets. You can create a widget e.g. "InventoryStatus" under the Product category that can be dragged and dropped anywhere on the product page. You can see the ProductName widget as an example. You can also place the same widget at the checkout page. You can use load product options etc. using the product id which is available in context. That is; Code:int productId = PageHelper.GetProductId();
To differentiate between the Product and checkout page, you will have to use the following code: Code:
if (CurrentRequestData.PageData.PageType == PageDataType.Product)
{
//apply product page related logic
}
else
{
//apply checkout page related logic
}
For the basket page, you can override the Views/Checkout/_BasketContents.cshtml view file under your theme and share the existing controller code by adding your logic in there. This is because the widget on the basket page can only be placed at the top (above Shopping Cart header or below the Checkout button. Hope this helps!
|
|
|
|
Rank: Advanced Member
Groups: Authorized User, Developers Joined: 5/30/2020(UTC) Posts: 125
Thanks: 14 times Was thanked: 3 time(s) in 3 post(s)
|
Thanks for responding. The part I'm not sure about is "load product options". I understand I can access the product options/choices by loading the product after getting the product id from the helper. What I'm not sure about is how to get the option choices selected by the user in the Buy form.
Am I using your PageType if/else, then building logic to check for posted fields (selected options)?
You mention overriding view files in my Theme. Can Themes be installed and set to Default as part of a plug-in?
|
|
|
|
Rank: Advanced Member
Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System Joined: 10/11/2018(UTC) Posts: 110
Thanks: 19 times Was thanked: 18 time(s) in 18 post(s)
|
Quote:The part I'm not sure about is "load product options". I understand I can access the product options/choices by loading the product after getting the product id from the helper. What I'm not sure about is how to get the option choices selected by the user in the Buy form. You can save the selected choices dictionary to the session variable inside BuyProductDialog POST action method in ProductContorller.cs file something like this: Code:Session["SelectedOptionChoices"] = selectedOptionChoices;
Then grab the saved dictionary anywhere you want for example, inside _BasketContents action in CheckoutController.cs file like this: Code:
Dictionary<int, int> selectedOptionChoices = (Dictionary<int, int>)Session["SelectedOptionChoices"];
string optionList = _productVariantRepo.GetOptionList(product.Id, selectedOptionChoices, true);
ProductVariant productVariant = _productVariantRepo.LoadForOptionList(product.Id, optionList);
Quote:Am I using your PageType if/else, then building logic to check for posted fields (selected options)? Yes, you can wrap your selection logic inside if/else if needed. Quote:You mention overriding view files in my Theme. Can Themes be installed and set to Default as part of a plug-in? Since the Themes are created and uploaded to the application independently, therefore, there is currently no need to use themes from the plugin interface. That is the reason it isn't currently supported. You can create a copy of the existing theme inside the main Themes folder, rename it and set it as the default theme. You can override views to your custom theme. If you are trying to implement everything using a plugin interface, then it is better to replicate views/controllers, etc. inside the plugin and use it from there.
|
|
|
|
Rank: Advanced Member
Groups: Authorized User, Developers Joined: 5/30/2020(UTC) Posts: 125
Thanks: 14 times Was thanked: 3 time(s) in 3 post(s)
|
Whoa! I just saw some MVC voodoo magic going on as I was digging into this. Noticed the BuyProductDialog action was decorated with some Attributes. The one I found most interesting was [Code.BuyProductDialog.GetChoiceSelections]. Buried in there I can see how you are pulling the selected option choices and kit options from the proceeding form and storing it to ViewData for later use. Going to have to do some experimenting to see if a separate controller/action has access to these details. Push comes to shove, I should be able to re-create it if needed now. Edited by user Thursday, May 19, 2022 1:43:03 PM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Advanced Member
Groups: Administrators, Developers, Registered, HelpDesk, Authorized User, Admin, System Joined: 10/11/2018(UTC) Posts: 110
Thanks: 19 times Was thanked: 18 time(s) in 18 post(s)
|
Yes, the [Code.BuyProductDialog.GetChoiceSelections] attribute on the BuyProductDialog is responsible to return selected choices, kits, etc. This attribute will be available to your custom plugin when you add the AbleCommerce website reference.
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The AbleCommerce Forums uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close