Prestashop
I am stuck we one problem for cookie. In prestashop 1.4.7 I create a custom cookie variable using setcookie but when i am try to access and assign it on front-controller, I am not getting cookies set value.
here is my script:
page: checkpostcode.php
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');
global $cookie;
setcookie("is_postcode_checked", 1, time()+600, "/", "", 1); // Set the cookie in basepath
On frontcontroller.php page :
I am access it using $_COOKIE and assign it into smarty array.
'is_postcode_checked' => $_COOKIE['is_postcode_checked'] // Getting null value for cookie
page: checkpostcode.tpl
{$cookie->_get(postcode_checked_msg)} // here get the is_postcode_checked value but
but I am not able to get is_postcode_checked variable value.
In prestashop 1.5, global are deprecated.
To set something in the cookie :
In a controller :
$this->context->cookie->__set($key,$value);
Other file :
$context = Context::getContext();
$context->cookie->__set($finger_print,$result);
You can access to your value with :
In a controller
$this->context->cookie->key
Other file :
$context = Context::getContext();
$context->cookie->key;
You should use Prestashop's own cookie class entirely rather than using the PHP setcookie() function. The class uses the "magic methods" __get(), __set(), __unset() and __isset() which should allow you to do this easily.
Try in your "page" code (not sure how you're executing this since it doesn;t look like an additional page controller):
global $cookie;
$cookie->is_postcode_checked = 1;
$cookie->write(); // I think you'll need this as it doesn't automatically save
...
And in your FrontController override:
global $cookie;
if (isset($cookie->is_postcode_checked))
$is_postcode_checked = $cookie->is_postcode_checked;
else
$is_postcode_checked = 0;
You can assign the variable $is_postcode_checked to a corresponding smarty variable to use in your template.
If you want to fetch the cookie from Prestashop cookie class, you should store it in this class too.
Use die() function in your controller, to find out is that cookie set
It is better, as Paul said, to use only global $cookie class to store and getting data.
Related
I am trying to write some tests for Postman. Many of the requests require an API key that gets returned by an initial GET request.
To set something hard-coded that is not dynamic, it looks like the test code is of the form
let variable = pm.iterationData.get("variable");
console.log("Variable will be set to", variable);
How do I set a return value as a global variable and then set that as a header parameter?
#Example if you setting ApiToken that is dynamic.
Under Tests tab in postman.
Put the following code.
var jsonData = JSON.parse(responseBody);
postman.setEnvironmentVariable("Token", jsonData.token);
Under specific environment put variable name as "Token" and current value will be set automatically.
access the variable using {{variable_name}}
#Example: {{token}}
You can specify that variable value in the request Headers by using the {{var_name}} syntax. Instead of any hardcoded value that you may have been using.
You would previously have had to set the value using the pm.globals.set()syntax.
If you do not have the SDK active (monthly payment required to Postman). You can retrieve the values through __environment and __globals.
//Use of environment
postman.setEnvironmentVariable("my_value", "This is a value");
//...
let myValueVar = postman.__environment["my_value"];
console.log("Variable value is:", myValueVar);
//shows: Variable value is: This is a value
//Use of Globals
postman.setGlobalVariable("my_value2", "This is a value of globals");
//...
let myValueVar2 = postman.__globals["my_value2"];
console.log("Variable value is:", myValueVar2);
//shows: Variable value is: This is a value of globals
Also you can see your globals variables in Environments->Globals of your Posmant client.
how to set validation rule for password in prestashop 1.6.3
I need to add validation for alpha numeric and some validation rules.Currently prestashop by default takes any password without any validation
You can achieve that with a hook actionBeforeSubmitAccount. In that hook you can validate any POST field and pass errors to the controller's error array.
public function hookActionBeforeSubmitAccount()
{
$password = Tools::getValue('passwd');
// some validation logic here
if ($some_validation_failed) {
// Add error to AuthController's errors array
$this->context->controller->errors[] = Tools::displayError('Password validation failed!');
}
}
The AuthController creates an account only if its property $errors array is empty, otherwise it will put you back into account form with errors.
Pretty much every other controller works the same way when it comes to validations.
In file /classes/Validate.php, you will see a function as follows:
public static function isPasswd($passwd, $size = Validate::PASSWORD_LENGTH)
{
return (Tools::strlen($passwd) >= $size && Tools::strlen($passwd) < 255);
}
This function is responsible for the current validation of any password, you can simply modify the same as per your requirements.
I set a session variable inside a controller :
$this->session->set("navig_param",$livc_code);
Now I want to test if that session variable is not empty inside a php file outside of the Controller domain, Model domain and View domain. In fact this file is in a particular folder named lib at the same level as controllers, models and views. So how to test the session variable in this php file ?
You can also access your session data ( statically ) via
$session = Phalcon\Di::getDefault()->get('session');
$navigParam = $session->get('navig_param');
or oneliner:
$navigParam = Phalcon\Di::getDefault()->get('session')->get('navig_param');
reference : phalcon static DI
$di=\Phalcon\DI::getDefault();
$session=$di->getSession();
if($session->has("navig_param"))
{
$navig_param=$session->get("navig_param");
//do something with it like flash it:
$di->getFlash()->success('navig_param is: '.$navig_param);
}
As session is a service you only need an access to DI container:
$navigParam = $di->get('session')->get('navig_param');
Alternatively you can always use $_SESSION super global:
$navigParam = $_SESSION['navig_param'];
To get $di you can use: $di = DI::getDefault();
I should change on zf2 controller a variable global. In practice, I'd like a function to insert the value in the global variable and another function prints the value of the variable. for example:
protected $variablename;
public function setAction()
{
$this->variablename = "hi friends!";
}
public function getAction()
{
var_dump($this->variablename);
}
In this example, when I print the variable I always get NULL.
Any suggestions? tnx
simone
indirectly you can't because of the lifecircle in a zend/php request. after you set up your variable in actionA the variable is reseted if you request actionB
if you want to set your variabel data in actionA and make the data present in actionB you need a persistent save storage (like a db, cookie or session. otherwise it is only possible to forward the current request to another request in your controller. then have a look at the forward controller helper in zend.
http://framework.zend.com/manual/2.3/en/modules/zend.mvc.plugins.html#zend-mvc-controller-plugins-forward
//edit after comment
you can use a session in zend like this
set session
$session = new Zend\Session\Container('base');
$session->offsetSet('someSettings', 'someValue');
get session
$session = new Zend\Session\Container('base');
if( $session->offsetExists('someSettings') )
{
$someSettingValue = $session->offsetGet('someSettings');
}
I'm using the Magento API V2.
When I call salesOrderCreditmemoInfo, I get a response with the credit memo details and a list of the products associated with the order.
But in the list of product items there is no product_type attribute.
I want to manually edit the response to add this attribute.
I tried editing:
app\code\core\Mage\Sales\Model\Order\Creditmemo\Api.php
And replaced:
public function info($creditmemoIncrementId)
{
...
$result['items'] = array();
foreach ($creditmemo->getAllItems() as $item) {
$result['items'][] = $this->_getAttributes($item, 'creditmemo_item');
}
With the following - (basically appending an extra attribute to the array):
public function info($creditmemoIncrementId)
{
...
$result['items'] = array();
foreach ($creditmemo->getAllItems() as $item) {
$product_type = '1'; //test value to check if works
$attribs = $this->_getAttributes($item, 'creditmemo_item');
$attribs['product_type'] = $product_type;
$result['items'][] = $attribs;
}
When I do mage::log($result), the extra attribute seems to be added correctly to the array.
(also indicating that this function is the one getting called)
But it has no impact on the actual API response.
Am I totally looking in the wrong place or is there something else I need to update?
Since You were using SOAP V2, you should update the wsdl.xml to get the output.
For your case it is product_type and refresh cache on server. /tmp to load the new wsdl.xml that already updated. don't forget to go to System -> Cache Management clear all cache.