inserting custom javascript in hikashop

  • Posts: 18
  • Thank you received: 0
11 years 5 months ago #150944

I created an editor to adjust images (javascript based). Now I want it to be able to start that dialog when a button is clicked in the front-end or when "add to cart" is clicked. I am not able to get the javascript or the button working via a Joomla Plugin (like I saw in the documentation). Can someone give some extra information about this?

I put my javascript code in the "on fields load" method of the hikashop plugin.

Please Log in or Create an account to join the conversation.

  • Posts: 12953
  • Thank you received: 1778
11 years 5 months ago #150952

Hello,
In your case, I think that the best solution will probably be to use the "onBeforeCartUpdate" or "onAfterCartUpdate" triggers : www.hikashop.com/support/documentation/i...ml#onAfterCartUpdate

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
11 years 4 months ago #151282

Hi,

that's not really working...
For now:
I override the "onFieldsLoad(&$externalValues)" externalValues method, in which I add the javascript.
When I now go to the product itself (on the client side), the javascript is added (but twice...).
Do you know why the onFieldsLoad is executed twice when loading one product?

The editor can be started when I click the "add to cart" button, but how can I than pass the resulting image to the cart?
(The user chooses an image (size), when he clicks 'add to cart' an image editor will pop up to create the image you want,
when he than clicks on "save", the resulting image (or link to it) should be passed with the product to the cart)

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 4 months ago #151385

Hi,

It's loaded twice because there is "item" and "product" custom fields which are loaded in this page.
So you can add a global variable to see if you already used the javascript or not.

To pass the resulting image to the cart, I think that the easiest way is to create a custom field "item" display it on frontend in the custom fields options, and hide it thanks to css properties. Then when adding the image thanks to your custom code, fill the created custom field with the image path. By this way you will have the image path in the cart.

This kind of custom field is only in the business edition of HikaShop.

If you just need to upload images, why not use the custom fields "Ajax image" ?

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
11 years 4 months ago #151423

I have the business edition.
It's not just uploading an image: the customer can buy images that will be printed on a canvas. To compose that canvas, we have a javascript editor, which can be launched now by the custom field. The result (the canvas that will be bought) will than be added to the hidden input field.
Which type do I override for a custom Item? I know there is hikashopSingledropdown, but is there something like a button or text input field? (I don't find that kind of documentation....)

Please Log in or Create an account to join the conversation.

  • Posts: 84290
  • Thank you received: 13692
  • MODERATOR
11 years 4 months ago #151530

If you want to create a new type of custom fields with your editor, the best will be to use this plugin as an example of what to do as it does exactly that:
hikashop.com/component/hikashop/product/cid-19.html

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
11 years 4 months ago #151794

Thanks :-) I'm progressing now.
The only thing left now is following question:

I added some custom fields in the back-end (i.e. bleed).
So now I have the fields width, height and bleed in the back-end that I can use to configure the type of canvasses.
How can I access those field values and the values of the characteristics through the view (display) of the product.

I override the display() method while I'm extending a hikashop field, but if I do var_dump() on all the input paramaters, I don't see those values popping up. Do I have to query the database for those values? Or do I need to override another method?

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 4 months ago #151817

Hi,

To get custom field values on the product page, you just have to look into the product object.

echo $this->element->CUSTOMFIELDNAME;

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
11 years 4 months ago #153010

$this->element is not set...
I'll try to do the query on my own now.
If I add a custom field in the admin part (article), in which database table can I find the value of that field and how is it linked
to the data (article) displayed on the client side?

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 4 months ago #153017

Hi,

Are you working on a HikaShop view ? or somewhere else ?
If it's HikaShop view you should have the element set , else the table where the custom field values are stored is directly in the product one if the custom field is of the type "product".

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
11 years 4 months ago #153219

I have this plugin (see attachment).
The plugin now has 2 issues:
- when you install it the first time and you want to install it again, it complains that it can't remove article.php (don't know where this comes from....)
- after installation, if you go to custom fields, you can't specify the plugin type (e.g. address, text).
I would expect to see viae-canvas-editor in that drop down.

For now, I know there are already types existing that are providing the stuff I'm trying to do with this plugin, but the idea is to extend the javascript when this plugin is ok.

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 84290
  • Thank you received: 13692
  • MODERATOR
11 years 4 months ago #153221

Hi,

1. That's because you have a file article.php in your zip. Remove it and it should not bother you anymore.

2. The line:

$field->name = 'VIAE-Canvas-Editor';
should be:
$field->name = 'ViaeCanvasEditor';

Please Log in or Create an account to join the conversation.

Time to create page: 0.094 seconds
Powered by Kunena Forum