- Posts: 221
- Thank you received: 8
Create plugin to add more field to restriction section of product
i need to add some restriction to purchase a product. for example if he do not complete some part of a course in other website out of joomla context, then he can not purchase this product. simply i need to add some additional dropdown field to render all part of each course and select multiple section of that course. i need to use php to user curl and api to ask from other site to verify this user complete or not some part of that course. can you advise me?
thank you.
if it is possible create some new field through hika Custom Field , it is enough for me, but i can not see can use php in new custom field and it seems only can use MySQL query tab in new field. also i need show my additional field in somewhere for admin or vendor for example RESTRICTIONS AND DIMENSIONS.
thank you again.
Please Log in or Create an account to join the conversation.
I think the best would be to create a plugin of the group "hikashop" and implement two events:
- First, the event onAfterCheckCartQuantities(&$cart, &$parent_products, &$ret) is called when the cart is being loaded. In it, you can loop on the products array in $cart->products and set the cart_product_quantity to 0 for a product if you want to remove it from the cart. You can also add an entry to $cart->messages to set an error message to be displayed to the user like this:
- Second, the event onBeforeProductQuantityCheck(&$products, &$cart, &$options) is called when a product is being added to the cart. In the $products array you can set the 'qty' array entry to 0 for each sub array to cancel the add to cart for the corresponding product (several products can be added at once in some cases). And you can use the code below to set the error message:
Please Log in or Create an account to join the conversation.
is it possible advise about how to create additional customized php calculator field in RESTRICTIONS AND DIMENSIONS.
i want give something via api from other website and show it in dropdown.my field need search feature like that you have in payment method plugin to ajax search in product list. and is there any sample plugin?
Please Log in or Create an account to join the conversation.
You can do something like that to display a search field like that:
$value contains the current value (several values separated by a comma
$values contains an array of values to be selected along with their keys (the keys will be saved in the database, the values will be displayed to the user)
You could add that in product / form for your backend template via the menu Display>Views. You'll want to have in $map something like that:
Please Log in or Create an account to join the conversation.
thank you nicolas.nicolas wrote: Hi,
You could add that in product / form for your backend template via the menu Display>Views. You'll want to have in $map something like that:Code:data[product][xxx]nicolas wrote: where xxx is the column of the hikashop_product table where you want the data to be stored.
is it possible implement this piece of code in plugin structure?
and excuse me for more toil. i have some course that has some activity in that course. it meens nested structure. and figure out if i have more than 1000 course and each of them has some activity in that course, is it posibble load step by step means in the first step load course title and when click on the course title in second step load all activity in that course. by this way it is loaded less dom element in the first step. or can you say me it is better or not to create related drop down fields , when user select in the first field then the second field load activity of the selected course in the first field.
Please Log in or Create an account to join the conversation.
Yes. To add that code to the product edit form from a plugin, you want to implement the event onProductFormDisplay(&$product, &$html) and you can add your HTML as a new entry in $html.
Note however that in that case, you can't choose the location of your HTML. It will be in the "Fields" section, after the custom product fields. That's why I was recommending a view override sine you wanted to place it elsewhere in the interface.
To load the search field dynamically, like we have in some places, it's possible, but much more complex.
First, you need to implement the event onNameboxTypesLoad(&$loaded_types) to add your own type of search field. That way, instead of "rawlist" you can use that type.
Here is an example I made for a custom development to get a search field to select users:
Then, you also need to implement the event onHikashopPluginController($ctrl) in order to add your own controller to HikaShop, like so:
This function actually uses the getNameboxData function of administrator/components/com_hikashop/classes/user.php
So you'll have to adapt all this to your needs. You're in for at least several hours of work.
I think it's quite complex for a marginal gain. I would recommend you to stick with the code I gave in my previous message. Loading a few thousand elements in a Javascript array is not a problem.
Please Log in or Create an account to join the conversation.
i create a plugin to add field in the restriction but i have two problem:
1- when i remove the options from our example field in the product restriction, it can not set a default option. for example i select some option from dropdown of that field after plugin install and the create manually a field with the name "moojla_courses" with my own type. how to resolve this problem? if you don't understand my mean please see the video:
app.screencast.com/E6HTJzVDbc0mT
2- how to use return in moojla_course_completed_restriction_class.php line:83 ?
we use echo in line70 . the return not work according that you, is it possible advise me?
please see and install the attached extension. thank you
this plugin want to restrict buy a product until he complete some course.
Please Log in or Create an account to join the conversation.
1. I'm not sure why it does that and doesn't remove the last element selected in the field. However, I thing which could be problematic is the __construct function you have in your code. You don't call the parent class function. Because of that it's missing several pieces and the field won't work properly in some cases. So it might be linked. Please either remove the __construct function in your code or call the parent class __construct in it.
2. Change the "echo" on line 70 to "return" and that's it.
Please Log in or Create an account to join the conversation.