hoesman LiteCart Fan من Croatia عضو منذ يونيو 2024 hoesman 18 أغسطس 2024 21:28 I created a shipping module for BoxNow parcel machines, I am trying to insert the widget for picking the location of the parcel machine, I tried putting it in the options fields but it doesnt work the js is not even loaded, I am not sure how to properly implement/where to insert. This is the how to on their website: https://boxnow.hr/diy/widget/developers/ The example 2 would be good for this: https://boxnow.hr/diy/widget/developers/example2
tim Founder من Sweden عضو منذ مايو 2013 tim 18 أغسطس 2024 22:15 Hi. Put your HTML in the "fields" parameter. 'title' => $this->name, 'options' => [ [ 'id' => 'packstation', 'icon' => '', 'name' => language::translate('title_packstation', 'Packstation'), 'description' => '', 'fields' => functions::form_draw_select_field('packstation', $options, @$this->userdata['packstation']) . $javascriptas, 'cost' => $this->settings['fee'], 'tax_class_id' => $this->settings['tax_class_id'], 'exclude_cheapest' => false, ], ], ];``` If the widget does not emulate a hidden input with the picked location you would need to add some scripting. The form would collect any form data that is populated with native input elements. Those later become available in $this->userdata.
hoesman LiteCart Fan من Croatia عضو منذ يونيو 2024 hoesman 19 أغسطس 2024 01:56 Solved, best I could come up with is adding a hidden comment: { $order->data['comments'][] = [ 'text' => 'Chosen locker: '.$this->userdata['boxnow_id'].'', 'hidden' => true, 'notify' => false ]; $order->save(); }```
hoesman LiteCart Fan من Croatia عضو منذ يونيو 2024 hoesman 24 أغسطس 2024 14:50 One more thing, how can I validate that one of the $this->userdata has a value to make sure a location was chosen? Would this be correct way? if(!isset($this->userdata['boxnow_id'])) { return ['error' => 'Choose a locker']; } }```
tim Founder من Sweden عضو منذ مايو 2013 tim 24 أغسطس 2024 15:19 isset() just checks if the variable and value is declared. It doesn't check if it's empty. Try empty() instead. if (empty($this->userdata['boxnow_id'])) { return 'You need to choose a locker'; } }``` validate() is good for this use. Any error returned prevents the ability to checkout.
hoesman LiteCart Fan من Croatia عضو منذ يونيو 2024 hoesman 24 أغسطس 2024 15:37 Good point I always confuse these two, anyways for some reason I get a error but not the right one :) ← ~/includes/templates/default.catalog/views/box_checkout_summary.inc.php (Line 55) in __callstatic() ← ~/includes/entities/ent_view.inc.php (Line 28) in include() ← ~/includes/entities/ent_view.inc.php (Line 33) in {closure}() ← ~/pages/ajax/checkout_summary.inc.php (Line 142) in stitch() ← ~/includes/library/lib_route.inc.php (Line 125) in include() ← ~/index.php (Line 51) in process()``` Edit: I tried it like this and it works but it has the problem that after I choose the locker from the map and it populates the hidden inputs but still shows the error to choose a locker, how would I trigger a revalidate after chosing the locker? ``` public function validate($order) { try { if (empty($this->userdata['boxnow_id'])) throw new Exception(language::translate(__CLASS__.':error_choose_locker', 'You need to choose a locker.')); } catch (Exception $e) { return 'BoxNow: '. $e->getMessage(); } }```
tim Founder من Sweden عضو منذ مايو 2013 tim 27 أغسطس 2024 22:54 Can you attach your module here and I will fiddle with it? If it's not for the eyes of the public you can email it to tim (at) litecart.net.
insha LiteCart Fan من Serbia عضو منذ مارس 2022 insha 12 سبتمبر 2024 23:00 Hello, is your module free for use, i would like to use it or pay for it?
hoesman LiteCart Fan من Croatia عضو منذ يونيو 2024 hoesman 12 سبتمبر 2024 23:27 I plan to add it to the addons here for some price, still discovering all litecart features, but its progressing. Its going to work in all the countries boxnow is present and the prices will adjust based on item sizes/quantity and the volume of lockers, its the classic bin packing problem but dont want any external libraries so wont be completely perfect but still usable. It could also be modified and defined relatively easily for other services and boxes instead of lockers.
insha LiteCart Fan من Serbia عضو منذ مارس 2022 insha 12 سبتمبر 2024 23:39 Ok good thank you, this would be useful.