Fedex shipping error - php

I've searched Google and Stackoverlow about this problem which a lot of people appear to be running into, but not one single definitive answer.
I'm using Opencart vs 1.5.5.1 and the Fedex module doesn't display any shipping options during checkout, it simply displays ERROR.
I have verified that my key, password, account and meter number are correct. I am using a production account, not a testing account. Below is the exact XML (sensitive information removed) I am sending to: https://gateway.fedex.com/web-services/
<?xml version="1.0"?>
<soap-env:envelope xmlns:ns1="http://fedex.com/ws/rate/v10" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<soap-env:body>
<ns1:raterequest>
<ns1:webauthenticationdetail>
<ns1:usercredential>
<ns1:key>ThisIsMyKey</ns1:key>
<ns1:password>ThisIsMyPassword</ns1:password>
</ns1:usercredential>
</ns1:webauthenticationdetail>
<ns1:clientdetail>
<ns1:accountnumber>123456789</ns1:accountnumber>
<ns1:meternumber>987654321</ns1:meternumber>
</ns1:clientdetail>
<ns1:version>
<ns1:serviceid>crs</ns1:serviceid>
<ns1:major>10</ns1:major>
<ns1:intermediate>0</ns1:intermediate>
<ns1:minor>0</ns1:minor>
</ns1:version>
<ns1:returntransitandcommit>true</ns1:returntransitandcommit>
<ns1:requestedshipment>
<ns1:shiptimestamp>2013-09-11T11:35:31-05:00</ns1:shiptimestamp>
<ns1:dropofftype>REGULAR_PICKUP</ns1:dropofftype>
<ns1:packagingtype>FEDEX_ENVELOPE</ns1:packagingtype>
<ns1:shipper>
<ns1:contact>
<ns1:personname>Jägermein</ns1:personname>
<ns1:companyname>Jägermein</ns1:companyname>
<ns1:phonenumber>123-456-7890</ns1:phonenumber>
</ns1:contact>
<ns1:address>
<ns1:stateorprovincecode>IL</ns1:stateorprovincecode>
<ns1:postalcode>61422</ns1:postalcode>
<ns1:countrycode>US</ns1:countrycode>
</ns1:address>
</ns1:shipper>
<ns1:recipient>
<ns1:contact>
<ns1:personname>test test</ns1:personname>
<ns1:companyname></ns1:companyname>
<ns1:phonenumber></ns1:phonenumber>
</ns1:contact>
<ns1:address>
<ns1:streetlines>test</ns1:streetlines>
<ns1:city>test</ns1:city>
<ns1:stateorprovincecode>IL</ns1:stateorprovincecode>
<ns1:postalcode>61554</ns1:postalcode>
<ns1:countrycode>US</ns1:countrycode>
<ns1:residential>false</ns1:residential>
</ns1:address>
</ns1:recipient>
<ns1:shippingchargespayment>
<ns1:paymenttype>SENDER</ns1:paymenttype>
<ns1:payor>
<ns1:accountnumber>123456789</ns1:accountnumber>
<ns1:countrycode>US</ns1:countrycode>
</ns1:payor>
</ns1:shippingchargespayment>
<ns1:raterequesttypes>LIST</ns1:raterequesttypes>
<ns1:packagecount>1</ns1:packagecount>
<ns1:requestedpackagelineitems>
<ns1:sequencenumber>1</ns1:sequencenumber>
<ns1:grouppackagecount>1</ns1:grouppackagecount>
<ns1:weight>
<ns1:units>LB</ns1:units>
<ns1:value>19.541</ns1:value>
</ns1:weight>
<ns1:dimensions>
<ns1:length>20</ns1:length>
<ns1:width>20</ns1:width>
<ns1:height>10</ns1:height>
<ns1:units>IN</ns1:units>
</ns1:dimensions>
</ns1:requestedpackagelineitems>
</ns1:requestedshipment>
</ns1:raterequest>
</soap-env:body>
</soap-env:envelope>
Opencart is sending this request through CURL as follows:
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
curl_close($curl);
If I var_dump the response it gives me the following:
ERRORERRORprof1000Authentication Failed crs 10 0 0
Any ideas where the problem might be?

I finally managed to resolve this with the help of Fedex support.
It turns out the account credentials I was using were the same for another parent company, so I needed to register a separate account.

I have Fixed Fedex not showing error
Please find the file catalog/model/shipping/fedex.php
change the code with my code
if you see ERROR after it then don't forget to check your product weight
<?php
class ModelShippingFedex extends Model {
function getQuote($address) {
$this->load->language('shipping/fedex');
$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "zone_to_geo_zone WHERE geo_zone_id = '" . (int)$this->config->get('fedex_geo_zone_id') . "' AND country_id = '" . (int)$address['country_id'] . "' AND (zone_id = '" . (int)$address['zone_id'] . "' OR zone_id = '0')");
if (!$this->config->get('fedex_geo_zone_id')) {
$status = true;
} elseif ($query->num_rows) {
$status = true;
} else {
$status = false;
}
$error = '';
$quote_data = array();
if ($status) {
$weight = $this->weight->convert($this->cart->getWeight(), $this->config->get('config_weight_class_id'), $this->config->get('fedex_weight_class_id'));
$weight_code = strtoupper($this->weight->getUnit($this->config->get('fedex_weight_class_id')));
$date = time();
$day = date('l', $date);
if ($day == 'Saturday') {
$date += 172800;
} elseif ($day == 'Sunday') {
$date += 86400;
}
$this->load->model('localisation/country');
$country_info = $this->model_localisation_country->getCountry($this->config->get('config_country_id'));
$this->load->model('localisation/zone');
$zone_info = $this->model_localisation_zone->getZone($this->config->get('config_zone_id'));
if (!$this->config->get('fedex_test')) {
$url = 'https://gateway.fedex.com/web-services/';
} else {
$url = 'https://gatewaybeta.fedex.com/web-services/';
}
// Whoever introduced xml to shipping companies should be flogged
$xml = '<?xml version="1.0"?>';
$xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/rate/v10">';
$xml .= ' <SOAP-ENV:Body>';
$xml .= ' <ns1:RateRequest>';
$xml .= ' <ns1:WebAuthenticationDetail>';
$xml .= ' <ns1:UserCredential>';
$xml .= ' <ns1:Key>' . $this->config->get('fedex_key') . '</ns1:Key>';
$xml .= ' <ns1:Password>' . $this->config->get('fedex_password') . '</ns1:Password>';
$xml .= ' </ns1:UserCredential>';
$xml .= ' </ns1:WebAuthenticationDetail>';
$xml .= ' <ns1:ClientDetail>';
$xml .= ' <ns1:AccountNumber>' . $this->config->get('fedex_account') . '</ns1:AccountNumber>';
$xml .= ' <ns1:MeterNumber>' . $this->config->get('fedex_meter') . '</ns1:MeterNumber>';
$xml .= ' </ns1:ClientDetail>';
$xml .= ' <ns1:Version>';
$xml .= ' <ns1:ServiceId>crs</ns1:ServiceId>';
$xml .= ' <ns1:Major>10</ns1:Major>';
$xml .= ' <ns1:Intermediate>0</ns1:Intermediate>';
$xml .= ' <ns1:Minor>0</ns1:Minor>';
$xml .= ' </ns1:Version>';
$xml .= ' <ns1:ReturnTransitAndCommit>true</ns1:ReturnTransitAndCommit>';
$xml .= ' <ns1:RequestedShipment>';
$xml .= ' <ns1:ShipTimestamp>' . date('c', $date) . '</ns1:ShipTimestamp>';
$xml .= ' <ns1:DropoffType>' . $this->config->get('fedex_dropoff_type') . '</ns1:DropoffType>';
$xml .= ' <ns1:PackagingType>' . $this->config->get('fedex_packaging_type') . '</ns1:PackagingType>';
$xml .= ' <ns1:Shipper>';
$xml .= ' <ns1:Contact>';
$xml .= ' <ns1:PersonName>' . $this->config->get('config_owner') . '</ns1:PersonName>';
$xml .= ' <ns1:CompanyName>' . $this->config->get('config_name') . '</ns1:CompanyName>';
$xml .= ' <ns1:PhoneNumber>' . $this->config->get('config_telephone') . '</ns1:PhoneNumber>';
$xml .= ' </ns1:Contact>';
$xml .= ' <ns1:Address>';
if ($country_info['iso_code_2'] == 'US') {
$xml .= ' <ns1:StateOrProvinceCode>' . ($zone_info ? $zone_info['code'] : '') . '</ns1:StateOrProvinceCode>';
} else {
$xml .= ' <ns1:StateOrProvinceCode>' . ($zone_info ? $zone_info['name'] : '') . '</ns1:StateOrProvinceCode>';
}
$xml .= ' <ns1:PostalCode>' . $this->config->get('fedex_postcode') . '</ns1:PostalCode>';
$xml .= ' <ns1:CountryCode>' . $country_info['iso_code_2'] . '</ns1:CountryCode>';
$xml .= ' </ns1:Address>';
$xml .= ' </ns1:Shipper>';
$xml .= ' <ns1:Recipient>';
$xml .= ' <ns1:Contact>';
$xml .= ' <ns1:PersonName>' . $address['firstname'] . ' ' . $address['lastname'] . '</ns1:PersonName>';
$xml .= ' <ns1:CompanyName>' . $address['company'] . '</ns1:CompanyName>';
$xml .= ' <ns1:PhoneNumber>' . $this->customer->getTelephone() . '</ns1:PhoneNumber>';
$xml .= ' </ns1:Contact>';
$xml .= ' <ns1:Address>';
$xml .= ' <ns1:StreetLines>' . $address['address_1'] . '</ns1:StreetLines>';
$xml .= ' <ns1:City>' . $address['city'] . '</ns1:City>';
if ($address['iso_code_2'] == 'US') {
$xml .= ' <ns1:StateOrProvinceCode>' . $address['zone_code'] . '</ns1:StateOrProvinceCode>';
} else {
$xml .= ' <ns1:StateOrProvinceCode>' . $address['zone'] . '</ns1:StateOrProvinceCode>';
}
$xml .= ' <ns1:PostalCode>' . $address['postcode'] . '</ns1:PostalCode>';
$xml .= ' <ns1:CountryCode>' . $address['iso_code_2'] . '</ns1:CountryCode>';
$xml .= ' <ns1:Residential>' . ($address['company'] ? 'true' : 'false') . '</ns1:Residential>';
$xml .= ' </ns1:Address>';
$xml .= ' </ns1:Recipient>';
$xml .= ' <ns1:ShippingChargesPayment>';
$xml .= ' <ns1:PaymentType>SENDER</ns1:PaymentType>';
$xml .= ' <ns1:Payor>';
$xml .= ' <ns1:AccountNumber>' . $this->config->get('fedex_account') . '</ns1:AccountNumber>';
$xml .= ' <ns1:CountryCode>' . $country_info['iso_code_2'] . '</ns1:CountryCode>';
$xml .= ' </ns1:Payor>';
$xml .= ' </ns1:ShippingChargesPayment>';
$xml .= ' <ns1:RateRequestTypes>' . $this->config->get('fedex_rate_type') . '</ns1:RateRequestTypes>';
$xml .= ' <ns1:PackageCount>1</ns1:PackageCount>';
$xml .= ' <ns1:RequestedPackageLineItems>';
$xml .= ' <ns1:SequenceNumber>1</ns1:SequenceNumber>';
$xml .= ' <ns1:GroupPackageCount>1</ns1:GroupPackageCount>';
$xml .= ' <ns1:Weight>';
$xml .= ' <ns1:Units>' . $weight_code . '</ns1:Units>';
$xml .= ' <ns1:Value>' . $weight . '</ns1:Value>';
$xml .= ' </ns1:Weight>';
$xml .= ' <ns1:Dimensions>';
$xml .= ' <ns1:Length>20</ns1:Length>';
$xml .= ' <ns1:Width>20</ns1:Width>';
$xml .= ' <ns1:Height>10</ns1:Height>';
$xml .= ' <ns1:Units>IN</ns1:Units>';
$xml .= ' </ns1:Dimensions>';
$xml .= ' </ns1:RequestedPackageLineItems>';
$xml .= ' </ns1:RequestedShipment>';
$xml .= ' </ns1:RateRequest>';
$xml .= ' </SOAP-ENV:Body>';
$xml .= '</SOAP-ENV:Envelope>';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($curl);
curl_close($curl);
$dom = new DOMDocument('1.0', 'UTF-8');
$dom->loadXml($response);
if ($dom->getElementsByTagName('HighestSeverity')->item(0)->nodeValue == 'FAILURE' || $dom->getElementsByTagName('HighestSeverity')->item(0)->nodeValue == 'ERROR') {
$error = $dom->getElementsByTagName('HighestSeverity')->item(0)->nodeValue;
} else {
$rate_reply_details = $dom->getElementsByTagName('RateReplyDetails');
foreach ($rate_reply_details as $rate_reply_detail) {
$code = strtolower($rate_reply_detail->getElementsByTagName('ServiceType')->item(0)->nodeValue);
if (in_array(strtoupper($code), $this->config->get('fedex_service'))) {
$title = $this->language->get('text_' . $code);
if ($this->config->get('fedex_display_time')) {
$title .= ' (' . $this->language->get('text_eta') . ' ' . date($this->language->get('date_format_short') . ' ' . $this->language->get('time_format'), strtotime($rate_reply_detail->getElementsByTagName('DeliveryTimestamp')->item(0)->nodeValue)) . ')';
}
$total_net_charge = $rate_reply_detail->getElementsByTagName('RatedShipmentDetails')->item(0)->getElementsByTagName('ShipmentRateDetail')->item(0)->getElementsByTagName('TotalNetCharge')->item(0);
$cost = $total_net_charge->getElementsByTagName('Amount')->item(0)->nodeValue;
$currency = $total_net_charge->getElementsByTagName('Currency')->item(0)->nodeValue;
$quote_data[$code] = array(
'code' => 'fedex.' . $code,
'title' => $title,
'cost' => $this->currency->convert($cost, $currency, $this->config->get('config_currency')),
'tax_class_id' => $this->config->get('fedex_tax_class_id'),
'text' => $this->currency->format($this->tax->calculate($this->currency->convert($cost, $currency, $this->currency->getCode()), $this->config->get('fedex_tax_class_id'), $this->config->get('config_tax')), $this->currency->getCode(), 1.0000000)
);
}
}
}
}
$method_data = array();
if ($quote_data || $error) {
$title = $this->language->get('text_title');
if ($this->config->get('fedex_display_weight')) {
$title .= ' (' . $this->language->get('text_weight') . ' ' . $this->weight->format($weight, $this->config->get('fedex_weight_class_id')) . ')';
}
$method_data = array(
'code' => 'fedex',
'title' => $title,
'quote' => $quote_data,
'sort_order' => $this->config->get('fedex_sort_order'),
'error' => $error
);
}
return $method_data;
}
}
?>

Related

Separate sitemap to multiple files

I'm using opencart 2 and default sitemap generator generate everything in one file I mean all products,category,image and so on , its take a long time when you open the file . How can I make something like:
products to be stored in sitemap-product.xml
category to be stored in sitemap-category.xml
image to be stored in sitemap-image.xml
and all to append to sitemap.xml
public function index() {
if ($this->config->get('google_sitemap_status')) {
$output = '<?xml version="1.0" encoding="UTF-8"?>';
$output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';
$this->load->model('catalog/product');
$this->load->model('tool/image');
$products = $this->model_catalog_product->getProducts();
foreach ($products as $product) {
if ($product['image']) {
$output .= '<url>';
$output .= '<loc>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</loc>';
$output .= '<changefreq>weekly</changefreq>';
$output .= '<priority>1.0</priority>';
$output .= '<image:image>';
$output .= '<image:loc>' . $this->model_tool_image->resize($product['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')) . '</image:loc>';
$output .= '<image:caption>' . $product['name'] . '</image:caption>';
$output .= '<image:title>' . $product['name'] . '</image:title>';
$output .= '</image:image>';
$output .= '</url>';
}
}
$this->load->model('catalog/category');
$output .= $this->getCategories(0);
$this->load->model('catalog/manufacturer');
$manufacturers = $this->model_catalog_manufacturer->getManufacturers();
foreach ($manufacturers as $manufacturer) {
$output .= '<url>';
$output .= '<loc>' . $this->url->link('product/manufacturer/info', 'manufacturer_id=' . $manufacturer['manufacturer_id']) . '</loc>';
$output .= '<changefreq>weekly</changefreq>';
$output .= '<priority>0.7</priority>';
$output .= '</url>';
$products = $this->model_catalog_product->getProducts(array('filter_manufacturer_id' => $manufacturer['manufacturer_id']));
foreach ($products as $product) {
$output .= '<url>';
$output .= '<loc>' . $this->url->link('product/product', 'manufacturer_id=' . $manufacturer['manufacturer_id'] . '&product_id=' . $product['product_id']) . '</loc>';
$output .= '<changefreq>weekly</changefreq>';
$output .= '<priority>1.0</priority>';
$output .= '</url>';
}
}
$this->load->model('catalog/information');
$informations = $this->model_catalog_information->getInformations();
foreach ($informations as $information) {
$output .= '<url>';
$output .= '<loc>' . $this->url->link('information/information', 'information_id=' . $information['information_id']) . '</loc>';
$output .= '<changefreq>weekly</changefreq>';
$output .= '<priority>0.5</priority>';
$output .= '</url>';
}
$output .= '</urlset>';
$this->response->addHeader('Content-Type: application/xml');
$this->response->setOutput($output);
}
}
What you can do is simple. The controller you are trying to extend is the url:
index.php?route=feed/google_sitemap
or
index.php?route=extension/feed/google_sitemap if you are using opencart 2.3.x
The above url loads public function index(), so it's the same as:
index.php?route=feed/google_sitemap/index
Now, copy public function index () and create a new function with name products. It should look like this:
public function products() {
if ($this->config->get('google_sitemap_status')) {
$output = '<?xml version="1.0" encoding="UTF-8"?>';
$output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';
$this->load->model('catalog/product');
$this->load->model('tool/image');
$products = $this->model_catalog_product->getProducts();
foreach ($products as $product) {
if ($product['image']) {
$output .= '<url>';
$output .= '<loc>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</loc>';
$output .= '<changefreq>weekly</changefreq>';
$output .= '<priority>1.0</priority>';
$output .= '<image:image>';
$output .= '<image:loc>' . $this->model_tool_image->resize($product['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')) . '</image:loc>';
$output .= '<image:caption>' . $product['name'] . '</image:caption>';
$output .= '<image:title>' . $product['name'] . '</image:title>';
$output .= '</image:image>';
$output .= '</url>';
}
}
$output .= '</urlset>';
$this->response->addHeader('Content-Type: application/xml');
$this->response->setOutput($output);
}
}
Now if call the url:
index.php?route=feed/google_sitemap/products
it should load only the products. It won't create the file you want, but it will create the sitemap xml for products on the fly.
Edit / Additional info :
If you have thousands of products you can add some limits easily.
public function products() {
if ($this->config->get('google_sitemap_status')) {
$output = '<?xml version="1.0" encoding="UTF-8"?>';
$output .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">';
$this->load->model('catalog/product');
$this->load->model('tool/image');
$data = [];
if (isset($this->request->get['start'])) {
$data['start'] = $this->request->get['start'];
} else {
$data['start'] = 0;
}
if (isset($this->request->get['limit'])) {
$data['limit'] = $this->request->get['limit'];
} else {
$data['limit'] = 2000; /* Change the default value for the limit */
}
$products = $this->model_catalog_product->getProducts($data);
foreach ($products as $product) {
if ($product['image']) {
$output .= '<url>';
$output .= '<loc>' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . '</loc>';
$output .= '<changefreq>weekly</changefreq>';
$output .= '<priority>1.0</priority>';
$output .= '<image:image>';
$output .= '<image:loc>' . $this->model_tool_image->resize($product['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height')) . '</image:loc>';
$output .= '<image:caption>' . $product['name'] . '</image:caption>';
$output .= '<image:title>' . $product['name'] . '</image:title>';
$output .= '</image:image>';
$output .= '</url>';
}
}
$output .= '</urlset>';
$this->response->addHeader('Content-Type: application/xml');
$this->response->setOutput($output);
}
}
Let's say that you have 50000 products.
Example of the url to get the first 25000 products:
index.php?route=feed/google_sitemap/products&start=0&limit=25000
Then get the rest 25000 products
index.php?route=feed/google_sitemap/products&start=25000&limit=25000
You can do the same for categories, images, information pages etc.
PS: Of course to load the above urls, you need to add your domain name as prefix :D
Hope this helped you.

Sage Pay Reporting API - generated signature hash not valid

I am trying to invoke the getTransactionDetail end point on sagepay reporting api (https://www.sagepay.co.uk/file/6946/download-document/Reporting_and_Admin_API_Integration_Guideline_31012014.pdf) and the signature I made as per the following instructions:
does not appear to be working, I am getting an invalid signature response.
Here's what I have tried so far:
<?php
$vendor = 'myvendername';
$username = 'my-username';
$password = 'my-password';
$vpstxid = '{my-vpstxid-guid-here}';
$request = [
'command' => 'getTransactionDetail',
'vendor' => $vendor,
'user' => $username,
'vpstxid' => $vpstxid,
];
$signature = _calculate_request_signature($request);
$request_xml = _build_sagepay_request($request, $signature);
$result = _call_sagepay_server('https://test.sagepay.com/access/access.htm', $request_xml);
$xml = simplexml_load_string($result);
$json = json_encode($xml);
$array = json_decode($json,TRUE);
echo '<pre>'; print_r($array); exit;
function _calculate_request_signature($data) {
global $password;
$req = '';
foreach ($data as $key => $value) {
$req .= '<' . $key . '>' . $value . '</' . $key . '>' . PHP_EOL;
}
$req .= '<password>' . $password . '</password>';
return md5($req);
}
function _build_sagepay_request($data, $signature) {
$result = '<vspaccess>' . PHP_EOL;
foreach ($data as $key => $value) {
$result .= "\t" . '<' . $key . '>' . $value . '</' . $key . '>' . PHP_EOL;
}
$result .= "\t" . '<signature>' . $signature . '</signature>' . PHP_EOL;
$result .= '</vspaccess>';
return $result;
}
function _call_sagepay_server($url, $request_xml)
{ ... snipped ... }
Any ideas?
Ok, I've figured it out:
No tabs / PHP_EOL in the request / signature calc, keep it flat one line xml and it works.
function _calculate_request_signature($data) {
global $password;
$req = '';
foreach ($data as $key => $value) {
$req .= '<' . $key . '>' . $value . '</' . $key . '>';
}
$req .= '<password>' . $password . '</password>';
return strtoupper(md5($req));
}
function _build_sagepay_request($data, $signature) {
$result = '<vspaccess>';
foreach ($data as $key => $value) {
$result .= '<' . $key . '>' . $value . '</' . $key . '>';
}
$result .= '<signature>' . $signature . '</signature>';
$result .= '</vspaccess>';
return $result;
}
function _call_sagepay_server($url, $request_xml)
{
global $lastCurlError;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'XML=' . $request_xml);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 45);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
$lastCurlError = curl_errno($curl);
curl_close($curl);
return $result;
}

Create WSDL File For SoapServer EndPoint PHP File

i wanna create wsdl file for my php end point.
this is my php end point class with two function:
class server{
private $UserIdSender;
private $UserIdReciver;
private $Title;
private $Body;
private $BoardId;
private $obj_ticket;
private $obj_ticket_owner;
private $ticket_id;
public function __construct() {
date_default_timezone_set("Asia/Tehran");
require_once "../../diba-modules/conf.php";
require_once "../../diba-modules/functions.php";
require_once "../../diba-include/entities/ticket.php";
require_once "../../diba-include/entities/ticket_owner.php";
$this->obj_ticket = new \entities\ticket(TRUE);
$this->obj_ticket_owner = new \entities\ticket_owner(TRUE);
mb_internal_encoding("UTF-8");
}
/*public board = 17*/
public function SaveTicketFromPortal($Token,$NationalCodeSender , $NationalCodeReciver , $Title , $Body = "" , $BoardId = 17 ){
$this->UserIdSender = get_id_from_national_code($NationalCodeSender);
$this->UserIdReciver = get_id_from_national_code($NationalCodeReciver);
$this->Title = trim(filter_var($Title,FILTER_SANITIZE_STRING));
$this->Body = trim(filter_var($Body,FILTER_SANITIZE_STRING));
$this->BoardId = filter_var($BoardId,FILTER_SANITIZE_NUMBER_INT);
if($this->UserIdSender <= 0 ){
return array("Success" => "-1" , "Message" => "Sender NationalCode Not Found !" );
}elseif($this->UserIdReciver <= 0 ){
return array("Success" => "-1" , "Message" => "Reciver NationalCode Not Found !" );
} elseif(mb_strlen($this->Title)>500){
return array("Success" => "-1" , "Message" => "OverFlow in Ticket Title Variable! Type Of Variable Is String(500) " );
}elseif(mb_strlen($this->Body)>3000){
return array("Success" => "-1" , "Message" => "OverFlow in Ticket Body Variable! Type Of Variable Is String(3000) " );
}elseif(!is_numeric($this->BoardId) ){
return array("Success" => "-1" , "Message" => "BoardId Should Be Number!" );
}else{
$this->ticket_id = $this->obj_ticket->save(NULL, $this->Title, $this->Body, $this->UserIdSender , date("Y-m-d H:i:s"), "" , 3 , 0 , $this->BoardId);
$this->obj_ticket_owner->save(NULL, $this->ticket_id, $this->UserIdReciver, date("Y-m-d H:i:s"), 3, 0, 1);
if($this->obj_ticket->flage && $this->obj_ticket_owner->flage){
$this->obj_ticket->commit(TRUE);
$this->obj_ticket_owner->commit(TRUE);
$boardname = get_board_name($this->BoardId);
$robot_msg = "\xF0\x9F\x93\xA2 Your Ticket Has Been Successfuly Refrenced From Portal. \n\x23\xE2\x83\xA3 $this->ticket_id \n\xF0\x9F\x93\x8B Board $boardname";
send_with_telegram($this->UserIdReciver, $robot_msg,$this->UserIdSender);
return array("Success" => "1" , "Message" => "Your Ticket Has Been Successfuly Refrenced." );
}else{
$this->obj_ticket->commit(FALSE);
$this->obj_ticket_owner->commit(FALSE);
return array("Success" => "-1" , "Message" => "Error In Ticket Referrals!" );
}
}
}
public function SaveTicketFromPortalResponse($Token){
}
}
$params=array("uri"=>"http://127.0.0.1/board/my-webservice/portal/server.php");
$server = new SoapServer(NULL,$params);
$server->setClass("server");
$server->handle();
when i use address "server.php?wsdl" for call my Soap Function from asp.net i recive a error like this :
WSDL generation is no supported yet.!
please help.
its emergency.
thanks a lot.
i found it =>
wsdl.php
<?php
$functions = array();
$serviceName = "My Webservice For Recive Data From Portal";
$functions[] = array("funcName" => "SaveTicketFromPortal",
"doc" => "My Webservice For Recive Data From Portal",
"inputParams" => array(array("name" => "Token", "type" => "string"),
array("name" => "NationalCodeSender", "type" => "string"),
array("name" => "NationalCodeReciver", "type" => "string"),
array("name" => "Title", "type" => "string"),
array("name" => "Body", "type" => "string")
),
"outputParams" => array(array("name" => "Success", "type" => "string"),
array("name" => "Message" ,"type" => "string" )),
"soapAddress" => "http://192.168.10.16/board/my-webservice/portal/server.php"
);
$functions[] = array("funcName" => "SetState",
"doc" => "To Change Ticket State From Todo To Doing And Done",
"inputParams" => array(array("name" => "Token", "type" => "string"),
array("name" => "TicketId", "type" => "string"),
array("name" => "NationalCode", "type" => "string"),
array("name" => "StateId", "type" => "string")),
"outputParams" => array(array("name" => "Success", "type" => "string"),
array("name" => "Message" ,"type" => "string" )),
"soapAddress" => "http://192.168.10.16/board/my-webservice/portal/server.php"
);
if (stristr($_SERVER['QUERY_STRING'], "wsdl")) {
// WSDL request - output raw XML
header("Content-Type: application/soap+xml; charset=utf-8");
echo DisplayXML();
} else {
// Page accessed normally - output documentation
$cp = substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") + 1); // Current page
echo '<!-- Attention: To access via a SOAP client use ' . $cp . '?WSDL -->';
echo '<html>';
echo '<head><title>' . $serviceName . '</title></head>';
echo '<body>';
echo '<h1>' . $serviceName . '</h1>';
echo '<p style="margin-left:20px;">To access via a SOAP client use <code>' . $cp . '?WSDL</code></p>';
// Document each function
echo '<h2>Available Functions:</h2>';
echo '<div style="margin-left:20px;">';
for ($i=0;$i<count($functions);$i++) {
echo '<h3>Function: ' . $functions[$i]['funcName'] . '</h3>';
echo '<div style="margin-left:20px;">';
echo '<p>';
echo $functions[$i]['doc'];
echo '<ul>';
if (array_key_exists("inputParams", $functions[$i])) {
echo '<li>Input Parameters:<ul>';
for ($j=0;$j<count($functions[$i]['inputParams']);$j++) {
echo '<li>' . $functions[$i]['inputParams'][$j]['name'];
echo ' (' . $functions[$i]['inputParams'][$j]['type'];
echo ')</li>';
}
echo '</ul></li>';
}
if (array_key_exists("outputParams", $functions[$i])) {
echo '<li>Output Parameters:<ul>';
for ($j=0;$j<count($functions[$i]['outputParams']);$j++) {
echo '<li>' . $functions[$i]['outputParams'][$j]['name'];
echo ' (' . $functions[$i]['outputParams'][$j]['type'];
echo ')</li>';
}
echo '</ul></li>';
}
echo '</ul>';
echo '</p>';
echo '</div>';
}
echo '</div>';
echo '<h2>WSDL output:</h2>';
echo '<pre style="margin-left:20px;width:800px;overflow-x:scroll;border:1px solid black;padding:10px;background-color:#D3D3D3;">';
echo DisplayXML(false);
echo '</pre>';
echo '</body></html>';
}
exit;
/*****************************************************************************
* Create WSDL XML
* #PARAM xmlformat=true - Display output in HTML friendly format if set false
*****************************************************************************/
function DisplayXML($xmlformat=true) {
global $functions; // Functions that this web service supports
global $serviceName; // Web Service ID
$i = 0; // For traversing functions array
$j = 0; // For traversing parameters arrays
$str = ''; // XML String to output
// Tab spacings
$t1 = ' ';
if (!$xmlformat) $t1 = ' ';
$t2 = $t1 . $t1;
$t3 = $t2 . $t1;
$t4 = $t3 . $t1;
$t5 = $t4 . $t1;
$serviceID = str_replace(" ", "", $serviceName);
// Declare XML format
$str .= '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n\n";
// Declare definitions / namespaces
$str .= '<wsdl:definitions ' . "\n";
$str .= $t1 . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" ' . "\n";
$str .= $t1 . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" ' . "\n";
$str .= $t1 . 'xmlns:s="http://www.w3.org/2001/XMLSchema" ' . "\n";
$str .= $t1 . 'targetNamespace="http://www.darkerwhite.com/" ' . "\n";
$str .= $t1 . 'xmlns:tns="http://www.darkerwhite.com/" ' . "\n";
$str .= $t1 . 'name="' . $serviceID . '" ' . "\n";
$str .= '>' . "\n\n";
// Declare Types / Schema
$str .= '<wsdl:types>' . "\n";
$str .= $t1 . '<s:schema elementFormDefault="qualified" targetNamespace="http://www.darkerwhite.com/">' . "\n";
for ($i=0;$i<count($functions);$i++) {
// Define Request Types
if (array_key_exists("inputParams", $functions[$i])) {
$str .= $t2 . '<s:element name="' . $functions[$i]['funcName'] . 'Request">' . "\n";
$str .= $t3 . '<s:complexType><s:sequence>' . "\n";
for ($j=0;$j<count($functions[$i]['inputParams']);$j++) {
$str .= $t4 . '<s:element minOccurs="1" maxOccurs="1" ';
$str .= 'name="' . $functions[$i]['inputParams'][$j]['name'] . '" ';
$str .= 'type="s:' . $functions[$i]['inputParams'][$j]['type'] . '" />' . "\n";
}
$str .= $t3 . '</s:sequence></s:complexType>' . "\n";
$str .= $t2 . '</s:element>' . "\n";
}
// Define Response Types
if (array_key_exists("outputParams", $functions[$i])) {
$str .= $t2 . '<s:element name="' . $functions[$i]['funcName'] . 'Response">' . "\n";
$str .= $t3 . '<s:complexType><s:sequence>' . "\n";
for ($j=0;$j<count($functions[$i]['outputParams']);$j++) {
$str .= $t4 . '<s:element minOccurs="1" maxOccurs="1" ';
$str .= 'name="' . $functions[$i]['outputParams'][$j]['name'] . '" ';
$str .= 'type="s:' . $functions[$i]['outputParams'][$j]['type'] . '" />' . "\n";
}
$str .= $t3 . '</s:sequence></s:complexType>' . "\n";
$str .= $t2 . '</s:element>' . "\n";
}
}
$str .= $t1 . '</s:schema>' . "\n";
$str .= '</wsdl:types>' . "\n\n";
// Declare Messages
for ($i=0;$i<count($functions);$i++) {
// Define Request Messages
if (array_key_exists("inputParams", $functions[$i])) {
$str .= '<wsdl:message name="' . $functions[$i]['funcName'] . 'Request">' . "\n";
$str .= $t1 . '<wsdl:part name="parameters" element="tns:' . $functions[$i]['funcName'] . 'Request" />' . "\n";
$str .= '</wsdl:message>' . "\n";
}
// Define Response Messages
if (array_key_exists("outputParams", $functions[$i])) {
$str .= '<wsdl:message name="' . $functions[$i]['funcName'] . 'Response">' . "\n";
$str .= $t1 . '<wsdl:part name="parameters" element="tns:' . $functions[$i]['funcName'] . 'Response" />' . "\n";
$str .= '</wsdl:message>' . "\n\n";
}
}
// Declare Port Types
for ($i=0;$i<count($functions);$i++) {
$str .= '<wsdl:portType name="' . $functions[$i]['funcName'] . 'PortType">' . "\n";
$str .= $t1 . '<wsdl:operation name="' . $functions[$i]['funcName'] . '">' . "\n";
if (array_key_exists("inputParams", $functions[$i]))
$str .= $t2 . '<wsdl:input message="tns:' . $functions[$i]['funcName'] . 'Request" />' . "\n";
if (array_key_exists("outputParams", $functions[$i]))
$str .= $t2 . '<wsdl:output message="tns:' . $functions[$i]['funcName'] . 'Response" />' . "\n";
$str .= $t1 . '</wsdl:operation>' . "\n";
$str .= '</wsdl:portType>' . "\n\n";
}
// Declare Bindings
for ($i=0;$i<count($functions);$i++) {
$str .= '<wsdl:binding name="' . $functions[$i]['funcName'] . 'Binding" type="tns:' . $functions[$i]['funcName'] . 'PortType">' . "\n";
$str .= $t1 . '<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />' . "\n";
$str .= $t1 . '<wsdl:operation name="' . $functions[$i]['funcName'] . '">' . "\n";
$str .= $t2 . '<soap:operation soapAction="' . $functions[$i]['soapAddress'] . '#' . $functions[$i]['funcName'] . '" style="document" />' . "\n";
if (array_key_exists("inputParams", $functions[$i]))
$str .= $t2 . '<wsdl:input><soap:body use="literal" /></wsdl:input>' . "\n";
if (array_key_exists("outputParams", $functions[$i]))
$str .= $t2 . '<wsdl:output><soap:body use="literal" /></wsdl:output>' . "\n";
$str .= $t2 . '<wsdl:documentation>' . $functions[$i]['doc'] . '</wsdl:documentation>' . "\n";
$str .= $t1 . '</wsdl:operation>' . "\n";
$str .= '</wsdl:binding>' . "\n\n";
}
// Declare Service
$str .= '<wsdl:service name="' . $serviceID . '">' . "\n";
for ($i=0;$i<count($functions);$i++) {
$str .= $t1 . '<wsdl:port name="' . $functions[$i]['funcName'] . 'Port" binding="tns:' . $functions[$i]['funcName'] . 'Binding">' . "\n";
$str .= $t2 . '<soap:address location="' . $functions[$i]['soapAddress'] . '" />' . "\n";
$str .= $t1 . '</wsdl:port>' . "\n";
}
$str .= '</wsdl:service>' . "\n\n";
// End Document
$str .= '</wsdl:definitions>' . "\n";
if (!$xmlformat) $str = str_replace("<", "<", $str);
if (!$xmlformat) $str = str_replace(">", ">", $str);
if (!$xmlformat) $str = str_replace("\n", "<br />", $str);
return $str;
}
?>

Twitter authentication via OAuth using php cURL

I'm trying to show tweets based on a searchword submitted by a visitor. My code is:
function searchTwitter($query) {
$searchquery = urlencode($query);
//Filter for language
if (isset($_GET['lang'])) {
$langs = array("fr", "en", "es", "de", "it", "pt", "nl", "no", "sv", "fi", "da", "pl", "th", "en-gb");
if(in_array($_GET['lang'], $langs)) {
$lang = '&lang='.$_GET['lang'];
} else {
$lang = "";
}
}
$oauth_hash = '';
$oauth_hash .= 'lang='.$lang.'&';
$oauth_hash .= 'oauth_consumer_key=XXXX&';
$oauth_hash .= 'oauth_nonce=' . time() . '&';
$oauth_hash .= 'oauth_signature_method=HMAC-SHA1&';
$oauth_hash .= 'oauth_timestamp=' . time() . '&';
$oauth_hash .= 'oauth_token=XXXX&';
$oauth_hash .= 'oauth_version=1.0';
$oauth_hash .= 'q='.$searchquery.'&';
$oauth_hash .= 'result_type=recent';
$base = '';
$base .= 'GET';
$base .= '&';
$base .= rawurlencode('https://api.twitter.com/1.1/search/tweets.json');
$base .= '&';
$base .= rawurlencode($oauth_hash);
$key = '';
$key .= rawurlencode('XXXX');
$key .= '&';
$key .= rawurlencode('XXXX');
$signature = base64_encode(hash_hmac('sha1', $base, $key, true));
$signature = rawurlencode($signature);
$oauth_header = '';
$oauth_header .= 'lang="'.$lang.'", ';
$oauth_header .= 'oauth_consumer_key="XXXX", ';
$oauth_header .= 'oauth_nonce="' . time() . '", ';
$oauth_header .= 'oauth_signature="' . $signature . '", ';
$oauth_header .= 'oauth_signature_method="HMAC-SHA1", ';
$oauth_header .= 'oauth_timestamp="' . time() . '", ';
$oauth_header .= 'oauth_token="XXXX", ';
$oauth_header .= 'oauth_version="1.0", ';
$oauth_header .= 'q="'.$searchquery.'", ';
$oauth_header .= 'result_type="recent", ';
$curl_header = array("Authorization: Oauth {$oauth_header}", 'Expect:');
$curl_request = curl_init();
curl_setopt($curl_request, CURLOPT_HTTPHEADER, $curl_header);
curl_setopt($curl_request, CURLOPT_HEADER, false);
curl_setopt($curl_request, CURLOPT_URL, 'https://api.twitter.com/1.1/search/tweets.json? count=100'.$lang.'$q='.$searchquery.'&result_type=recent');
curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
$json_content = curl_exec($curl_request);
curl_close($curl_request);
$tweets = $tweets = json_decode($json_content, true);
print_r($tweets);
I'm getting an error 32: Could not authenticate you. I've searched all over the internet and a lot of people are having this problem, but I can't find the solution. I prefer writing my own script instead of using plugins, because I also want to learn it.

Associate attributes with products in opencart to generate xml file

The past couple of hours I am trying to generate an xml file like this
<?xml version="1.0" encoding="UTF-8"?>
<mywebstore>
<created_at>2010-04-08 12:32</created_at>
<products>
<product>
<id>322233</id>
<name><![CDATA[MadBiker 600 Black Polarized]]></name>
<link><![CDATA[http://www.mywebstore.gr/product/322233]]></link>
<image><![CDATA[http://www.mywebstore.gr/product/322233.jpg]]></image>
<category id="23"><![CDATA[Sports > Extreme Sports]]></category>
<price_with_vat>322.33</price_with_vat>
<manufacturer><![CDATA[SuperGlasses]]></manufacturer>
<description><![CDATA[This is the description.....]]></description>
<weight>350</weight>
<mpn>ZHD332</mpn>
<instock>N</instock>
<availability>Pre-order</availability>
</product>
<product>
...
</product>
</products>
</mywebstore>
from opencart.
I have written this piece of code
<?php
class ControllerFeedSkroutzXml extends Controller {
public function index() {
$this->language->load('feed/skroutz_xml');
if ($this->config->get('skroutz_xml_status')) {
$output = '<?xml version="1.0" encoding="UTF-8"?>';
$output .= '<mywebstore>';
$output .= '<created_at>' . date('Y-m-d H:i') . '</created_at>';
$output .= '<products>';
$this->load->model('catalog/product');
$products = $this->model_catalog_product->getProducts();
foreach ($products as $product) {
$attribute_groups = $this->model_catalog_product->getProductAttributes($product['product_id']);
//print_r($attribute_groups);
if (!empty($attribute_groups)) {
foreach ($attribute_groups as $attribute_group) {
if (!empty($attribute_group)) {
foreach ($attribute_group['attribute'] as $attribute) {
$attribute = array_filter($attribute);
if (!empty($attribute)) {
// [attribute_id] => 13, Color
if ($attribute['attribute_id'] == 13 && $attribute['text'] != '') {
$attribute_color = $attribute['text'];
}
// [attribute_id] => 16, Lens Technology
if ($attribute['attribute_id'] == 16 && $attribute['text'] != '') {
$attribute_lens_technology = $attribute['text'];
}
}
}
}
}
}
if ($product['special']) {
$final_price = number_format((float)$product['special'], 2, '.', '');
} else {
$final_price = number_format((float)$product['price'], 2, '.', '');
}
if ($product['quantity'] > 0) {
$instock = $this->language->get('instock_Y');
} else {
$instock = $this->language->get('instock_N');
}
$output .= '<product>';
$output .= '<id>' . $product['product_id'] . '</id>';
$output .= '<name><![CDATA[' . $this->language->get('category_name') . ' ' . $product['name'] . ' ' . $attribute_color . ' ' . $attribute_lens_technology . ']]></name>';
$output .= '<link><![CDATA[' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . ']]></link>';
$output .= '<image><![CDATA['. HTTP_IMAGE . $product['image'] . ']]></image>';
$output .= '<category id="' . $product['manufacturer_id'] . '"><![CDATA[ ' . $this->language->get('category_name') . ' > ' . $product['manufacturer'] . ' ]]></category>';
$output .= '<price_with_vat>' . $final_price . '</price_with_vat>';
$output .= '<manufacturer><![CDATA[' . $product['manufacturer'] . ']]></manufacturer>';
$output .= '<description><![CDATA[' . $product['meta_description'] . ']]></description>';
$output .= '<instock>' . $instock . '</instock>';
$output .= '<availability>' . $product['stock_status'] . '</availability>';
$output .= '</product>';
}
$output .= '</products>';
$output .= '</mywebstore>';
$this->response->addHeader('Content-Type: application/xml');
$this->response->setOutput($output);
}
}
}
?>
But the block of code that generates the attributes it doesn't work as expected.
A lot of my products don't have attributes (at least not yet), so what I want to accomplish is to show attributes right next to the name of the product
Example
Name: MadBiker 600
Attribute - Color: Black
Attribute - Lens Technology : Polarized
All together <name>MadBiker 600 Black Polarized</name>
Only if a product has attributes!
The above php code generates the <name>MadBiker 600 Black Polarized</name> to all empty of attributes products until it finds the next product with an attribute!
Could someone please point out where is the problem?
Thank you!
You aren't resetting the $attribute_lens_technology and $attribute_color with each iteration of the foreach. You need to reset these after the foreach loop definition
New foreach loop:
foreach ($products as $product) {
$attribute_lens_technology = false;
$attribute_color = false;
$attribute_groups = $this->model_catalog_product->getProductAttributes($product['product_id']);
//print_r($attribute_groups);
if (!empty($attribute_groups)) {
foreach ($attribute_groups as $attribute_group) {
if (!empty($attribute_group)) {
foreach ($attribute_group['attribute'] as $attribute) {
$attribute = array_filter($attribute);
if (!empty($attribute)) {
// [attribute_id] => 13, Color
if ($attribute['attribute_id'] == 13 && $attribute['text'] != '') {
$attribute_color = $attribute['text'];
}
// [attribute_id] => 16, Lens Technology
if ($attribute['attribute_id'] == 16 && $attribute['text'] != '') {
$attribute_lens_technology = $attribute['text'];
}
}
}
}
}
}
if ($attribute_lens_technology === false || $attribute_color === false) {
// Code here such as continue; if you want to skip products without both attributes
}
if ($product['special']) {
$final_price = number_format((float)$product['special'], 2, '.', '');
} else {
$final_price = number_format((float)$product['price'], 2, '.', '');
}
if ($product['quantity'] > 0) {
$instock = $this->language->get('instock_Y');
} else {
$instock = $this->language->get('instock_N');
}
$output .= '<product>';
$output .= '<id>' . $product['product_id'] . '</id>';
$output .= '<name><![CDATA[' . $this->language->get('category_name') . ' ' . $product['name'] . ' ' . $attribute_color . ' ' . $attribute_lens_technology . ']]></name>';
$output .= '<link><![CDATA[' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . ']]></link>';
$output .= '<image><![CDATA['. HTTP_IMAGE . $product['image'] . ']]></image>';
$output .= '<category id="' . $product['manufacturer_id'] . '"><![CDATA[ ' . $this->language->get('category_name') . ' > ' . $product['manufacturer'] . ' ]]></category>';
$output .= '<price_with_vat>' . $final_price . '</price_with_vat>';
$output .= '<manufacturer><![CDATA[' . $product['manufacturer'] . ']]></manufacturer>';
$output .= '<description><![CDATA[' . $product['meta_description'] . ']]></description>';
$output .= '<instock>' . $instock . '</instock>';
$output .= '<availability>' . $product['stock_status'] . '</availability>';
$output .= '</product>';
}
It's easier to write an xml file using simplexml than it is to manually try and output your own.
Nevertheless, here's a simple shorthand if statement to fix to your problem though (if attribute color is empty, it will append an empty string instead:
$output .= !empty($attribute_color) ? '<name><![CDATA[' . $this->language->get('category_name') . ' ' . $product['name'] . ' ' . $attribute_color . ' ' . $attribute_lens_technology . ']]></name>' : '';

Categories