Overriding paypal module template files in prestashop - templates

I've been creating a theme for prestashop and found out pretty early on that you could override module templates by creating a folder in myTheme/modules/modulename and then put the overriding templates in there, however, when I try and do this for the paypal module the overriden template file does not get used.
Have any other prestashop users had this problem in the past and if so how have you fixed it? Thanks in advance.

I was having a similar problem because I was copying the files from modules I wanted to override into my theme directory and deleting those I wasn't overriding.
However, PayPal's module is several levels deep. You can't leave the files where they are, they need to be in the root of the override dir.
Para example, to override express_checkout_payment.tpl:
Copy /app/modules/paypal/views/templates/hook/express_checkout_payment.tpl
to /app/themes/han/modules/paypal/express_checkout_payment.tpl

I have the same problem and found a workaround on prestashop forums.
It implies to modify the paypal module code, it's not a perfect solution, but it works...

Related

Namespacing Rails models. How should this be done and what's the best syntax for calling the namespaced models?

Let's assume we have a very large codebase and want to namespace a group of functionally-related code under a folder structure. Say we have a bunch of files related to Admin so we create an app/models/admin folder and place files like admin.rb and admin_accounts.rb under the models/admin folder.
Questions:
1. Do these classes now need to be wrapped in an admin module or does Rails do this for us automatically?
2. When creating a new admin, is there a way for us to not have to call it like Admin::Admin.rb or Admin::AdminAccount.new. The call sites range in the 100s. Do we have to change each call site to reference the wrapping module now? Or is there a way around this with the autoload feature?
In short, what's best practice? Do we now need to wrap the classes in a module? IF so, does that mean we now need to preface Admin.new and AdminAccount with the module? Is this necessary?

Moving admin-related files out of their models and controller folders and into a separate admin folder in Rails. How to organize this code?

I am working on a legacy app with 100s of related admin models, controllers, services, jobs, etc. We decided to move all of these files in a folder at the top-level of the app directory called admin. So our ideal file structure would be:
app/admin/models/admin.rb
app/admin/controllers/admin_controller.rb
app/admin/services/admin_service_of_some_kind.rb
app/admin/models/audit.rb
etc
We want the call sites in our code to be:
Admin::Admin.create...
Admin::AdminService.retrieve_all_audit_logs...
Admin::Audit.scope_by_admin...
etc
The problem is that after reading these links:
http://urbanautomaton.com/blog/2013/08/27/rails-autoloading-hell/
http://guides.rubyonrails.org/autoloading_and_reloading_constants.html
I understand that Rails infers file path names from the constants. So if I want to call Admin::AdminService.some_task... Rails will believe the Admin constant and the nested AdminService constant would exist in a file at (assuming that app/admin is autoloaded... which I believe it is) app/admin/admin_service.rb which is not true... they exist in app/admin/services/admin_service.rb.
How can I make this happen given that I want the call site to be Admin::AdminService.some_task?
Given the folder structure of app/admin/services/admin_service.rb, the call site would have to be Services::AdminService.some_task right? (this assumes that app/admin is autoloaded) right? However, this is not what I want.
Why not just move them into
app/models/admin/*.rb
app/services/admin/*.rb

Helpers in Rails 4

I make an application writed in Rails, it's growing fast and I learning with it. But I'm don't understand about helpers.
application_helper.rb
module ApplicationHelper
# This file it's empty
end
users_helper.rb
module UsersHelper
def avatar
# Do something
end
end
customer_helper.rb
module CustomerHelper
# This file it's empty
end
Why in any customer's view can call avatar helper method on user helper module?
Then, why separate helpers in many files?
Thanks in advance.
P.S: Rails' version 4.
Because all helpers are included in all controllers, by default. The separate files are really just for logical separation in this scenario. You can change that behaviour though:
By default, each controller will include all helpers.
In previous versions of Rails the controller will include a helper
whose name matches that of the controller, e.g., MyController will
automatically include MyHelper. To return old behavior set
config.action_controller.include_all_helpers to false.
http://api.rubyonrails.org/classes/ActionController/Helpers.html
To add to Mike Campbell's answer:
Framework
As magic as it is, Rails is a set of files which are called
sequentially
These files hold classes, methods, etc; but they're still files.
And that means that when you run an action through Rails, it loads up
a series of other dependent files to help it run (that's what a
framework is)
The design of Rails is such that your helper methods are all
loaded each time you run an action. I don't know why, but it helps
administer the methods for different areas of your app
So to answer your question, there's no real reason why the helpers are split up, at least with Rails 4

how to pre-compile templates with knockout?

from the sample/tutorials of knockout, all view/templates are in one page, is it possible to separate them in different files and pre-compile them. just like what ember framework do.
if yes, is there a sample ? better using handlebars or knockout native template engine.
thanks.
The guys from Cassette have found a solution to pre-compile Knockout JS templates: http://getcassette.net/documentation/v1/html-templates/knockoutjs-jquery-tmpl
But Cassette is an asset to build .NET web apps so this solution seems to work only for the .NET world.
There are a few different libraries for this, like
https://github.com/ifandelse/Knockout.js-External-Template-Engine
I have made my own too which uses a Convention approach
https://github.com/AndersMalmgren/Knockout.Bootstrap
Install-Package Knockout.Bootstrap
It needs a service to get the templates, once that is done you load templates like
this.bootstrap.loadView(model, this.view);
By convention if the model is sent in is named EditOrderViewModel it will load the View named EditOrderView
wiki
https://github.com/AndersMalmgren/Knockout.Bootstrap/wiki

Multiple Grails scaffolding templates in one application

I'm creating a DB web application with grails for my company and found myself in the need to change the default scaffolding templates.
So far so good, everything gets generated with the modified templates (controllers, views, ..).
Now, however, I get a request to create some "composite screens" with functionalities and a layout that differ from the overwritten templates.
So now my question is: is it possible in grails to create one or more templates (next the the default one) and pass this template name as an argument to the generate-* commands?
Thanks in advance!
EDIT: Adding the template name to the generate commands was just an idea, if it's possible to do this a different way, I'll be happy too.
Grails commands are scripts in grails/scripts. If you follow its logic you will see two things.
1) There is only one parameter passed to the script → domain.
2) Class for generating views is DefaultGrailsTemplateGenerator. You can analyse sourcecode and check what this class offers.
Update
Link to DefaultGrailsTemplateGenerator in GitHub.
I am not sure about the generate command parameters, but if you add another .gsp page into scaffolding directory, I believe it will try to run it through generation process.
So for example I used to have a show.gsp page as well as showBasic.gsp page, which showed fewer properties.