csv - Print or echo a selected option in php, without a form -
this shipping module, allows choose store branches local pickup. branches listed in csv, not in database.
<?php if ( ($n > 1) || ($n2 > 1) ) { if ($quotes[$i]['id'] == 'localdelivery') { if (file_exists($quotes[$i]['pricesl'])) { echo '<td class="main" style="padding-right:15px;"><select name="locdeliv">'; $file_handle = fopen($quotes[$i]['pricesl'], "r"); while (!feof($file_handle)) { $line_of_text = fgetcsv($file_handle, 1024); echo '<option value="' . $line_of_text[1] . '">' . $line_of_text[0] . '</option>'; } fclose($file_handle); } else { echo '<td class="main"><select name="locdeliv"><option value="0">file missing</option>'; } echo '</select></td>'; } //else { ?>
that works fine. here's code shows user sees shipping description:
function quote($method = '') { global $order; $this->quotes = array('id' => $this->code, 'module' => module_shipping_localdelivery_text_title, 'pricesl' => module_shipping_localdelivery_pricesfile, 'methods' => array(array('id' => $this->code, 'title' => print $line_of_text[1], 'cost' => module_shipping_localdelivery_cost))); if ($this->tax_class > 0) { $this->quotes['tax'] = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']); } if (tep_not_null($this->icon)) $this->quotes['icon'] = tep_image($this->icon, $this->title); return $this->quotes; }
this part
'title' => print $line_of_text[1],
i need echo whatever user has chosen dropdown list. i've tried various things $file_handle etc., "1" result. there simple way selected dropdown value 'title'? allows title later saved in database. in other modules, 'title' taken language file, never comes database , checkout page "doesn't care" line is, saves database can see option chosen in administration. reason using csv company updates branches , easiest way update frequently.
you trying use programming construct
(print
) while defining variable - incorrect syntax.
what need use function, quote
, , value returned array.
$result = $obj->quote(); $title = $result['methods'][0]['title']; print $title;
edit elaborate:
your function quote
referencing $this
, meaning method
within class
. able use method need call outside of class itself. call client code.
class foo { public function quotes() { // ** code ** return $this->quotes; } } // outside class, client code $foo = new foo(); $result = $foo->quote(); $title = $result['methods'][0]['title']; print $title;
Comments
Post a Comment