Good morning, I am a php programmer but with no knowledge of Magento modules, I need to know how I can use this code made in php with the Channeladvisor API in a Magento 2 module. This code Syncronice Channeladvior inventary with other Unknown site..... i want be Magento2, I would be very grateful to know how the file structure would be, I can already handle a basic module, but I can't find a way to make that code work in Mgwnto2
PHP Code:
<?php
//Initialize test variables
$sku='zz-cf002-e';
$title='Game Set';
$subtitle='';
$shortdescription='Some Descriptive Text';
$description='More Descriptive Text';
$weight=1.1;
$total=14;
$cost=99;
$retailprice=99;
$startingprice=99;
$takeItprice=99;
$secondchanceofferprice=99;
$storeprice=99;
$classname='mahjong';
$attname1='Bullet_List';
$attvalue1='A list of bullet points';
$attname2='SHIPPING_BESTRATE';
$attvalue2='11.77';
$attname3='SHIPPING_BESTRATESERVICE';
$attvalue3='UPS Ground';
$image1='ZZ-CF002-E_a.jpg';
$image2='ZZ-CF002-E_b.jpg';
$image3='ZZ-CF002-E_c.jpg';
$image4='ZZ-CF002-E_d.jpg';
$usa_48_ups_ground=10;
$usa_48_ups_ground_2=7;
$usa_48_ups_2day=30;
$usa_48_ups_2day_2=15;
//Create the XML set
require_once('nusoap.php');
$client = new soapclient_xxx('https://api.channeladvisor.com/
ChannelAdvisorAPI/v1/inventoryService.asmx?WSDL', true );
$err = $client->getError();
if ($err)
{
echo 'Constructor error' . $err . '';
}
$developerKey = 'XXX';
$password = 'XXX';
$headers = '<APICredentials xmlns="http://api.channeladvisor.com/
webservices/">
<DeveloperKey>'.$developerKey.'</DeveloperKey>
<Password>'.$password.'</Password>
</APICredentials> ';
$arrData = array('accountID'=>'XXX',
'item'=>array(
'Sku'=>$sku,
'Title'=>$title,
'Subtitle'=>$subtitle,
'ShortDescription'=>$shortdescription,
'Description'=>$description,
'Weight'=>$weight,
'QuantityInfo'=>array(
'UpdateType'=>'Absolute', 'Total'=>$total),
'PriceInfo'=>array(
'Cost'=>number_format($cost, 2),
'RetailPrice'=>number_format($retailprice, 2),
'StartingPrice'=>number_format($startingprice, 2),
'ReservePrice'=>0,
'TakeItPrice'=>number_format($takeItprice, 2),
'SecondChanceOfferPrice'=>number_format($secondchanceofferprice, 2),
'StorePrice'=>number_format($storeprice, 2)),
'ClassificationInfo'=>array(
'Name'=>$classname, 'AttributeList'=>array(
'ClassificationAttributeInfo___1'=>array(
'Name'=>$attname1, 'Value'=>$attvalue1),
'ClassificationAttributeInfo___2'=>array(
'Name'=>$attname2, 'Value'=>$attvalue2),
'ClassificationAttributeInfo___3'=>array(
'Name'=>$attname3, 'Value'=>$attvalue3))),
'ImageList'=>array(
'ImageInfoSubmit___1'=>array(
'PlacementName'=>'ITEMIMAGEURL1',
'FilenameOrUrl'=>$image1),
'ImageInfoSubmit___2'=>array(
'PlacementName'=>'ITEMIMAGEURL2',
'FilenameOrUrl'=>$image2),
'ImageInfoSubmit___3'=>array(
'PlacementName'=>'ITEMIMAGEURL3',
'FilenameOrUrl'=>$image3),
'ImageInfoSubmit___4'=>array(
'PlacementName'=>'ITEMIMAGEURL4',
'FilenameOrUrl'=>$image4)),
'ShippingInfo'=>array(
'DistributionCenterCode'=>'Alhambra', 'ShippingRateList' =>array(
'ShippingRateInfo___1'=>array(
'DestinationZoneName'=>'USA48',
'CarrierCode'=>'* UPS',
'ClassCode'=>'GROUND',
'FirstItemRate'=>$usa_48_ups_ground,
'AdditionalItemRate'=>$usa_48_ups_ground_2,
'FirstItemHandlingRate'=>0,
'AdditionalItemHandlingRate'=>0,
'FreeShippingIfBuyItNow'=>'false',
'FirstItemRateAttribute'=>'Price',
'AdditionalItemRateAttribute'=>'Price'),
'ShippingRateInfo___2'=>array(
'DestinationZoneName'=>'USA48',
'CarrierCode'=>'UPS',
'ClassCode'=>'2DAY',
'FirstItemRate'=>$usa_48_ups_2day,
'AdditionalItemRate'=>$usa_48_ups_2day_2,
'FirstItemHandlingRate'=>0,
'AdditionalItemHandlingRate'=>0,
'FreeShippingIfBuyItNow'=>'false',
'FirstItemRateAttribute'=>'Price',
'AdditionalItemRateAttribute'=>'Price'))),
));
//fix repeating fields prior to send (eliminate ___1, ___2, etc.)
function array2xml($arrData, $level) {
$xml = '';
foreach( $arrData as $key => $value ) {
$spacer = '';
for ($i = 0; $i < $level; $i++) { $spacer .= "\t"; }
if ( is_array( $value ) ) {
if (preg_match("/^(.+)___\d+$/", $key, $m)) {
$xml .= $spacer . "<" . $m[1] . ">\n" . array2xml($value, $level
+1) . $spacer . "</" . $m[1] . ">\n";
} else {
$xml .= $spacer . "<" . $key . ">\n" . array2xml($value, $level
+1) . $spacer . "</" . $key . ">\n";
}
} else {
$xml .= $spacer . "<" . $key . ">" . $value . "</" . $key . ">\n";
}
}
return $xml;
}
//apply the function
$cleanedxml = '<SynchInventoryItem xmlns="http://
api.channeladvisor.com/webservices/">' . "\n" .
array2xml($arrData, 0) .
'</SynchInventoryItem>' . "\n";
// Call the SOAP method and send
$result = $client->call('SynchInventoryItem', $cleanedxml, false,
false, $headers);
//Print out the results
if ($client->fault)
{
echo 'Fault';
print_r($result);
echo '';
}
else
{
$err = $client->getError();
if ($err)
{
echo 'Error' . $err . '';
}
else
{
echo 'Result';
print_r($result);
echo '';
}
}
echo "<hr>";
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</
pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</
pre>';
?>
tnks for help