-2

I am creating a custom shipping method for opencart, however i am stuck on the catalog model file, which is for PHP 5.4+, but how do i make it working with PHP 5.3 as Opencart Requirement is start from PHP 5.3

catalog/model/shipping/items.php

    $languages = $this->language->get('code');
    $quote_data = array();
    $quote_data['items'] = array(
        'code'         => 'items.items',
        'title'        => $this->config->get('items_shipping_description')[$languages],
        'cost'         => $this->config->get('items_cost'),
        'tax_class_id' => $this->config->get('items_tax_class_id'),
        'text'         => $this->currency->format($this->tax->calculate($items_cost, $this->config->get('items_tax_class_id'), $this->config->get('config_tax')))
    );

this line working fine with PHP 5.4+ but not PHP 5.3

'title'=> $this->config->get('items_shipping_description')[$languages],

I get an error for PHP 5.3 which is

Parse error: syntax error, unexpected '[', expecting ')' in ...

I've also read many duplicate question and tried many different way to make this working with no luck! please help, thank you!

Zulfakar Zukri
  • 173
  • 4
  • 21
  • 1
    *first* google hit for the *title* of the question: http://stackoverflow.com/questions/17411106/parse-error-syntax-error-unexpected-expecting – Karoly Horvath Oct 29 '15 at 16:51
  • 2
    Possible duplicate of [PHP syntax for dereferencing function result](http://stackoverflow.com/questions/742764/php-syntax-for-dereferencing-function-result) – Karoly Horvath Oct 29 '15 at 16:51
  • @karoly Horvath: that was the first question i've ever read, btw thank you – Zulfakar Zukri Oct 29 '15 at 16:56

3 Answers3

3

Just assign it to variable: $description = $this->config->get('items_shipping_description') And then use:

$quote_data['items'] = array(
    'code'         => 'items.items',
    'title'        => $description[$languages]
    'cost'         => $this->config->get('items_cost'),
    'tax_class_id' => $this->config->get('items_tax_class_id'),
    'text'         => $this->currency->format($this->tax->calculate($items_cost, $this->config->get('items_tax_class_id'), $this->config->get('config_tax')))
);
sergio
  • 5,210
  • 7
  • 24
  • 46
1
$this->config->get('items_shipping_description')[$languages]

This is function array dereferencing and was only added in php 5.4

To make it work with php 5.3 you will need to assign that return value to a variable and then use that.

$items = $this->config->get('items_shipping_description');
$items[$languages];
danjam
  • 1,064
  • 9
  • 13
0

Try this,

$desc = $this->config->get('items_shipping_description');

And

'title'        => $desc[$languages],
Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41