I have created a function that call a Magento SoapClient
In traditional PHP if i run it via command php soapcron.php
it works
Also i put the same code in a function on CI, on web it Works, but on command via CLI cron it doesn't work and give me an error:
the traditional php is:
PHP Code:
$client = new SoapClient('http://www.magento.com/api/soap/?wsdl');
$session = $client->login('ApiUser', 'ApiKey');
try {
$getAttributes = $client->call($session, 'catalog_product_attribute.options', 11);
} catch (SoapFault $e) {
echo '11';
print($client->__getLastResponse());
}
var_dump($getAttributes);
$client->endSession($session);
CI Method
PHP Code:
public function SyncAttributes(){
$client = new SoapClient('http://www.magento.com/api/soap/?wsdl');
$session = $client->login('ApiUser', 'ApiKey');
$attributes = $this->Magento_m->getAttributes();
foreach($attributes as $attribute){
try {
$getAttributes = $client->call($session, 'catalog_product_attribute.options', $attribute->attribute_code);
} catch (SoapFault $e) {
echo $attribute->attribute_code;
print($client->__getLastResponse());
}
foreach($getAttributes as $value){
$dataInsert = null;
if($value['value'] != ""){
$dataInsert = array(
'attribute_code' => $attribute->attribute_code,
'attribute_value' => $value['value'],
'attribute_label' => $value['label']
);
}
if($dataInsert != null){
$syncronize = $this->Magento_m->syncAttributes($dataInsert);
}
}
}
if(isset($syncronize) && $syncronize == true){
echo json_encode(array('status' => 'success'));
}else{
echo json_encode(array('status' => 'nothing_new'));
}
$client->endSession($session);
}
This method is called in command php /paht/to/ci/index.php Controller SyncAttributes
the error is:
Code:
PHP Notice: Constant ENVIRONMENT already defined in /path/to/ci/index.php on line 57
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 2
Filename: /path/to/ci/application/controllers/Controller.php
Line Number: 25
Backtrace: File: /path/to/ci/application/controllers/Controller.php
Line: 25
Function: _error_handler
File: /path/to/ci/index.php
Line: 293
Function: require_once
A PHP Error was encountered
Severity: Error
Message: SoapClient::SoapClient(): 'uri' option is required in nonWSDL mode
Filename: /path/to/ci/application/controllers/Controller.php
Line Number: 25
Line 25 is: $client = new SoapClient('http://www.magento.com/api/soap/?wsdl');
Is there a way to fix it?