Today started off working on the dev machine with the Magento2 install to push the testing theme forward to the default theme. Apache changes were easy, Magento has weird caching/reindexing things that make it seem like you failed, but leaving it alone for a few moments fixes everything (assuming you have your crons setup). A few touches to pathings that went astray and that was taken care of.
Latter half of the day was spent building up a php interface to the Core Commerce ERP api. Only have 1 client on-boarding using this system and it seems its not super popular, so not spending too much time on it, but I am making everything generic; better safe than sorry.
Below is a basic communication class, mostly for testing purposes at this point. These a logic script above this that handles data parsing/input/output etc etc
<?php
class CoreCommerceCom
{
private $url = null;
private $proxytunnel = false;
private $curlProxy = 0;
private $username = null;
private $password = null;
private $storeName = null;
private $key = null;
function __construct($config)
{
$this->url = $config->url;
$this->proxytunnel = $config->proxytunnel;
$this->curlProzy = $config->curlProxy;
$this->username = $config->username;
$this->password = $config->password;
$this->storeName = $config->storeName;
$this->key = $config->key;
}
private function sendRequest($request)
{
$request=createCall($request);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_PORT, '443');
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT'] );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
if($this->proxytunnel === true){
curl_setopt($curl, CURLOPT_HTTPPROXYTUNNEL, TRUE);
curl_setopt($curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
if($curlProxy) {
curl_setopt($curl, CURLOPT_PROXY, $curlProxy);
}
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
}
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($curl);
if(false === $response){
$err = curl_error($curl);
$errno = curl_errno($curl);
print 'cURL error ' . $errno . ': ' . $err;
}
curl_close($curl);
return $response;
}
private function createCall($action)
{
return '<?xml version="1.0" encoding="utf-8"?>
<Request version="1.0">
<Authentication>
<Username>' . $this->username . '</Username>
<Password>' . $this->password . '</Password>
<StoreName>' . $this->storeName . '</StoreName>
<XmlKey>'. $this->key . '</XmlKey>
</Authentication>
'.$action.'
</Request>';
}
function getOrdersByDate($from, $to)
{
$xml='<SearchCriteria type="Like">
<DateRanges>
<DateRange>
<From>'.$from.'</From>
<To>'.$to.'</To>
</DateRange>
</DateRanges>
</SearchCriteria>';
return sendRequest($xml);
}
function setTracking($externalid, $tracking, $carrier, $method)
{
$xml='<Action>ACTION_TYPE_ORDER_EDIT</Action>
<List length="1">
<Order id="'.$externalid.'">
<Status>ORDER_STATUS_SHIPPED</Status>
<ShippingDate>
<UnixTimeStamp>1235148507</UnixTimeStamp>
</ShippingDate>
<TrackingElement>
<Number><![CDATA['.$tracking.']]></Number>
<Service><![CDATA['.$carrier.']]></Service>
<Method><![CDATA['.$method.']]></Method>
</TrackingElement>
</Order>
</List>';
return sendRequest($xml);
}
function setInventory($externalprodid, $inv)
{
$xml='<Action>ACTION_TYPE_PRODUCT_EDIT</Action>
<List length="1">
<Product id="'.$externalprodid.'">
<InventoryLevel><![CDATA['.$inv.']]></InventoryLevel>
</Product>
</List>';
return sendRequest($xml);
}
}
No comments:
Post a Comment