1

Is there any way to pass a string from php field to php filter?

on the PHP FIELD I can tell if a product has discount or not ( i think because the field formatter render the field_price in a way that triggers the discount rules) and if there is a discount I can set a variable on/off based on the output of this formatter.

This custom discount variable created with PHP FIELD I need to pass it to the PHP FILTER to control if a product must needs to be shown or not (sorry for my bad English)

PHP FIELD CODE

<?php

// $var1 will take value 0.00E or -94.99E (the last value is an example)
$var1 = strip_tags($data->field_commerce_price[0][rendered]);

// $var2 will take value 0 or -
$var2 = mb_substr($var1, 0, 1, 'utf-8');

// set $static = 0 or 1, if PHP FILTER can see this then can filter discount products
if ($var2=="-") { $static = "1"; echo "DISCOUNT!"; } else {$static = "0"; }

?>

PHP FILTER CODE

// all 4 variables gives output nothing
dpm($row->_field_data['nid']['entity']->field_commerce_price[0][rendered]);
dpm($data->_field_data['nid']['entity']->field_commerce_price[0][rendered]);
dpm($data->field_commerce_price[0][rendered]);
dpm($static);

if ($static=="1") { return FALSE; } else { return TRUE;}

So how PHP field send a string to PHP FILTER??? OR Is there any to create a filter function using the PHP FIELD?

1

You can copy the code from the php field and add some logic to it to return false or true depending on the result but no there is no current way to transfer it.

EDIT: This may seem a bit backwards, though if you made a $_SESSION variable as an Array() you could maybe do something with that. Maybe not very helpful. views_php has always been entirely buggy for me and it comes in handy sparingly.

| improve this answer | |
  • You'll need to look at the available variables in the PHP Filter. – SDMulroy Jul 3 '14 at 1:55
  • thanks for your reply Mulroy. $static is one of the available variables on both FIELD and FILTER field. – user33711 Jul 3 '14 at 8:29
  • Also i have try to copy the code from FIELD to FILTER, but from the FILTER I don't have access to discount value because is calculated with rules and appears with FIELD formatter – user33711 Jul 3 '14 at 8:37
  • I bet you could do the same logic in your formatter code. – SDMulroy Jul 3 '14 at 10:28
  • I don't understand where is this 'formatter code' and how this could help since the FIELD formatter output cannot pass into the scope of FILTER, can you give some additional info about it? thank you – user33711 Jul 3 '14 at 11:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.