How to add new field to admin customer form in Prestashop 1.6 - prestashop

Good evening,
I want to add new field to admin customer form. There where I can display the customer preferences. Is there any hook ? Or I need to override a controller (which) ?
Kind regards

Alter customer table to add new field
override classes/customer.php to add new definition and variable
override controllers/admin/admincustomercontroller.php
override auth or myaccount on front controller

Related

Which hook I should use to get info about cart after payment in Prestashop 1.6

I create a module. When user bought some product I want to display a special page for him. To do this I need a information about cart after payment. Which hook I should use to this ?
Thanks for help
You can use actionOrderStatusUpdate.
public function hookActionOrderStatusUpdate($params)
{
// You can use $params['newOrderStatus'] or $params['id_order'], i. e.:
$order = new Order((int)$params['id_order']);
if (Validate::isLoadedObject($order) && $order->valid)
{
// The order is paid, you code goes here...
}
}
if you want to redirect the customer to a specific page instead of the standard OrderConfirmation, you can create a module and register/use the hooks displayOrderConfirmation or displayPaymentReturn in which you have the order object as first argument where you can check if the customer bought specific products. You also can override the OrderConfirmationController to modify the standard behaviour (but it's not the best practice).
Good luck

Prestashop 1.6 Create Module to Display Carrier Filter

My Prestashop-based site is currently having an override for AdminOrdersController.php, I have placed it in override folder.
From the link provided below, it is perfectly working fine to add a Carrier filter which is not available in Prestashop 1.6 now. I have tried the solution and it is working perfectly.
Reference: Adding carrier filter in Orders page.
Unfortunately, for production site, I have no access to core files and unable to implement as such. Thus, I will need to create a custom module. Do take note that I already have an override in place for AdminOrdersController.php. I would like to tap on this override and insert the filter.
I have managed to create a module and tried placing an override (with the code provided in the URL) in mymodule/override/controller/admin/AdminOrdersController.php with the carrier filter feature.
There has been no changes/effect, I am baffled. Do I need to generate or copy any .tpl file?
Any guidance is greatly appreciated.
Thank you.
While the answer in the linked question works fine the same thing can be achieved with a module alone (no overrides needed).
Admin controllers have a hook for list fields modifications. There are two with the same name however they have different data in their params array.
actionControllernameListingFieldsModifier executes before a filter is applied to list.
actionControllernameListingFieldsModifier executes before data is pulled from DB and list is rendered.
So you can add fields to existing controller list definition like this in your module file:
public function hookActionAdminOrdersListingFieldsModifier($params) {
if (isset($params['select'])) {
$params['select'] .= ', cr.name';
$params['join'] .= ' LEFT JOIN `'._DB_PREFIX_.'carrier` cr ON (cr.`id_carrier` = a.`id_carrier`)';
}
$params['fields']['carrier'] = array(
'title' => $this->l('Carrier'),
'align' => 'text-center',
'filter_key' => 'cr!name'
);
}
Because array data is being passed into $params array by reference you can modify them in your hook and changes persist back to controller. This will append carrier column at the end of list.
It is prestashop best practice to try and solve problems through module hooks and only if there is really no way to do it with hooks, then do it with overrides.
Did you delete /cache/class_index.php ? You have to if you want your override to take effect.
If it still does not work, maybe you can process with the hook called in the AdminOrderControllers method with your new module.

silverstripe 3 - How to add access control to generated data objects?

Good afternoon,
Please let me know if this question is not clear enough, I'll try my best to make as straight-forward as possible.
How can I add access control to objects that are generated by an end-user using my data object?
Example: I have a class that extends a DataObject. Someone logs in the back-end; fills out the form that's generated by the CMS for the data object. A record is then created in the database by the CMS.
I would like to add an access control to that newly created record in the database.
For a code scenario you can take a look at one of my posts: Silverstripe 3 - Unable to implement controller access security from CMS
The only other way I can think of asking this question is: How to Dynamically (or programmatically) create permissions for records that are created by a DataObject extension via the CMS?
Thanks for your assistance.
Update - Sample Code
///>snippet, note it also has a Manager class that extends ModelAdmin which manages this!
class component extends DataObject implements PermissionProvider{
public static $db = array(
'Title' => 'Varchar',
'Description' => 'Text',
'Status' => "Enum('Hidden, Published', 'Hidden')",
'Weight' => 'Int'
);
///All the regular permission checks (overrides), for the interface goes here, etc...
///That is: canView, canDelete, canEdit, canCreate, providePermissions
}
Now, from the back-end an end-user can add components using the Manager Interface that's generated by extending ModelAdmin. How can I add individual permissions to those added components by the end-user?
Thanks.
Update 2
Example: Add Process Data Object that extends ModelAdmin will give you this in the back end
Then, when you click on the generated 'Add Process' button, you'll get this:
Finally, someone fills out the form and clicks on the 'Create' button, which saves the data in the database. That looks like this:
Now, on that record thats created in MySQL I'd like to add granular permissions to that record. Meaning, for every record created I want to be able to Deny/Allow access to it via a Group/Individual, etc.
Is that even possible with the SilverStripe framework? Thanks.
Implement the functions canView, canEdit, canDelete, and/or canCreate on your DataObject.
Each function will return true or false depending on the conditions you set - any conditions, not just what is defined in the CMS.
See the example code on the tutorial site.

How send unknown number of inputs texts into create action in MVC?

In my Create View, I have a form that the user decides how many objects to add to the database.
Lets say the DB is for a Recipe site, so in add recipe you will have 1 textbox for RecipeName, but the number of ingredients change from one recipe to another, so I let the user add textboxes with Jquery.
now, after the user presses the submit button, I want to manually get the Querystring and order them by the inputbox name.
my question is how do I get the Querystring in the create action?
I tried to use the Request.QueryString[], but it returns null.
thanks in advance,
Nimi
Add a ViewModel class:
public class RecipeViewModel
{
public string ReceipeName {get; set;}
public List<string> ingredients {get; set;}
}
Bind your view to this ViewModel
Now use Jquery/Javascript to give user facility to add ingredients .
I think it's the case to use BeginCollectionItem:
MVC 3 Dynamic Form Using a ViewModel
It is available in NuGet as a package:
https://www.nuget.org/packages/BeginCollectionItem/

Database first - Add controller properties

Here's the thing: I built an app from an existing database. Later some changes were made to the db so I needed to add those fields to my controllers.
I added a few properties to my Users class like so:
public string GHProducts { get; set; }
and then on the View:
#Html.EditorFor(model => model.GHProducts)
I also have some other properties not showing on the form, which I set from the controller in the create new user action. But neither of them is being set when users get created, all registries have NULL values for these manually added properties. So I'm obviously missing something and can't figure out how to bind everything together. I tried the "replace from server" option, but it didn't solve anything. Any ideas?
You probably need to update your edmx file with the database changes.