Post by geniusroi » Sat May 26, 2018 9:09 pm

I need to change the price dynamically in my website based on the option selected.
(Example: http://www.hejazoud.net/index.php?route ... uct_id=394)

I tried multiple extensions like this one (Ajax Live Options) but nothing work.

Is there any extension or code to fulfil this?

Does using a theme different from the default one affect this? If so, do I need to change anything?

OpenCart version: 2.2.0.0

Newbie

Posts

Joined
Sun Mar 26, 2017 8:29 pm

Post by yodapt » Sat May 26, 2018 9:24 pm

geniusroi wrote:
Sat May 26, 2018 9:09 pm
Does using a theme different from the default one affect this? If so, do I need to change anything?
It might depending on the theme. It's hard to tell what needs to be changed, as it might also interfere with other extensions. PM me if you need commercial assistance.

Opencart Developer - My Extension Showcase
Contact me at aeon.yoda@gmail.com


User avatar
Active Member

Posts

Joined
Fri Jun 17, 2011 6:39 pm


Post by IP_CAM » Sun May 27, 2018 7:36 am

It's one of the most difficult OC-Extension, as fas as I found out.
I had only one of the Mods working in one of my test designs a
while ago, but never was able to make it work again in other Layouts.
It's probably the script, wich somehow collides with other routines.
So I delayed this so easy looking function, until everthing else works
as planned. So, you're not alone... :D
Ernie

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by geniusroi » Sun May 27, 2018 11:09 pm

I wrote this solution using jquery, which might not be ideal, but I think it works regardless of version and template changes.

Code: Select all

<script type="text/javascript">

$( "select" )
  .change(function() {
    var str = "";
    $( "select option:selected" ).each(function() {
      str =str.substring(str.lastIndexOf("(")+1,str.lastIndexOf(")"));
      str += " السعر:" + $( this ).text().split('(').pop().split(')').shift() + "ريال";
    });
    $( ".special-price" ).text( str );
  })
  .trigger( "change" );
</script>

</script>

I hope it helps other people who wants to achieve this result.

Newbie

Posts

Joined
Sun Mar 26, 2017 8:29 pm

Post by IP_CAM » Mon May 28, 2018 12:50 am

well, possibly after one finds out, what those two funny words mean ... :laugh:

Code: Select all

str += " السعر:" + $( this ).text().split('(').pop().split(')').shift() + "ريال";

My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.


User avatar
Legendary Member

Posts

Joined
Tue Mar 04, 2014 1:37 am
Location - Switzerland

Post by geniusroi » Mon May 28, 2018 5:10 pm

IP_CAM wrote:
Mon May 28, 2018 12:50 am
well, possibly after one finds out, what those two funny words mean ... :laugh:

Code: Select all

str += " السعر:" + $( this ).text().split('(').pop().split(')').shift() + "ريال";
"Price" and "Riyal" in Arabic, but you can change them with any words or symbols.

Newbie

Posts

Joined
Sun Mar 26, 2017 8:29 pm

Post by Scooteruk » Wed Jan 01, 2020 7:23 am

Hi, I am running the latest OC version and struggling to get this to work (i.e. dynamically update price upon selecting various options).
Where does your jquery code go? I would really appreciate some guidance.
I had some experience with opencart many years ago and now I have come back to it after many years and it seems that sadly opencart is now dying as there is hardly any new support. All these issues have been there for about 10+ years and you would think that developers would have integrated them by now!
I would be grateful for any help in this matter.

Newbie

Posts

Joined
Sat Dec 21, 2019 11:04 pm

User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by Scooteruk » Wed Jan 01, 2020 6:47 pm

The one you have mentioned does not work with the latest version (3.0.3.2) unless I am missing something

Newbie

Posts

Joined
Sat Dec 21, 2019 11:04 pm

Post by xxvirusxx » Wed Jan 01, 2020 7:15 pm

On Default theme work just fine.

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by Scooteruk » Wed Jan 01, 2020 7:35 pm

I am using default theme. I installed using extensions /installer, then I enabled it under extensions/ modules. Everything seems fine with no error messages and yet the price is not dynamically updated. I even made a new test product but to no avail. My config.php also has addresses as https I also cleared cache.
I also have a parallel default installation (just for testing) and it does not even work there (on basic default clean installation of 3.0.3.2)
Is there anything I am missing apart from doing the steps I have mentioned here.

Newbie

Posts

Joined
Sat Dec 21, 2019 11:04 pm

Post by straightlight » Wed Jan 01, 2020 11:05 pm

I have already reported this type of coding issue on Github in the past. Using exit with PHP can be tolerated on most servers but other ones that cannot while using a session. Besides, calling Ajax straight from a controller by using << HTML pointers can lead to XSS vulnerabilities. While the code structure may not be the worst I've seen so far, as it is free-of-use from the Marketplace, it still may require adjustments to be opted for all servers.

The developer did not really bothered of using the same methodology as the one already used from the admin - > systems - > settings - > add / edit settings when switching theme thumbnails. It's the identical functionality that should of been used with this extension in order to make the calls.

In addition, discounts doesn't need to be recalled as the $this->cart object can already pull that in. A second parameter is required? Simply use the $this->cart object to pass it as the first argument or even straight into the custom method name. It's only common sense. There's no need for redundant codes.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Wed Jan 01, 2020 11:27 pm

Also by looking on the admin side of the extension, the module_ prefix has been added on recent OC v3.x releases as compared to prior versions. Previous releases do not have this specific prefix and make cause settings not to be saved properly from the OC admin's extension page. Lastly, and hopefully, using JSON headers within the index() method is not in the best practices ...

Using md5 algorithm to handle cache is no longer the favored method. sha1 should, at least, be used.

options makeup in the controller should not be hard coded but rather be set in the target TWIG file.

Method names should not be used with underscores. Not that it would create problematic based on its functionality but using the same conventions as instanced variable names can be misleading as it may take longer to troubleshoot an issue. In addition, Opencart already uses that example when loading method names with the right convention names.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Wed Jan 01, 2020 11:57 pm

// you can add smth useful here
showing in the controller does not provide a non-technical user on how to add TWIG codes into a controller which is another reason why the JS code should rather be added into a TWIG file as Opencart settings already demonstrates. Otherwise, a non-technical user might never notice those instructions even exist.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by Scooteruk » Thu Jan 02, 2020 12:27 am

And what is the point of you adding 3 replies here - apart from impressing everyone that you have infinite knowledge on this subject but not helping someone with less knowledge than you to debug and fix the problem?
Please can you let someone else who has faced similar problem as me and fixed it answer my query. I appreciate your comments. Regards

Newbie

Posts

Joined
Sat Dec 21, 2019 11:04 pm

Post by straightlight » Thu Jan 02, 2020 12:30 am

Scooteruk wrote:
Thu Jan 02, 2020 12:27 am
And what is the point of you adding 3 replies here - apart from impressing everyone that you have infinite knowledge on this subject but not helping someone with less knowledge than you to debug and fix the problem?
Please can you let someone else who has faced similar problem as me and fixed it answer my query. I appreciate your comments. Regards
You want an extension to be fixed? Contact the extension developer or submit a new service request in the Commercial Support section of the forum as per the forum rules.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 148 guests