I have a question about how I can pull a deep nested translation value from Twig dynamically.
Here is the setup:
I have my translations files in yml format (en.yml), here is an example:
parent:
child:
something: here is some test
another: more text here
I then have an array passed to Twig:
array(2) {
[0]=>
array(2) {
["name"]=>
string(2) "GS"
["folders"]=>
array(1) {
[0]=>
array(1) {
["name"]=>
string(3) "something"
}
}
[1]=>
array(2) {
["name"]=>
string(1) "I"
["folders"]=>
array(2) {
[0]=>
array(3) {
["name"]=>
string(2) "another"
}
}
In twig, I want to print the folder names to screen, e.g.
here is some test
It would be easy if the lang file had everything in its root, I could use:
{{ array.folders.name|trans }}
However as this is a nested value in the lang file I somehow need to say:
{{'parent.child'.array.folders.name|trans }}
Any help would be very much appricated.
Simply first concatenate the string, then pass the value to the translator filter as follow:
{{ ('parent.child.' ~ array.folders.name)|trans }}
Hope this help
i have error in this line :
$count2 = new app\models\Opportunity;
--> $count3 = $count2->countType($idP, $allId); <--
coutType is this :
public function countType($type, $allId) {
$query = (new \yii\db\Query())->select(['count(id)'])->from('opportunity');
$query->andWhere(['in', 'id', $allId]);
$query->andWhere(['in', 'project_type_id', $type]);
$command = $query->createCommand();
$model = $command->queryAll();
return $model;
}
and $allId is with this data :
array(67) { [0]=> string(3) "473" [1]=> string(3) "472" [2]=> string(3) "471" [3]=> string(3) "470" [4]=> string(3) "469" [5]=> string(3) "468" [6]=> string(3) "467" [7]=> string(3) "466" [8]=> string(3) "465" [9]=> string(3) "464" [10]=> string(3) "463" [11]=> string(3) "462" [12]=> string(3) "461" [13]=> string(3) "460" [14]=> string(3) "451" [15]=> string(3) "450" [16]=> string(3) "449" [17]=> string(3) "448" [18]=> string(3) "447" [19]=> string(3) "446" [20]=> string(3) "445" [21]=> string(3) "444" [22]=> string(3) "443" [23]=> string(3) "442" [24]=> string(3) "436" [25]=> string(3) "435" [26]=> string(3) "434" [27]=> string(3) "433" [28]=> string(3) "432" [29]=> string(3) "431" [30]=> string(3) "430" [31]=> string(3) "426" [32]=> string(3) "425" [33]=> string(3) "424" [34]=> string(3) "423" [35]=> string(3) "422" [36]=> string(3) "421" [37]=> string(3) "420" [38]=> string(3) "419" [39]=> string(3) "418" [40]=> string(3) "417" [41]=> string(3) "416" [42]=> string(3) "415" [43]=> string(3) "414" [44]=> string(3) "413" [45]=> string(3) "412" [46]=> string(3) "411" [47]=> string(3) "410" [48]=> string(3) "409" [49]=> string(3) "407" [50]=> string(3) "406" [51]=> string(3) "405" [52]=> string(3) "404" [53]=> string(3) "403" [54]=> string(3) "402" [55]=> string(3) "401" [56]=> string(3) "400" [57]=> string(3) "399" [58]=> string(3) "393" [59]=> string(3) "392" [60]=> string(3) "391" [61]=> string(3) "390" [62]=> string(3) "389" [63]=> string(3) "388" [64]=> string(3) "387" [65]=> string(3) "386" [66]=> string(3) "382" }
how to resolve my problem ??
For normal username/password fields, it's pretty straight forward with a single key value pair, but I recently encountered a complicated Content Service, which has a group of fields (birth date), do we resubmit in plural form or as if they were separate fields?
Example:
Normal Form:
["componentList"]=>
array(4) {
[0]=>
object(stdClass)#3 (13) {
["valueIdentifier"]=>
string(5) "LOGIN"
["valueMask"]=>
string(11) "LOGIN_FIELD"
["fieldType"]=>
object(stdClass)#6 (1) {
["typeName"]=>
string(4) "TEXT"
}
["size"]=>
int(20)
["maxlength"]=>
int(15)
["name"]=>
string(5) "LOGIN"
["displayName"]=>
string(7) "User ID"
["isEditable"]=>
bool(true)
["isOptional"]=>
bool(false)
["isEscaped"]=>
bool(false)
["helpText"]=>
string(5) "85046"
["isOptionalMFA"]=>
bool(false)
["isMFA"]=>
bool(false)
}
Weird plural form:
[3]=>
object(stdClass)#11 (19) {
["defaultValues"]=>
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
["values"]=>
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
["validValues"]=>
array(3) {
[0]=>
array(12) {
[0]=>
string(2) "01"
[1]=>
string(2) "02"
[2]=>
string(2) "03"
[3]=>
string(2) "04"
}
[1]=>
array(31) {
[0]=>
string(2) "01"
[1]=>
string(2) "02"
[2]=>
string(2) "03"
[3]=>
string(2) "04"
}
[2]=>
NULL
}
["valueIdentifiers"]=>
array(3) {
[0]=>
string(8) "OPTIONS1"
[1]=>
string(7) "OPTIONS"
[2]=>
string(6) "LOGIN1"
}
["valueMasks"]=>
array(3) {
[0]=>
string(12) "/LOGIN_FIELD"
[1]=>
string(11) "LOGIN_FIELD"
[2]=>
string(12) "/LOGIN_FIELD"
}
["fieldTypes"]=>
array(3) {
[0]=>
object(stdClass)#9 (1) {
["typeName"]=>
string(7) "OPTIONS"
}
[1]=>
object(stdClass)#8 (1) {
["typeName"]=>
string(7) "OPTIONS"
}
[2]=>
object(stdClass)#14 (1) {
["typeName"]=>
string(4) "TEXT"
}
}
["validationRules"]=>
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
["sizes"]=>
array(3) {
[0]=>
int(20)
[1]=>
int(20)
[2]=>
int(20)
}
["maxlengths"]=>
array(3) {
[0]=>
int(40)
[1]=>
int(40)
[2]=>
int(4)
}
["userProfileMappingExpressions"]=>
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
["name"]=>
string(26) "Date of Birth (MM/DD/YYYY)"
["displayName"]=>
string(26) "Date of Birth (MM/DD/YYYY)"
["isEditable"]=>
bool(true)
["isOptional"]=>
bool(false)
["isEscaped"]=>
bool(false)
["helpText"]=>
string(5) "85043"
["isOptionalMFA"]=>
bool(false)
["isMFA"]=>
bool(false)
}
When sending this grouping back to the API, I currently flattened it so it's like:
credentialFields[3]
credentialFields[4]
credentialFields[5]
With each containing the relevant data for the date, month and year. However, perhaps we are supposed to roll it up as plurals in the same way it comes down? Is there an example of one of these multi-value forms for the REST API?
You are correct certain financial institutions do have multiple fields in groups, DOB is one of them. I have done successful implementation for the same. Since I did the same in purely SOAP, however I do not have any sample for REST implementation so what all I can tell you that is you do not need to flatten the list simply fill in the required answers in the original list and send back the form with your request.
Im having trouble with Yii conditions.
My code:
$criteria=new CDbCriteria;
//$criteria->together = true;
$criteria->group='t.id';
$criteria->with = array('farmer_goods','goods_catalog');
//$criteria->compare('farmer_goods.price', '<>0');
$criteria->compare('goods_catalog.name', $this->_params['category']);
In this case it works the way i want (i get list of items and each item has a list of farmers that have them, and 1 category to with this item is relative to.
But the problem is that I need to sort the list by price of a item that is stored in a farmers table.
so, if I uncomment this line:
//$criteria->compare('farmer_goods.price', '<>0');
I get:
SELECT `t`.`id` AS `t0_c0`, `t`.`catalog_id` AS `t0_c1`, `t`.`articul` AS `t0_c2`, `t`.`###name` AS `t0_c3`, `t`.`name_rus` AS `t0_c4`, `t`.`ed_izm` AS `t0_c5`, `t`.`srok_godnosti` AS `t0_c6`, `t`.`temp_hraneniya` AS `t0_c7`, `t`.`belki` AS `t0_c8`, `t`.`jiri` AS `t0_c9`, `t`.`uglevodi` AS `t0_c10`, `t`.`kalorii` AS `t0_c11`, `t`.`gost` AS `t0_c12`, `t`.`photo` AS `t0_c13`, `t`.`opisanie` AS `t0_c14`, `goods_catalog`.`id` AS `t2_c0`, `goods_catalog`.`parent_id` AS `t2_c1`, `goods_catalog`.`unique_name` AS `t2_c2`, `goods_catalog`.`name` AS `t2_c3`, `goods_catalog`.`name_rus` AS `t2_c4`, `goods_catalog`.`rout_url` AS `t2_c5`, `goods_catalog`.`launch_model` AS `t2_c6`, `goods_catalog`.`photo` AS `t2_c7` FROM `goods_details` `t` LEFT OUTER JOIN `goods_catalog` `goods_catalog` ON (`t`.`catalog_id`=`goods_catalog`.`id`) WHERE (((farmer_goods.price LIKE :ycp0) AND (farmer_goods.price<>:ycp1)) AND (goods_catalog.name=:ycp2)) GROUP BY t.id LIMIT 50
You can see that there is no join with farmers:
FROM `goods_details` `t` LEFT OUTER JOIN `goods_catalog` `goods_catalog` ON (`t`.`catalog_id`=`goods_catalog`.`id`)
If I uncomment:
//$criteria->together = true;
it solves this problem but in response i get list of 1 farmer (and that is not what i want)
I guess I have to do some kind of criteria in criteria but how?
my var_dump(); with 2 comment lines
object(GoodsDetails)#88 (11) {
["_attributes":"CActiveRecord":private]=>
array(15) {
["id"]=>
string(1) "1"
["catalog_id"]=>
string(1) "1"
["articul"]=>
string(6) "myaso1"
["###name"]=>
string(4) "meet"
["name_rus"]=>
string(29) "Мяско вкуснящее"
["ed_izm"]=>
string(1) "1"
["srok_godnosti"]=>
string(2) "14"
["temp_hraneniya"]=>
string(4) "0±2"
["belki"]=>
string(4) "13.7"
["jiri"]=>
string(4) "36,5"
["uglevodi"]=>
string(8) "uglevodi"
["kalorii"]=>
string(4) "384"
["gost"]=>
string(13) "Р 53221-2008"
["photo"]=>
string(371) "{"main":0,"images":[{"title":"pic","url":["images\/title_01.jpg","images\/title_02.jpg","images\/title_03.jpg","images\/title_04.jpg"]},{"title":"pic2","url":["images\/title_11.jpg","images\/title_12.jpg","images\/title_13.jpg","images\/title_14.jpg"]},{"title":"pic2","url":["images\/title_21.jpg","images\/title_22.jpg","images\/title_23.jpg","images\/title_24.jpg"]}]}"
["opisanie"]=>
string(98) "zxc"
}
["_related":"CActiveRecord":private]=>
array(2) {
["farmer_goods"]=>
array(5) {
[0]=>
object(FarmersGoods)#93 (11) {
["_attributes":"CActiveRecord":private]=>
array(7) {
["id"]=>
string(1) "1"
["farmer_id"]=>
string(1) "1"
["articul"]=>
string(6) "myaso1"
["price"]=>
string(1) "0"
["fasovka"]=>
string(9) "[1,3,4,5]"
["fasovka_options"]=>
NULL
["count_left"]=>
NULL
}
}
[1]=>
object(FarmersGoods)#94 (11) {
["_attributes":"CActiveRecord":private]=>
array(7) {
["id"]=>
string(1) "2"
["farmer_id"]=>
string(1) "3"
["articul"]=>
string(6) "myaso1"
["price"]=>
string(5) "20.99"
["fasovka"]=>
string(4) "3543"
["fasovka_options"]=>
NULL
["count_left"]=>
NULL
}
}
[2]=>
object(FarmersGoods)#95 (11) {
["_attributes":"CActiveRecord":private]=>
array(7) {
["id"]=>
string(1) "3"
["farmer_id"]=>
string(1) "4"
["articul"]=>
string(6) "myaso1"
["price"]=>
string(5) "35.60"
["fasovka"]=>
string(4) "3543"
["fasovka_options"]=>
NULL
["count_left"]=>
NULL
}
}
[3]=>
object(FarmersGoods)#96 (11) {
["_attributes":"CActiveRecord":private]=>
array(7) {
["id"]=>
string(1) "4"
["farmer_id"]=>
string(1) "5"
["articul"]=>
string(6) "myaso1"
["price"]=>
string(2) "50"
["fasovka"]=>
string(11) "[1,2,2.5,5]"
["fasovka_options"]=>
NULL
["count_left"]=>
NULL
}
}
[4]=>
object(FarmersGoods)#97 (11) {
["_attributes":"CActiveRecord":private]=>
array(7) {
["id"]=>
string(1) "5"
["farmer_id"]=>
string(1) "6"
["articul"]=>
string(6) "myaso1"
["price"]=>
string(5) "50.10"
["fasovka"]=>
string(3) "123"
["fasovka_options"]=>
NULL
["count_left"]=>
NULL
}
}
}
["goods_catalog"]=>
object(GoodsCatalog)#89 (11) {
["_new":"CActiveRecord":private]=>
bool(false)
["_attributes":"CActiveRecord":private]=>
array(8) {
["id"]=>
string(1) "1"
["parent_id"]=>
string(1) "6"
["unique_name"]=>
NULL
["name"]=>
string(4) "meet"
["name_rus"]=>
string(8) "Мясо"
["rout_url"]=>
NULL
["launch_model"]=>
NULL
["photo"]=>
NULL
}
}
}
}
my relations
TradeGoods
'farmer_goods'=>array(self::HAS_MANY, 'FarmersGoods', array('articul'=>'articul')),
'goods_catalog'=>array(self::BELONGS_TO, 'GoodsCatalog', array('catalog_id'=>'id')),
edit
manually posting SQL query via phpmyadmin gives fine results
SELECT
`t`.`id` AS `t0_c0`,
`t`.`catalog_id` AS `t0_c1`,
`t`.`articul` AS `t0_c2`,
`t`.`###name` AS `t0_c3`,
`t`.`name_rus` AS `t0_c4`,
`t`.`ed_izm` AS `t0_c5`,
`t`.`srok_godnosti` AS `t0_c6`,
`t`.`temp_hraneniya` AS `t0_c7`,
`t`.`belki` AS `t0_c8`,
`t`.`jiri` AS `t0_c9`,
`t`.`uglevodi` AS `t0_c10`,
`t`.`kalorii` AS `t0_c11`,
`t`.`gost` AS `t0_c12`,
`t`.`photo` AS `t0_c13`,
`t`.`opisanie` AS `t0_c14`,
`farmer_goods`.`id` AS `t1_c0`,
`farmer_goods`.`farmer_id` AS `t1_c1`,
`farmer_goods`.`articul` AS `t1_c2`,
`farmer_goods`.`price` AS `t1_c3`,
`farmer_goods`.`fasovka` AS `t1_c4`,
`farmer_goods`.`fasovka_options` AS `t1_c5`,
`farmer_goods`.`count_left` AS `t1_c6`,
`goods_catalog`.`id` AS `t2_c0`,
`goods_catalog`.`parent_id` AS `t2_c1`,
`goods_catalog`.`unique_name` AS `t2_c2`,
`goods_catalog`.`name` AS `t2_c3`,
`goods_catalog`.`name_rus` AS `t2_c4`,
`goods_catalog`.`rout_url` AS `t2_c5`,
`goods_catalog`.`launch_model` AS `t2_c6`,
`goods_catalog`.`photo` AS `t2_c7`
FROM
`goods_details` `t`
LEFT OUTER JOIN
`farmers_goods` `farmer_goods`
ON
(`farmer_goods`.`articul`=`t`.`articul`)
LEFT OUTER JOIN
`goods_catalog` `goods_catalog`
ON
(`t`.`catalog_id`=`goods_catalog`.`id`)
WHERE
(`goods_catalog`.`name`='meet')
GROUP BY `t`.`id`
ORDER BY `farmer_goods`.`price`
but when Yii sort is launched like this
$sort = new CSort('FarmersGoods');
$sort->attributes = array(
'price'=>array(
'asc'=>'farmer_goods.price ASC',
'desc'=>'farmer_goods.price DESC',
),
'*',
);
it "looses":
LEFT OUTER JOIN
`farmers_goods` `farmer_goods`
ON
(`farmer_goods`.`articul`=`t`.`articul`)
I found a problem
I really hope that helps someone like me and spare their time
so the point is that when you are sorting a BELONGS_TO or HAS_ONE there's no problem jast use
$criteria=new CDbCriteria;
$criteria->group='t.id';
$criteria->with = array('farmer_goods');
and sort like
$sort = new CSort('FarmersGoods');
$sort->attributes = array(
'price'=>array(
'asc'=>'farmer_goods.price ASC',
'desc'=>'farmer_goods.price DESC',
),
);
but when you need to sort a HAS_MANY (and possibly MANY_MANY, not tested that) you need to write your criteria like this
$criteria=new CDbCriteria;
$criteria->group='t.id';
$criteria->with = array('farmer_goods'=>array('together'=>true),'goods_catalog');
that's not obvious but a vary important thing that lets you sort by a related HAS_MANY table atribute
btw - sorry for my bad English
bast of luck from Ukraine
Ga1der
I need to display product image in order details page when user click order details link.
I have edited below code in order-detail.tpl but it not shows product image it shows only some dummy image
<td>
<a href="{$link->getProductLink($product.product_id, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|escape:'htmlall':'UTF-8'}">
<img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'small_default')}" alt="{$product.name|escape:'htmlall':'UTF-8'}" {if isset($smallSize)}width="{$smallSize.width}" height="{$smallSize.height}" {/if} /></a>
</td>
I want to do this in PS 1.3 version, and I have problem too :/ When I display {$product.image|var_dump} variable I get NULL
Function getImageLink($product.link_rewrite, $product.id_image, 'small_default') working good, but the problem is to get values from variables $product.link_rewrite and $product.id_image but I unfortunately don't know how to.
Now they are empty and so on links to image is incorrect
If that page you can view the variable what comes with $product. Like this.
{$product|var_dump}
and you will notice that $product have a array value image which is a object
so now go with this.
{$product.image|var_dump}
and you will view all this value.
object(Image)#490 (26) {
["id"]=>
int(1)
["id_image"]=>
string(1) "1"
["id_product"]=>
string(1) "3"
["position"]=>
string(1) "1"
["cover"]=>
string(1) "1"
["image_format"]=>
string(3) "jpg"
["source_index"]=>
string(52) "/Applications/MAMP/htdocs/prestashop/img/p/index.php"
["folder":protected]=>
NULL
["existing_path":protected]=>
NULL
["id_lang":protected]=>
NULL
["id_shop":protected]=>
int(1)
["id_shop_list"]=>
NULL
["get_shop_from_context":protected]=>
bool(true)
["table":protected]=>
string(5) "image"
["identifier":protected]=>
string(8) "id_image"
["fieldsRequired":protected]=>
array(1) {
[0]=>
string(10) "id_product"
}
["fieldsSize":protected]=>
array(0) {
}
["fieldsValidate":protected]=>
array(3) {
["id_product"]=>
string(12) "isUnsignedId"
["position"]=>
string(13) "isUnsignedInt"
["cover"]=>
string(6) "isBool"
}
["fieldsRequiredLang":protected]=>
array(0) {
}
["fieldsSizeLang":protected]=>
array(0) {
}
["fieldsValidateLang":protected]=>
array(0) {
}
["tables":protected]=>
array(0) {
}
["webserviceParameters":protected]=>
array(0) {
}
["image_dir":protected]=>
string(43) "/Applications/MAMP/htdocs/prestashop/img/p/"
["def":protected]=>
array(6) {
["table"]=>
string(5) "image"
["primary"]=>
string(8) "id_image"
["multilang"]=>
bool(true)
["fields"]=>
array(3) {
["id_product"]=>
array(3) {
["type"]=>
int(1)
["validate"]=>
string(12) "isUnsignedId"
["required"]=>
bool(true)
}
["position"]=>
array(2) {
["type"]=>
int(1)
["validate"]=>
string(13) "isUnsignedInt"
}
["cover"]=>
array(3) {
["type"]=>
int(2)
["validate"]=>
string(6) "isBool"
["shop"]=>
bool(true)
}
}
["classname"]=>
string(5) "Image"
["associations"]=>
array(1) {
["l"]=>
array(3) {
["type"]=>
int(2)
["field"]=>
string(8) "id_image"
["foreign_field"]=>
string(8) "id_image"
}
}
}
["update_fields":protected]=>
NULL
}
You will notice that there is not value of link_rewrite. So you need to pass that from the controller.