Prestashop admin orders controller - admin

I would like to ask about this controller.
In past versions like 1.5 I could find it in admin/tabs and add additional functions.
In 1.6 version I can`t find any admin classes files. So I should edit controllers/admin/AdminOrdersController yes?
elseif(isset($_POST['submitInvoice'])){
if ($this->tabAccess['edit'] === '1')
{
mysql_query('UPDATE `'._DB_REFIX_.'orders` SET `invoice_number` = \''.$_POST['invoice_number'].'\',`order_date` = \''.$_POST['order_date'].'\', `changed_invoice`=1, `manager`=\''.$cookie->firstname.' '.$cookie->lastname.'\', `changedStatus`= \''.$_POST['changedStatus'].'\' WHERE `id_order` = '.$_GET['id_order']);
}
}
I add this code to update some values like invoice number or order date. But I can`t to update this. Got same date and number. Is it bad method to update or what?

You should always use modules and hooks to modify PrestaShop logic if possible
If you need to override a function and there is nor suitable hook, you should use overrides: override/controllers/admin/AdminOrderController.php. Contents of this files should look like : AdminOrderController extends AdminOrderControllerCore. If you're unsure what I mean, you should try searching for any override classes in overide folder.
You code is extremely unsafe. You should at least use Db::getInstance()->execute($sql);.
You code might not be working because you are writing you values somewhere in the middle of a function, and the Order is an object, which mean that possibly the Order object is saved after you wrote you values to database. When the order object is saved, it overwrites your values

Related

How figure out methods and properties of jQuery object returned by apex.region(region_static_id).widget() method?

I am using APEX 20.2.0.00.20. apex.region(region_static_id).widget() method should return a jQuery object according to the documentation. I am trying to figure out how to know what the object's properties and methods are, especially when they are not mentioned in the documentation. I tried running apex.region(calendar_region_static_id).widget() to return the object and inspect what properties and methods it has but I got S.fn.init [div#CAL_calendar.fc.ui-widget.fc-ltr, prevObject: S.fn.init(1)] 0: div#CAL_calendar.fc.ui-widget.fc-ltr length: 1 prevObject: S.fn.init [document] __proto__: Object(0)
I did not get the object. I do not know what s.fn.init or the rest of the returned code is?!
I see code like apex.region("calendar_static_id").widget().fullCalendar("getView"), so I assumed I should have gotten the jQuery object which has the "fullCalendar" method and more when I ran apex.region(calendar_region_static_id).widget(), but I have not.
Is this not the right way to inspect a jQuery object's properties and methods?
APEX integrates the FullCalendar widget, but it doesn't duplicate its documentation. Have a look here for a list of the FullCalendar methods and options.
In general, most (interactive) APEX regions are implemented as jQuery UI widgets. That means you can use them like this:
$('selector').widgetName('methodName'); //invokes said method
$('selector').widgetName('methodName', 'param1'); //invokes said method with a parameter
$('selector').widgetName('option', 'optionName'); //gets a specific option
$('selector').widgetName('option', 'optionName', 'newVal'); //sets a specific option
What's more, you can inspect all available options by running:
$('selector').widgetName('option');
And even have a look at the internal object, see all methods, public and otherwise, via:
$('selector').widgetName('instance');
Moreover, via its region interface, APEX offers an even easier way to reach those methods and options, even without having to know a region's widgetName:
// this
$('widgetSelector', 'staticId').widgetName('methodName');
// is equivalent to
apex.region('staticId').widget().widgetName('methodName');
// is quivalent to
apex.region('staticId').call('methodName');
The last way is the shortest and doesn't require knowing the real widget's id or widget name.
All of this helps when dealing with regular APEX widgets, such as the Interactive Grid.
apex.region('emp').call('instance'); //inspects all methods
apex.region('emp').call('option'); //inspects all options
This however does not work on the FullCalendar region, for reasons that are beyond me. It should help you navigate all other APEX regions, but for the FullCalendar you'll have to resort to their API docs.
Hope this helps a bit.

How can I create a custom module to display a calculated value on an already existing page/view?

Trying get started with custom module development on Drupal 8. Don't have previous Drupal dev background. Been reading and watching some materials in the past 2 or so weeks.
I decided to dare doing a little more "complex" other than "Hello World", but I got stuck on how would I actually go about this.
This is what I have so far:
I created a content type for "people". It's very simple, all it has is the person's name and birthdate (date only), so you can use the form to input a few people.
I created a view that displays the list of people, their names and their birthdate. Of course everything so far is using the core admin thing.
Now, I wanted to create a custom module that calculates the person's age (based on the date stored in the DB). It takes today's date, subtracts the person's birthdate, and calculates their age.
Then, with some magic, it returns the age to the render/page output and now this calculated value (the age) will be displayed on the view as well along with the person's name and birthdate.
I assume I would need to "hook into" a place somewhere, where the list of people is returned from the database. Then I loop through the data, get the birthdate, calculate the age, stick the result (age) back into the data, and then the page/view will display this - somehow.
Of course I am already stuck on how would I go about doing this? Where would I need to hook into? With what API? And then of course, I created a view already, but the view doesn't have the "age" field - since that is calculated on the fly. So where and how would I display it?
So many questions...
If anyone would know some tutorial that is similar to this, I'd appreciate it. It's kinda tough getting started with the "custom" side of Drupal.
Thanks for some tips!
without custom programming
You can actually do this without custom coding. For this you can I would use either of the following modules field_token_value or computed_field.
They both create a field without giving the user a textbox to input any value.
The value of such fields are calculated from predefined rules/custom coding/tokens defined per field.
from your custom theme
The easiest way is to do this on the theming layer and not store this value in the database. You have to use hook_preprocess_node in your THEMENAME.theme
function THEMENAME_preprocess_node(&$variables){
//install debug and kint to be able to use
//kint($variables);
$node = $variables["node"];
if($node->getType() == "CONTENTTYPE" && $node->hasField('field_date')){
//get date value something like "2018-09-07T21:35:30"
$date = $node->field_date->value;
//your logic and age calculations
// ...
$age = 35;
//set variable to use in node.html.twig based templates
$variables["person_age"] = $age;
}
}
In order to get more information on what is available install debug module and enable kint (which is part of debug) to be able to see variables using kint function
Than copy node.html.twig from your custom theme (or parent theme or classy core theme) to your THEMENAME/templates folder and rename it node--CONTENTTYPE.html.twig.
In there you can include the variable you just created in proprocess.
person age: {{ person_age }}
Make sure you clear the cache for all those changes to be seen by Drupal.
FOR MORE INFO
To find out what twig templates to override see here
More on twig and getting available variables
Getting more info on which twig template is used can also be obtained by enabling debug mode on previous link.
I would suggest you pick up a book on drupal development to understand all those concepts in a more concrete way.

Odoo v7 to v8 translation

I am converting OpenERP code from version 7 to version 8 and I have come across a weird structure. In version 7 we can use fields, function and one of the attributes is store. The store function allows current field to be updated when fields of other objects are changed.
In the new API, the store function only accepts 'True' or 'False'. I was wondering if I have inherit other models and modify their fields so they perform a value update of model in question using "onchange"
Nope, in Odoo 8 store function is working fine. you can search add-ons and find some interesting examples, Understand from it.
Some example I found in online
[http://www.odoo.yenthevg.com/saving-and-resizing-images-in-odoo-8/]
go through it.
In v8 their is no fields.function field and with that we also do not need store with fields pararms, but you can achieve same thing very easily by using [#depends][1] decorator , which does same thing as store with field does.
```
#openerp.api.depends(*args)
Return a decorator that specifies the field dependencies of a "compute" method (for new-style function fields).
```
so you can say that you field to be calculated on change of some field change.

Ember-Model init issue

I concatinate my application code from multiple js files into one js file. Therefore I can't control the order, and to be honest would not want to. To specify a custom adapter with ember-model you need to create an instance of it like so:
App.User.adapter = Ember.CustomAdapter.create();
So if the CustomAdapter's code appears after the above statement I get the [Uncaught TypeError: Cannot call method 'create' of undefined] error.
App.User.adapter = App.CustomAdapter.create();
App.CustomAdapter = Ember.Adapter.extend({
// custom
});
Is there a way around this?
The order of code loading is very, very important. That's just a fact of life. You need to either figure out how to make your current tool load things in the order that you want, or you need a new tool.

SOAP - Why do I need to query for the original values for an update?

I'm taking over a project and wanted to understand if this is common practice using SOAP. The process that is currently in place I have to query all the values before I do an update cause I need to pass back all the values that are not being updated. Does this sound right?
Example Values:
fname=phill
lname=pafford
address=123 main
phone:222-555-1212
So if I just wanted to update the phone number I need to query for the record, get all the values and submit these values for an update.
Example Update Values:
fname=phill
lname=pafford
address=123 main
phone:111-555-1212
I just want to know if this is common practice or should I change the functionality of this?
This is not specific to SOAP. It may simply be how the service is designed. In general, there will be fields that can only be updated if you have the original value: you can't add one to a field unless you know the original value, for instance. The service seems to have been designed for the general case.
I don't think that it is a very "common" practice. However I've seen cases where the old values are posted together with the new values, in order to validate that noone else has updated the values in the meantime.