3
Answers
Vote up!
-1
Vote down!

i want to dynamicly change the price of the product for each letter count of the word

I have a product type with a line-type-item - editable field as a textfield where user can type a word.
i want to dynamicly change the price of the product for each letter count of the word.
e.g. "word" costs 4 euro and "words" costs 5 euro.
i would be more than thankful for any help to archive that or even to get started.

thank you

Asked by: strr
on July 12, 2013

3 Answers

Vote up!
0
Vote down!

Please someone give me a hint to get started?
Should i create a custom module or could that done with views or some custom cart code.

Answer by: strr
Posted: Sep 4, 2013
Vote up!
0
Vote down!

I tried to solve my challenge with a rule. Here is what i did so far:

{ "rules_textfeldl_nge_preiskalkulation" : {
"LABEL" : "Textfeldl\u00e4nge Preiskalkulation",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "php", "commerce_line_item", "commerce_cart" ],
"ON" : [ "commerce_cart_product_add" ],
"IF" : [
{ "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "field_usertexts" } }
],
"DO" : [
{ "commerce_line_item_unit_price_multiply" : {
"commerce_line_item" : [ "commerce_line_item" ],
"amount" : {
"select" : "commerce-product:commerce-price:amount",
"num_offset" : { "value" : "1" },
"php" : { "code" : "$field_usertexts_1 = $data-\u003Efield_field_usertexts[0][\u0027raw\u0027][\u0027value\u0027];\r\nif ($field_usertexts_1 !== \u0022Beispieltext\u0022) {\r\n$printtext = $field_usertexts_1;\r\n$value = strlen($printtext);\r\nreturn $value;\r\nprint $value;\r\necho $value;\r\n};" }
},
"component_name" : "base_price",
"round_mode" : "1"
}
}
]
}
}

I guess the challenge is to read the editable field called "usertexts" count the number of characters and then multiply the price with the value.

i used custom "PHP evaluation" under "Actions" to do that:

$field_usertexts_1 = $data->field_field_usertexts[0]['raw']['value'];
if ($field_usertexts_1 !== "Beispieltext") {
$printtext = $field_usertexts_1;
$value = strlen($printtext);
return $value;
print $value;
echo $value;
};

Answer by: strr
Posted: Sep 4, 2013
Vote up!
0
Vote down!

Anyone please?

Answer by: strr
Posted: Sep 17, 2013