logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
sweeperqb  
#1 Posted : Thursday, May 19, 2022 12:47:07 AM(UTC)
sweeperqb

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.

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

nadeem  
#2 Posted : Thursday, May 19, 2022 7:17:53 AM(UTC)
nadeem

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!
sweeperqb  
#3 Posted : Thursday, May 19, 2022 8:26:08 AM(UTC)
sweeperqb

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?
nadeem  
#4 Posted : Thursday, May 19, 2022 9:45:12 AM(UTC)
nadeem

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.
sweeperqb  
#5 Posted : Thursday, May 19, 2022 1:42:23 PM(UTC)
sweeperqb

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

nadeem  
#6 Posted : Friday, May 20, 2022 5:06:44 AM(UTC)
nadeem

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.
Users browsing this topic
Guest (3)
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.