How to make a field required for customers but not for administrators in prestashop? - prestashop

I made a custom field in prestashop.
I would like to know if there is some way to make this field only required on the frontend and not for administrators.
this is my code in Customer class
array('type' => self::TYPE_STRING, 'required' => true, 'size' => 64),
Thanks in advance

Can't think of a quick way to make this possible exactly as you want it, so here are two suggestions:
1 - Remove the 'required' => true from the definition and create some kind of custom validation like if (Tools::getValue('type ') == "") { return false; } in an override of the front office AuthController (Warning: code is completely untested and should definitely be improved, also according to your particular PS version).
2 - Use frontend validation by giving the frontend form field the required attribute (you should do this even if oyu use 1)

Related

Prestashop - Multi Shop Associations - Missing Group name

Im making a multi shop module, the module saves / adds to the modules shop tables etc.
This part is fine.
I just have an issue with the GUI its missing the Group names, to me it looks like I'm missing something for a sprintf() I just see the %s and not the group name.
The image shows what I mean.
In my renderform function I have added.
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'shop',
'label' => $this->l('Shop association'),
'name' => 'checkBoxShopAsso',
'values' => Shop::getTree()
);
}
I wonder do i need to add anything else? all of the other modules I have look fine.
Thanks.
** Updated **
Have just found the template, it is the sprintf() that is not working because if i relace the line it works fine.
{*<label class="tree-toggler">{l s='Group: %s' sprintf=$node['name']}</label>*}
<label class="tree-toggler">{$node['name']}</label>
Any Ideas?
Thanks.

How to remove validation on a Select Element in Zend Framework 2

I wanted to bypass the annoying validation for the Select Element in Zend Framework 2. My requirement is that I have two select drop down boxes where I pass the values from the left select box to right select box and finally when I click the submit button, I post the values from right select box.
So basically the left select box is there to show the values to the user, my problem is that in the left select box as no value is selected it throws this error:
["selectAll"] => array(1) {
["isEmpty"] => string(36) "Value is required and can't be empty"
}
I have seen some old posts from Stackoverflow, where this is possible in Zend Framework 1 like one can disable the validation for the particular select element´
Examples:-
$selectAllElement->setRequired(false);
or
$selectAllElement->removeDecorator('Errors');
which some how these methods are not available in Zend Framework 2. In case if somebody has a solution of how disable the validation for a particular select element, please do share your knowledge, will be hepful for people getting into Zend Framework 2.
EDIT:
In my Form-
$select = new Element\Select('selectAllElement');
$select->setAttribute('title', 'Select a Value')
->setAttribute('id', 'id');
$options = array(
array(
//Fetching the values from database
),
);
$select->setAttribute('multiple', 'multiple')
->setAttribute('required', false)
->setValueOptions($options);
$this->add($select);
As per request from Sam, I have provided the code how I am adding the select element to my form and setting the attributes.
NOTE: I am not using any FIELDSETS
To clarify this as an answer, using the setRequired()-Method on any Zend\Form\Element only declares if the HTML-Attribute required="(bool)" should be rendered or not.
If you want to exclude a Field/Element from Validation you need to define this inside your InputFilters setting 'required' => false
Sometimes with me, the setRequired(false) not works when working with select multiple or checkbox that is not in the view, and so, i just override the isValid method and remove the validator as the code above:
public function isValid() {
$this->getInputFilter()->remove('alterarsenha');
$this->getInputFilter()->remove('usuario_perfis');
return parent::isValid();
}
I know this topic is most probably very outdated, but still maybe one consider this as useful.
In version of zf2 which I'm using there is a bug in class Zend\Form\Element\Select, this class provides InputProviderInterface, especially method getInputSpecification(), in this method option
$spec = array(
'name' => $this->getName(),
'required' => true,
);
So if you redefine method getInputSpecification it should works.

Yii recognise timestamp column

I'm using giix to extend model (and crud) behavior. In this I would like to handle columns of type timestamp (that already exist in my model) specifically, rather like autoincrement fields are handled. (Ignored and not shown, that is.) However, there is no property $column->isTimestamp. I would like to add this somewhere, but I'm rather at loss what the best place for this would be. Do I put it in giix somewhere, or do I have to extend the column-baseclass?
Edit: I want to ignore them from every view, for every table. Since this is a lot of work, and it's something I always want, I'd like to automate it. Adapting the generators seems to make most sense, but I'm not sure what the best way to do it would be.
Here is the process:
Extend your database schema, if you are on MySQL it is CMysqlSchema.
Extend CMysqlColumnSchema and add a "isTimestamp" attribute.
In your CMysqlSchema sub-class extend createColumn and test for a timestamp, you'll see that Yii makes simple string comparisons here to set it's own flags. Set "isTimestamp" in your CMysqlColumnSchema here.
Tell Yii to use your schema driver like this in your components section in the config:
'db' => array(
'connectionString' => 'mysql:host=localhost;dbname=database',
'username' => '',
'password' => '',
'driverMap' => array('mysql' => 'CustomMysqlSchema'),
),
You will need to query the column schema, I've not used giix but find where it is generating the views, it should be looping through either the model attributes or the underlying table schema.
If it is looping through the schema:
//you can also ask Yii for the table schema with Yii::app()->db->schema->getTable[$tableName];
if ('timestamp' === $tableSchema->columns[$columnName]->dbType)
continue; //skip this loop iteration
If it loops over the attributes:
$dbType = Yii::app()->db->schema->getTable[$model->tableName]->columns[$modelAttribute]->dbType;
if ('timestamp' === $dbType)
continue; //skip this loop iteration

Is it possible to set certain product attributes for a different store view using the Magento API?

We are currently using the Magento API for importing a bunch of products into the store.
But we now run into a problem where some product attributes should be translated into a different language.
And I was wondering if it is possible to do this using the Magento API, because I can't seem to find anything related to that problem.
We currently have 2 store views, 1 for the Dutch version of the site and one for the French version of the site.
Our current import code looks something like this:
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('nl'));
echo("store_id: $store_id");
$new_product_data = array(
'name' => 'NameInDutch',
'short_description' => 'DescriptionInDutch',
'price' => $price,
'weight' => $weight,
'websites' => array('base'),
'status' => '1'
);
$new_product_id = $soapClient->call($soapSession, 'catalog_product.create', array('simple', 4, $sku, $new_product_data)); // 4 => 'Default' attribute set
$localized_product_data = array(
'name' => 'NameInFrench',
'short_description' => 'DescriptionInFrench'
);
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('fr'));
echo("store_id: $store_id");
$soapClient->call($soapSession, 'catalog_product.update', array($sku, $localized_product_data ));
Now, the output of the echo statements differs, the first time it's 1 and the second time it's 2, so that doesn't seem to be problem. But apparently it doesn't matter for the API if we set that value.
The result is that on the 'catalog_product.update' call, the name 'NameInFrench' overwrites the default name 'NameInDutch'.
So my question is if something like this is possible using the Magento API, and how one would accomplish this?
Ok, I found the answer, apparently I overlooked a certain line in the Magento API docs, because the solution was right there.
So: you don't need to set the currentStore each time, you just need to append the store id or code to the update array:
$soapClient->call(
$soapSession,
'catalog_product.update',
array($sku, $localized_product_data, 'fr')
);
This works perfectly.

Cakephp, i18n, SQL Error, Not unique table/alias

I get the following SQL error:
SQL Error: 1066: Not unique table/alias: 'I18n__name'
when doing a simple find query.
Any ideas on possible situations that may have caused this??
I'm using a bindModel method to retrieve the data is that related?
This is my code:
$this->Project->bindModel(array(
'hasOne' => array(
'ProjectsCategories',
'FilterCategory' => array(
'className' => 'Category',
'foreignKey' => false,
'conditions' => array('FilterCategory.id = ProjectsCategories.category_id')
))));
$prlist = $this->Project->find('all', array(
'fields' => array('DISTINCT slug','name'),
'conditions' => array('FilterCategory.slug !='=>'uncategorised')
))
You have not used or initialized the required table/model you are using in your controller. Use var $uses = array('your_table_name');
I do not have a direct answer to my problem. However after some research I came to the following conclusion.
I've decided to change my methodology and stop using the translate behavior in cakephp.
I've found another behavior called i18n which works much better when dealing with associated models. You can read about it http://www.palivoda.eu/2008/04/i18n-in-cakephp-12-database-content-translation-part-2/#comment-1380
In cakephp book it says :
"Note that only fields of the model
you are directly doing find on will
be translated. Models attached via
associations won't be translated
because triggering callbacks on
associated models is currently not
supported."
I'm not sure if I made the right choice however I have been struggling to get the translate behavior to work in cakephp and this solution at least makes the project I'm working functional.