How to use actionValidateCustomerAddressForm hook to get the address of customer - prestashop

How to use actionValidateCustomerAddressForm, during runtime of address update details

In the actionValidateCustomerAddressForm you will get the whole address form as parameter.
public function hookActionValidateCustomerAddressForm($params){
$addressForm = $params['form'];
// do the stuff
}
Of course, you can use the hook only in a module. For generating a basic custom module, check the https://validator.prestashop.com/

Related

How do I call a FrontController from within a module

I implemented a Prestashop module for Payment
beside of my main Module I generated a ModuleFrontController , which work fine and I have access on it by using URL like mydomain.com/module/controllers/mymethod
The problem is I would like to execute this method from my main module class / a simple php file
But I can not find a solution for that yet.
Note :
I Can not use CURL / open_socket
I can not call this URL from an Ajax
Simply I want to make an instance of my FrontController and call a method
Any Idea?
Thx
Include that controller file where you want to use and create instance of class and call desired method on that
FrontController define like this :
class ModulenameControllernameModuleFrontController extends ModuleFrontController
{
...
}
and make didn't accept like normal instance to call $obj = new Classname()
,... or when some how make an instance , wasn't work well. was missing some parameters in $this->context->XXX
Any way my problem solve some have different without need to make an instance .
But I think should be another way like how Cron execute
Ex. for Cron can send parameter like :
$_GET['fc'] = 'module';
$_GET['module'] = 'modulename';
$_GET['controller'] = 'controllername';
,....
Some how to call FrontController , independently

Prestashop 1.7 How to Display data from database to tpl

i'm new on Prestashop, i have a little problem on prestashop 1.7, i just bought a module for my orders, on the page of details when i launch smarty i can see the array $order_reference with some information, but when i go to the page of my history i can't access to this information, i don't know how to add this information to access it with my page history, do i have to create a function on history controller or class with dbclass or do u have any others solutions to add my details information of my order ?
The problem is my information is in a another table who call eo_orderreference and i can't access to it with my orders object. I think i need to write a function but as i see on internet it is wrong to write it on a tpl file, i have to do it on my class but i don't know how.
This is the information i want to add
SELECT 'order_reference' FROM eo_orderreference
Sorry i can't upload image because it contains sensible informations.
Thank for your time.
Smarty templates are meant to display data,
you should perform your query in the PHP file that recall your TPL and then use the Prestashop
assign()
method to return data to your TPL as smarty variables that you can show at front office.
See here for more details.
you can create the sql query within a function either within a module or a controller.
For example:
public function getAccessories($id_product)
{
// Your code
}
into a hook or initcontent, you can call the function on the query sql and assign it a template:
public function hookDiplayAccessoryExtraProduct($params)
{
$accessories = $this->getAccessories((int)$params['id_product']);
$this->context->smarty->assign(array(
'accessories_custom' => $accessories,
)
);
return $this->display(__FILE__, 'views/templates/front/accessory.tpl');
}

Laravel scope not responding

I am using laravel for my backend api.
My question is about an scopefilter, the problem is that it is not responding when I call to it.
I have a lot of examples for using scopefilters.
So I looked at each of them to see if I did something wrong.
But I can't seem to find the problem.
When I call to this model in laravel, I use a parameter to define too the scopefilter to use a specific function.
The point only is that it never gets to this function, I don't get a response when I have put a log in this function.
I assume it is a syntax problem but maybe someone else can find the problem for this.
public static $scopeFilters = [
"supplierArticleClientId" => "bySupplierArticleClientId"
];
public function scopeBySupplierArticleClientId($query, $clientId) {
\Log::info([$clientId]);
}
In this case I expect that I see an clientId in my log.
You have to create a Custom validation function Implementing Rule Class
please go through this link for reference

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

Sending more data to changeIdentity in CWebUser by overriding it?

Disclaimer: Complete beginner in Yii, Some experience in php.
In Yii, Is it OK to override the login method of CWebUser?
The reason i want to do this is because the comments in the source code stated that the changeIdentity method can be overridden by child classes but because i want to send more parameters to this method i was thinking of overriding the login method too (of CWebUser).
Also if that isn't such a good idea how do you send the extra parameters into the changeIdentity method.(By retrieving it from the $states argument somehow ??). The extra parameters are newly defined properties of UserIdentity class.
It is better to first try to do what you wish to do by overriding components/UserIdentity.php's authenticate method. In fact, that is necessary to implement any security system more advanced than the default demo and admin logins it starts you with.
In that method, you can use
$this->setState('myVar', 5);
and then access that anywhere in the web app like so:
Yii::app()->user->getState('myVar');
If myVar is not defined, that method will return null by default. Otherwise it will return whatever it was stored as, in my example, 5. These values are stored in the $_SESSION variable, so they persist as long as the session does.
UPDATE: Okay, took the time to learn how this whole mess works in Yii for another answer, so I'm sharing my findings here as well. The below is mostly copy pasted from a similar answer I just gave elsewhere. This is tested as working and persisting from page to page on my system.
You need to extend the CWebUser class to achieve the results you want.
class WebUser extends CWebUser{
protected $_myVar = 'myvar_default';
public function getMyVar(){
$myVar = Yii::app()->user->getState('myVar');
return (null!==$myVar)?$myVar:$this->_myVar;
}
public function setMyVar($value){
Yii::app()->user->setState('myVar', $value);
}
}
You can then assign and recall the myVar attribute by using Yii::app()->user->myVar.
Place the above class in components/WebUser.php, or anywhere that it will be loaded or autoloaded.
Change your config file to use your new WebUser class and you should be all set.
'components'=>
'user'=>array(
'class'=>'WebUser',
),
...
),