· 6 years ago · Jun 06, 2019, 10:20 PM
1<?php
2/**
3 * @version [2.0.0.0] [Supported opencart version 2.3.x.x]
4 * @category Webkul
5 * @package Opencart-Amazon Connector
6 * @author [Webkul] <[<http://webkul.com/>]>
7 * @copyright Copyright (c) 2010-2017 Webkul Software Private Limited (https://webkul.com)
8 * @license https://store.webkul.com/license.html
9 */
10class Amazonconnector {
11 /*
12 contain product information
13 */
14 public $product = [];
15
16 // to get the language index according to amazon country language
17 protected $marketplaceLanguageArray = [
18 'DE' => [
19 'Artikelbezeichnung' => 'item-name',
20 'Artikelbeschreibung' => 'item-description',
21 'H?ndler-SKU' => 'seller-sku',
22 'Preis' => 'price',
23 'Menge' => 'quantity',
24 'image-url' => 'image-url',
25 'ASIN 1' => 'asin1',
26 ],
27
28 'IN' => [
29 'item-name' => 'item-name',
30 'item-description' => 'item-description',
31 'seller-sku' => 'seller-sku',
32 'price' => 'price',
33 'quantity' => 'quantity',
34 'image-url' => 'image-url',
35 'asin1' => 'asin1',
36 ],
37 ];
38 /*
39 contain feed type of product
40 */
41 public $feedType;
42
43
44 public function __construct($registry) {
45 $this->registry = $registry;
46 $this->config = $registry->get('config');
47 $this->currency = $registry->get('currency');
48 $this->cache = $registry->get('cache');
49 $this->db = $registry->get('db');
50 $this->request = $registry->get('request');
51 $this->session = $registry->get('session');
52 }
53
54 /**
55 * [getListMarketplaceParticipations to get the marketplace participations list]
56 * @param array $data [description]
57 * @return [type] [description]
58 */
59 public function getListMarketplaceParticipations($data = array()){
60 $results = array();
61 $accountDetails = array(
62 'Action' => 'ListMarketplaceParticipations',
63 'wk_amazon_connector_access_key_id' => $data['wk_amazon_connector_access_key_id'],
64 'wk_amazon_connector_seller_id' => $data['wk_amazon_connector_seller_id'],
65 'wk_amazon_connector_secret_key' => $data['wk_amazon_connector_secret_key'],
66 'wk_amazon_connector_country' => $data['wk_amazon_connector_country'],
67 );
68
69 $returnData = $this->checkConnection($accountDetails, $XMLdata = true);
70
71 if(isset($returnData->ListMarketplaceParticipationsResult->ListMarketplaces->Marketplace)){
72 foreach ($returnData->ListMarketplaceParticipationsResult->ListMarketplaces->Marketplace as $key => $store_details) {
73 $makeStoreArray = array();
74 $makeStoreArray = (array)$store_details;
75 if($makeStoreArray['MarketplaceId'] == $data['wk_amazon_connector_marketplace_id']){
76 $results['currency_code'] = $makeStoreArray['DefaultCurrencyCode'];
77 }
78 }
79 }else if(isset($returnData->Error->Message)){
80 $results['error_message'] = $returnData->Error->Message;
81 $results['error'] = true;
82 }else{
83 $results['error'] = true;
84 }
85 return $results;
86 }
87
88 /**
89 * [checkConnection to check the connection with the amazon site based on country code]
90 * @param [type] $data [description]
91 * @param boolean $XMLdata [description]
92 * @return [type] [description]
93 */
94 public function checkConnection($data, $XMLdata = true)
95 {
96 $connectionDetails = array();
97 $connectionDetails['Action'] = $data['Action'];
98 $connectionDetails["Version"] = "2011-07-01";
99 $connectionDetails["Timestamp"] = gmdate("Y-m-d\TH:i:s\Z");
100 $connectionDetails['SignatureVersion'] = '2';
101 $connectionDetails['SignatureMethod']= 'HmacSHA256';
102 $connectionDetails["AWSAccessKeyId"] = $data['wk_amazon_connector_access_key_id'];
103 $connectionDetails['SellerId'] = $data['wk_amazon_connector_seller_id'];
104 $connectionDetails['Secretkey'] = $data['wk_amazon_connector_secret_key'];
105 $connectionDetails['CountryCode'] = $data['wk_amazon_connector_country'];
106 ksort($connectionDetails);
107
108 $curlOptions = $this->setCurlOptions($connectionDetails);
109 $curlHandle = curl_init();
110 curl_setopt_array($curlHandle, $curlOptions);
111 $curlResult = curl_exec($curlHandle);
112
113 if (($curlResult = curl_exec($curlHandle)) == false) {
114 $res = false;
115 } else {
116 $res = true;
117 }
118
119 if (!$res) {
120 return (false);
121 }
122
123 curl_close($curlHandle);
124
125 if ($XMLdata) {
126 try {
127 $resultXML = new \SimpleXMLElement($curlResult);
128 return ($resultXML);
129 } catch (\Exception $e) {
130 return false;
131 }
132 } else {
133 return ($curlResult);
134 }
135 }
136
137 /**
138 * [setCurlOptions make the amazon call url]
139 * @param array $data [description]
140 */
141 public function setCurlOptions($data = array())
142 {
143 $type = '/' . trim('Sellers');
144 $URL = $this->getAmazonURL($data['CountryCode']);
145
146 $canonicalizedData = [];
147 foreach ($data as $datakey => $dataval) {
148 if(($datakey != 'CountryCode') && ($datakey != 'Secretkey')){
149 $datakey = str_replace("%7E", "~", rawurlencode($datakey));
150 $dataval = str_replace("%7E", "~", rawurlencode($dataval));
151 $canonicalizedData[] = $datakey . "=" . $dataval;
152 }
153 }
154 $canonicalizedData = implode("&", $canonicalizedData);
155 $signString = "POST"."\n".$URL."\n".$type."\n".$canonicalizedData;
156
157 $pacSignature = base64_encode(hash_hmac("sha256", $signString, $data['Secretkey'], true));
158 $pacSignature = str_replace("%7E", "~", rawurlencode($pacSignature));
159
160 $curlOptions = [
161 CURLOPT_POST => true,
162 CURLOPT_RETURNTRANSFER => true,
163 ];
164
165 $curlOptions[CURLOPT_URL] = "https://" . $URL . $type;
166 $curlOptions[CURLOPT_POSTFIELDS] = $canonicalizedData . "&Signature=" . $pacSignature;
167 $curlOptions[CURLOPT_SSL_VERIFYPEER] = false;
168 $curlOptions[CURLOPT_VERBOSE] = false;
169
170 return $curlOptions;
171 }
172
173 /**
174 * [getAmazonURL - get URL by country iso]
175 * @return [type] [description]
176 */
177 public function getAmazonURL($accountCountryCode = false)
178 {
179 if ($accountCountryCode == 'US') {
180 return ('mws.amazonservices.com');
181 } elseif ($accountCountryCode == 'CA') {
182 //return ('mws.amazonservices.ca');
183 return ('mws.amazonservices.com');
184 } elseif ($accountCountryCode == 'JP') {
185 return ('mws.amazonservices.jp');
186 } elseif ($accountCountryCode == 'MX') {
187 //return ('mws.amazonservices.com.mx');
188 return ('mws.amazonservices.com');
189 } elseif ($accountCountryCode == 'CN') {
190 return ('mws.amazonservices.com.cn');
191 } elseif ($accountCountryCode == 'IN') {
192 return ('mws.amazonservices.in');
193 } elseif ($accountCountryCode == 'DE' || $accountCountryCode == 'ES' || $accountCountryCode == 'FR' || $accountCountryCode == 'IT' || $accountCountryCode == 'UK' || $accountCountryCode == 'GB' || $accountCountryCode == 'AT') {
194 return ('mws-eu.amazonservices.com');
195 } elseif ($accountCountryCode == 'AU') {
196 return ('mws.amazonservices.com.au');
197 } else {
198 return false;
199 }
200 }
201
202 /**
203 * [getReportFinal generate the product list]
204 * @param [type] $productGeneratedReportId [description]
205 * @param boolean $accountId [description]
206 * @return [type] [description]
207 */
208 public function getReportFinal($productGeneratedReportId, $accountDetails = array()){
209 if ($productGeneratedReportId) {
210 $getReportContent = '';
211 $finalReportArray = array();
212
213 $getReportContent = $this->getReport($productGeneratedReportId, $accountDetails['id']);
214
215 if ($getReportContent != '') {
216 //Get report data in array according to country
217 if ($accountDetails['wk_amazon_connector_country'] == 'FR') { //France Fr language
218 $finalReportArray = $this->getReportDataFRLanguage($getReportContent);
219 } elseif ($accountDetails['wk_amazon_connector_country'] == 'ES') { //Spain ES language
220 $finalReportArray = $this->getReportDataESLanguage($getReportContent);
221 } elseif ($accountDetails['wk_amazon_connector_country'] == 'DE') { //Germany(Dutch) DE language
222 $finalReportArray = $this->getReportDataDELanguage($getReportContent);
223 } else { //For EN language
224 $finalReportArray = $this->getReportDataENLanguage($getReportContent);
225 }
226 }
227 return $finalReportArray;
228 }
229 }
230
231 /**
232 * [getReportDataENLanguage - Get report data in array if report is in germany language
233 * @param [type] $reportContent [Flat content of report]
234 * @return [array] [report data]
235 */
236 public function getReportDataDELanguage($reportContent)
237 {
238 $finalReportArr = array();
239 $reportContent = str_replace( array( "\n" , "\t" ) , array( "[NEW*LINE]" , "[tAbul*Ator]" ) , $reportContent );
240 $reportArr = explode("[NEW*LINE]", $reportContent);
241
242 if ($reportArr) {
243 $reportHeadingArr = explode("[tAbul*Ator]", utf8_encode($reportArr[0]));
244
245 foreach ($reportArr as $reportKey => $reportItem) {
246 if (!empty($reportItem) && $reportKey != 0) {
247 // all content except heading part
248 $reportDataArr = explode("[tAbul*Ator]", $reportItem);
249
250 if ($reportDataArr) {
251 for ($rowi=0; $rowi<count($reportHeadingArr); $rowi++) {
252 if ($reportHeadingArr[$rowi] == 'Artikelbezeichnung') {
253 $finalReportArr[$reportKey]['item-name'] = utf8_encode($reportDataArr[$rowi]);
254 }
255 elseif ($reportHeadingArr[$rowi] == 'Artikelbeschreibung') {
256 $finalReportArr[$reportKey]['item-description'] = utf8_encode($reportDataArr[$rowi]);
257 }
258 elseif ($reportHeadingArr[$rowi] == 'Händler-SKU') {
259 $finalReportArr[$reportKey]['seller-sku'] = $reportDataArr[$rowi];
260 }
261 elseif ($reportHeadingArr[$rowi] == 'Produkt-ID') {
262 $finalReportArr[$reportKey]['product-id'] = $reportDataArr[$rowi];
263 }
264 elseif ($reportHeadingArr[$rowi] == 'Preis') {
265 $finalReportArr[$reportKey]['price'] = $reportDataArr[$rowi];
266 }
267 elseif ($reportHeadingArr[$rowi] == 'Menge') {
268 $finalReportArr[$reportKey]['quantity'] = $reportDataArr[$rowi];
269 }
270 elseif ($reportHeadingArr[$rowi] == 'ASIN 1') {
271 $finalReportArr[$reportKey]['asin1'] = $reportDataArr[$rowi];
272 }
273 elseif ($reportHeadingArr[$rowi] == 'fulfillment-channel') {
274 $finalReportArr[$reportKey]['fulfillment-channel'] = $reportDataArr[$rowi];
275 }
276 elseif ($reportHeadingArr[$rowi] == 'Quantity Available') { //For AFN report
277 $finalReportArr[$reportKey]['Quantity Available'] = $reportDataArr[$rowi];
278 }
279 elseif ($reportHeadingArr[$rowi] == 'asin') { //For AFN report
280 $finalReportArr[$reportKey]['asin'] = $reportDataArr[$rowi];
281 } else {
282 $finalReportArr[$reportKey][$reportHeadingArr[$rowi]] = $reportDataArr[$rowi];
283 }
284 }
285 }
286 }
287 }
288 }
289 return $finalReportArr;
290 }
291
292 /**
293 * [getReportDataENLanguage - Get report data in array if report is in English language
294 * @param [type] $reportContent [Flat content of report]
295 * @return [array] [report data]
296 */
297 public function getReportDataENLanguage($reportContent)
298 {
299 $finalReportArr = array();
300 $reportContent = str_replace( array( "\n" , "\t" ) , array( "[NEW*LINE]" , "[tAbul*Ator]" ) , $reportContent );
301 $reportArr = explode("[NEW*LINE]", $reportContent);
302
303 if (!empty($reportArr)) {
304 $reportHeadingArr = explode("[tAbul*Ator]", $reportArr[0]);
305
306 foreach ($reportArr as $reportKey => $reportItem) {
307 if (!empty($reportItem) && $reportKey != 0) {
308 // all content except heading part
309 $reportDataArr = explode("[tAbul*Ator]", $reportItem);
310
311 if (!empty($reportDataArr)) {
312 for ($rowi = 0; $rowi < count($reportHeadingArr); $rowi++) {
313 if ($reportHeadingArr[$rowi] == 'item-name') {
314 $finalReportArr[$reportKey]['item-name'] = utf8_encode($reportDataArr[$rowi]);
315 }
316 elseif ($reportHeadingArr[$rowi] == 'item-description') {
317 $finalReportArr[$reportKey]['item-description'] = utf8_encode($reportDataArr[$rowi]);
318 }
319 elseif ($reportHeadingArr[$rowi] == 'seller-sku') {
320 $finalReportArr[$reportKey]['seller-sku'] = $reportDataArr[$rowi];
321 }
322 elseif ($reportHeadingArr[$rowi] == 'product-id') {
323 $finalReportArr[$reportKey]['product-id'] = $reportDataArr[$rowi];
324 }
325 elseif ($reportHeadingArr[$rowi] == 'price') {
326 $finalReportArr[$reportKey]['price'] = $reportDataArr[$rowi];
327 }
328 elseif ($reportHeadingArr[$rowi] == 'quantity') {
329 $finalReportArr[$reportKey]['quantity'] = $reportDataArr[$rowi];
330 }
331 elseif ($reportHeadingArr[$rowi] == 'asin1') {
332 $finalReportArr[$reportKey]['asin1'] = $reportDataArr[$rowi];
333 }
334 elseif ($reportHeadingArr[$rowi] == 'fulfillment-channel') {
335 $finalReportArr[$reportKey]['fulfillment-channel'] = $reportDataArr[$rowi];
336 }
337 elseif ($reportHeadingArr[$rowi] == 'Quantity Available') { //For AFN report
338 $finalReportArr[$reportKey]['Quantity Available'] = $reportDataArr[$rowi];
339 }
340 elseif ($reportHeadingArr[$rowi] == 'asin') { //For AFN report
341 $finalReportArr[$reportKey]['asin'] = $reportDataArr[$rowi];
342 } else {
343 $finalReportArr[$reportKey][$reportHeadingArr[$rowi]] = $reportDataArr[$rowi];
344 }
345 }
346 }
347 }
348 }
349 }
350 return $finalReportArr;
351 }
352
353 /**
354 * [getReportDataFRLanguage - Get report data in array if report is in French language
355 * @param [type] $reportContent [Flat content of report]
356 * @return [array] [report data]
357 */
358 public function getReportDataFRLanguage($reportContent)
359 {
360 $finalReportArr = array();
361
362 $reportArr = preg_split("/[\n]/", $reportContent);
363 if ($reportArr) {
364 $reportHeadingArr = preg_split("/[\t]/", $reportArr[0]);
365 foreach ($reportArr as $reportKey => $reportItem) {
366 if (!empty($reportItem) && $reportKey != 0) {
367 // all content except heading part
368 $reportDataArr = preg_split("/[\t]/", $reportItem);
369 if ($reportDataArr) {
370 for ($rowi=0; $rowi<count($reportHeadingArr); $rowi++) {
371 if ($reportHeadingArr[$rowi] == 'item-name' || $reportHeadingArr[$rowi] == 'nom-produit') {
372 $reportDataArr[$rowi] = mb_convert_encoding($reportDataArr[$rowi], "UTF-8", "HTML-ENTITIES");
373 $finalReportArr[$reportKey]['item-name'] = json_encode($reportDataArr[$rowi]);
374 }
375 elseif ($reportHeadingArr[$rowi] == 'item-description' || $reportHeadingArr[$rowi] == 'description-article') {
376 $reportDataArr[$rowi] = mb_convert_encoding($reportDataArr[$rowi], "UTF-8", "HTML-ENTITIES");
377 $finalReportArr[$reportKey]['item-description'] = json_encode($reportDataArr[$rowi]);
378 }
379 elseif ($reportHeadingArr[$rowi] == 'seller-sku' || $reportHeadingArr[$rowi] == 'sku-vendeur') {
380 $finalReportArr[$reportKey]['seller-sku'] = $reportDataArr[$rowi];
381 }
382 elseif ($reportHeadingArr[$rowi] == 'price' || $reportHeadingArr[$rowi] == 'prix') {
383 $finalReportArr[$reportKey]['price'] = $reportDataArr[$rowi];
384 }
385 elseif ($reportHeadingArr[$rowi] == 'quantity' || preg_match("/\bquantit\b/i", $reportHeadingArr[$rowi])) {
386 $finalReportArr[$reportKey]['quantity'] = $reportDataArr[$rowi];
387 }
388 elseif ($reportHeadingArr[$rowi] == 'asin1') {
389 $finalReportArr[$reportKey]['asin1'] = $reportDataArr[$rowi];
390 }
391 elseif ($reportHeadingArr[$rowi] == 'canal-traitement') {
392 $finalReportArr[$reportKey]['fulfillment-channel'] = $reportDataArr[$rowi];
393 }
394 elseif ($reportHeadingArr[$rowi] == 'Quantity Available'
395 || (preg_match("/\bquantit\b/i", $reportHeadingArr[$rowi]) && preg_match("/\battente\b/i", $reportHeadingArr[$rowi]))) { //For AFN report
396 $finalReportArr[$reportKey]['Quantity Available'] = $reportDataArr[$rowi];
397 }
398 elseif ($reportHeadingArr[$rowi] == 'asin') { //For AFN report
399 $finalReportArr[$reportKey]['asin'] = $reportDataArr[$rowi];
400 } else {
401 $finalReportArr[$reportKey][$reportHeadingArr[$rowi]] = $reportDataArr[$rowi];
402 }
403 }
404 }
405 }
406 }
407 }
408
409 return $finalReportArr;
410 }
411
412 /**
413 * [getReportDataESLanguage - Get report data in array if report is in Spanish language
414 * @param [type] $reportContent [Flat content of report]
415 * @return [array] [report data]
416 */
417 public function getReportDataESLanguage($reportContent)
418 {
419 $finalReportArr = array();
420
421 $reportArr = preg_split("/[\n]/", $reportContent);
422 if ($reportArr) {
423 $reportHeadingArr = preg_split("/[\t]/", $reportArr[0]);
424 foreach ($reportArr as $reportKey => $reportItem) {
425 if (!empty($reportItem) && $reportKey != 0) {
426 // all content except heading part
427 $reportDataArr = preg_split("/[\t]/", $reportItem);
428 if ($reportDataArr) {
429 for ($rowi=0; $rowi<count($reportHeadingArr); $rowi++) {
430 if ($reportHeadingArr[$rowi] == 'item-name' || preg_match("/\btulo del producto\b/i", $reportHeadingArr[$rowi])) {
431 $reportDataArr[$rowi] = mb_convert_encoding($reportDataArr[$rowi], "UTF-8", "HTML-ENTITIES");
432 $finalReportArr[$reportKey]['item-name'] = json_encode($reportDataArr[$rowi]);
433 }
434 elseif ($reportHeadingArr[$rowi] == 'item-description' || preg_match("/\bDescripci\b/i", $reportHeadingArr[$rowi])) {
435 $reportDataArr[$rowi] = mb_convert_encoding($reportDataArr[$rowi], "UTF-8", "HTML-ENTITIES");
436 $finalReportArr[$reportKey]['item-description'] = json_encode($reportDataArr[$rowi]);
437 }
438 elseif ($reportHeadingArr[$rowi] == 'seller-sku' || $reportHeadingArr[$rowi] == 'SKU del vendedor') {
439 $finalReportArr[$reportKey]['seller-sku'] = $reportDataArr[$rowi];
440 }
441 elseif ($reportHeadingArr[$rowi] == 'price' || $reportHeadingArr[$rowi] == 'Precio') {
442 $finalReportArr[$reportKey]['price'] = $reportDataArr[$rowi];
443 }
444 elseif ($reportHeadingArr[$rowi] == 'quantity' || $reportHeadingArr[$rowi] == 'Cantidad') {
445 $finalReportArr[$reportKey]['quantity'] = $reportDataArr[$rowi];
446 }
447 elseif ($reportHeadingArr[$rowi] == 'asin1' || $reportHeadingArr[$rowi] == 'ASIN 1') {
448 $finalReportArr[$reportKey]['asin1'] = $reportDataArr[$rowi];
449 }
450 elseif ($reportHeadingArr[$rowi] == 'fulfillment-channel' || preg_match("/\bCanal de gesti\b/i", $reportHeadingArr[$rowi])) {
451 $finalReportArr[$reportKey]['fulfillment-channel'] = $reportDataArr[$rowi];
452 }
453 elseif ($reportHeadingArr[$rowi] == 'Quantity Available') { //For AFN report
454 $finalReportArr[$reportKey]['Quantity Available'] = $reportDataArr[$rowi];
455 }
456 elseif ($reportHeadingArr[$rowi] == 'asin') { //For AFN report
457 $finalReportArr[$reportKey]['asin'] = $reportDataArr[$rowi];
458 } else {
459 $finalReportArr[$reportKey][$reportHeadingArr[$rowi]] = $reportDataArr[$rowi];
460 }
461 }
462 }
463 }
464 }
465 }
466
467 return $finalReportArr;
468 }
469
470 /**
471 * [loadFile to load amazon mws api file to execute functoinality]
472 * @param [string] $type [file type Ex order,product etc]
473 * @param [string] $filename [name of the file that need to be loaded]
474 */
475 public function loadFile($type, $filename)
476 {
477 $path = DIR_APPLICATION.'../Lib'.'/amazon/';
478 include_once($path.'amazon'.$type.'/src/MarketplaceWebService'.$type.'/Samples/'.$filename.'.php');
479 }
480
481 public function getReport($generatedReportId, $accountId = false)
482 {
483 $this->loadFile('', 'GetReportSample');
484 $config = $this->_getAccountConfigData($accountId);
485 $config['reportId'] = $generatedReportId;
486 $Getreport = new \Getreport($config);
487 $report = $Getreport->invokeGetReport($Getreport->service, $Getreport->request);
488 return $report;
489 }
490
491 /**
492 * [requestReport to get request id before sync product from amazon]
493 * @param [type] $reportType [description]
494 * @param boolean $accountId [description]
495 * @return [type] [description]
496 */
497 public function requestReport($reportType, $accountId = false)
498 {
499 $this->loadFile('', 'RequestReportSample');
500 $config = $this->_getAccountConfigData($accountId);
501 $config['reportType'] = $reportType;
502 $requestReport = new \Requestreport($config);
503 $request = $requestReport->invokeRequestReport($requestReport->service, $requestReport->request);
504 return $request;
505 }
506 /**
507 * [GetReportRequestList to get report request list id based on report id]
508 * @param [type] $requestId [description]
509 * @param [type] $accountId [description]
510 */
511 public function GetReportRequestList($requestId, $accountId)
512 {
513 $this->loadFile('', 'GetReportRequestListSample');
514 $config = $this->_getAccountConfigData($accountId);
515 $config['requestId'] = $requestId;
516 $requestReport = new \GetReportRequestList($config);
517 $request = $requestReport->invokeGetReportRequestList($requestReport->service, $requestReport->request);
518 return $request;
519 }
520
521
522 /**
523 * [_getAccountConfigData to get module config setting]
524 * @param boolean $amazon_AccountId [amazon account id]
525 * @return [type] [array of config data]
526 */
527 public function _getAccountConfigData($amazon_AccountId = false)
528 {
529 $results = false;
530 if($amazon_AccountId){
531 if($accountInfo = $this->getAccountDetails(array('account_id' => $amazon_AccountId))){
532 if($countryDetails = $this->getAmazonServiceUrlAndMarketplaceId($accountInfo['wk_amazon_connector_country'])){
533 $results = [
534 'sellerId' => $accountInfo['wk_amazon_connector_seller_id'],
535 'marketplaceId' => $accountInfo['wk_amazon_connector_marketplace_id'],
536 'accessKeyId' => $accountInfo['wk_amazon_connector_access_key_id'],
537 'secretKey' => $accountInfo['wk_amazon_connector_secret_key'],
538 'applicationName' => 'testmarket',
539 'applicationVersion' => '1.0.0',
540 'countryMarketplaceId'=> $countryDetails['marketplaceId'],
541 'serviceUrl' => $countryDetails['serviceUrl']
542 ];
543 }
544 }
545 }
546 return $results;
547 }
548
549 /**
550 * [getAccountDetails to get account complete details]
551 * @param boolean $amazon_AccountId [description]
552 * @return [type] [description]
553 */
554 public function getAccountDetails($data = array()){
555 $sql = "SELECT * FROM ".DB_PREFIX."amazon_accounts WHERE 1 ";
556
557 if(!empty($data['account_id'])){
558 $sql .= "AND id = '".(int)$data['account_id']."' ";
559 }
560
561 if(!empty($data['report_id'])){
562 $sql .= "AND wk_amazon_connector_listing_report_id = '".$this->db->escape($data['report_id'])."' ";
563 }
564 $sql .= " ORDER BY id ASC ";
565 $result = $this->db->query($sql)->row;
566
567 return $result;
568 }
569
570
571 public function getAmazonServiceUrlAndMarketplaceId($accountCountryCode = false)
572 {
573 $countryCodeInfo = [
574 'US'=>['serviceUrl'=>'https://mws.amazonservices.com', 'marketplaceId'=>'ATVPDKIKX0DER'],
575 'UK'=>['serviceUrl'=>'https://mws-eu.amazonservices.com', 'marketplaceId'=>'A1F83G8C2ARO7P'],
576 'DE'=>['serviceUrl'=>'https://mws-eu.amazonservices.com', 'marketplaceId'=>'A1PA6795UKMFR9'],
577 'FR'=>['serviceUrl'=>'https://mws-eu.amazonservices.com', 'marketplaceId'=>'A13V1IB3VIYZZH'],
578 'IT'=>['serviceUrl'=>'https://mws-eu.amazonservices.com', 'marketplaceId'=>'APJ6JRA9NG5V4'],
579 'JP'=>['serviceUrl'=>'https://mws.amazonservices.jp', 'marketplaceId'=>'A1VC38T7YXB528'],
580 'CN'=>['serviceUrl'=>'https://mws.amazonservices.com.cn', 'marketplaceId'=>'AAHKV2X7AFYLW'],
581 'CA'=>['serviceUrl'=>'https://mws.amazonservices.com', 'marketplaceId'=>'A2EUQ1WTGCTBG2'],
582 'MX'=>['serviceUrl'=>'https://mws.amazonservices.com', 'marketplaceId'=>'A1AM78C64UM0Y8'],
583 'IN'=>['serviceUrl'=>'https://mws.amazonservices.in', 'marketplaceId'=>'A21TJRUUN4KGV'],
584 'ES'=>['serviceUrl'=>'https://mws-eu.amazonservices.com', 'marketplaceId'=>'A1RKKUPIHCS9HS'],
585 'GB'=>['serviceUrl'=>'https://mws.amazonservices.co.uk', 'marketplaceId'=>'A1F83G8C2ARO7P'],
586 'AU'=>['serviceUrl'=>' https://mws.amazonservices.com.au', 'marketplaceId'=>'A39IBJ37TRP1C6'],
587
588 ];
589 return isset($countryCodeInfo[$accountCountryCode]) ? $countryCodeInfo[$accountCountryCode] : false;
590 }
591
592 public function __getOcAmazonGlobalOption(){
593 $result = $this->db->query("SELECT * FROM ".DB_PREFIX."option o LEFT JOIN ".DB_PREFIX."option_description od ON(o.option_id = od.option_id) WHERE od.name = 'Amazon Variations' ")->row;
594
595 return $result;
596 }
597
598 /**
599 * check product parent asin value
600 * @param array $variations
601 * @return int|bool
602 */
603 public function checkParentAsinValue($variations)
604 {
605 $parentAsin = false;
606 foreach ($variations as $value) {
607 if (isset($value['MarketplaceASIN']['ASIN'])) {
608 $parentAsin = $value['MarketplaceASIN']['ASIN'];
609 break;
610 }
611 }
612 return $parentAsin;
613 }
614
615
616 public function getMatchedProduct($productASIN, $accountId = false)
617 {
618 $this->loadFile('Products', 'GetMatchingProductSample');
619 $config = $this->_getAccountConfigData($accountId);
620 $config['productASIN'] = $productASIN;
621 $matchingprodut = new \Getmatchingproduct((object)$config);
622 $get_product = $matchingprodut->invokeGetMatchingProduct($matchingprodut->service, $matchingprodut->request);
623 return $get_product;
624 }
625
626 public function GetMyPriceForASIN($productASIN, $accountId = false)
627 {
628 $this->loadFile('Products', 'GetMyPriceForASINSample');
629 $config = $this->_getAccountConfigData($accountId);
630 $config['productASIN'] = $productASIN;
631 $matchingprodut = new \GetMyPriceForASIN((object)$config);
632 $get_product = $matchingprodut->invokeGetMyPriceForASIN($matchingprodut->service, $matchingprodut->request);
633 return $get_product;
634 }
635
636 public function GetCompetitivePricingForASIN($productASIN, $accountId = false)
637 {
638 $this->loadFile('Products', 'GetCompetitivePricingForASINSample');
639 $config = $this->_getAccountConfigData($accountId);
640 $config['productASIN'] = $productASIN;
641 $matchingproduct = new \GetCompetitivePricingForASIN((object)$config);
642 $get_product = $matchingproduct->invokeGetCompetitivePricingForASIN($matchingproduct->service, $matchingproduct->request);
643 return $get_product;
644 }
645
646 public function __getProductFields($product_id = false){
647 $result = $this->db->query("SELECT * FROM ".DB_PREFIX."amazon_product_fields WHERE product_id = '".(int)$product_id."' ")->row;
648 return $result;
649 }
650
651 /**
652 * [_getEbayProductSpecification to get all the ebay specification]
653 * @return [type] [description]
654 */
655 public function _getAmazonSpecification(){
656 $amazonSpecifications = array();
657
658 $getAmazonAttributeEntry = $this->db->query("SELECT DISTINCT aam.account_group_id, name, account_id FROM ".DB_PREFIX."amazon_attribute_map aam LEFT JOIN ".DB_PREFIX."attribute_group ag ON(aam.account_group_id = ag.attribute_group_id) LEFT JOIN ".DB_PREFIX."attribute_group_description agd ON(ag.attribute_group_id = agd.attribute_group_id) ")->rows;
659
660 if(isset($getAmazonAttributeEntry) && $getAmazonAttributeEntry){
661 foreach ($getAmazonAttributeEntry as $key => $specification) {
662 $getConditionsValue = $this->db->query("SELECT *, ad.name as attribute_name FROM ".DB_PREFIX."attribute a LEFT JOIN ".DB_PREFIX."attribute_description ad ON (a.attribute_id = ad.attribute_id) LEFT JOIN ".DB_PREFIX."attribute_group ag ON(a.attribute_group_id = ag.attribute_group_id) LEFT JOIN ".DB_PREFIX."attribute_group_description agd ON(ag.attribute_group_id = agd.attribute_group_id) LEFT JOIN ".DB_PREFIX."amazon_attribute_map aam ON((a.attribute_group_id = aam.account_group_id) AND (a.attribute_id = aam.oc_attribute_id)) WHERE aam.account_group_id = '".(int)$specification['account_group_id']."' AND a.attribute_group_id = '".(int)$specification['account_group_id']."' AND ad.language_id = '".(int)$this->config->get('config_language_id')."' ")->rows;
663 $amazonSpecifications[$specification['account_group_id']]['name'] = $specification['name'];
664 $amazonSpecifications[$specification['account_group_id']]['account_id'] = $specification['account_id'];
665 $amazonSpecifications[$specification['account_group_id']]['attributes'] = $getConditionsValue;
666 }
667 }
668
669 return $amazonSpecifications;
670 }
671
672 /**
673 * [getProductSpecification to get opencart product specification]
674 * @param boolean $product_id [description]
675 * @return [type] [description]
676 */
677 public function getProductSpecification($product_id = false){
678 $productSpecification = array();
679
680 $getOcProductSpecification = $this->db->query("SELECT pa.attribute_id FROM " . DB_PREFIX . "product_attribute pa RIGHT JOIN ".DB_PREFIX."amazon_attribute_map aam ON(pa.attribute_id = aam.oc_attribute_id) WHERE pa.product_id = '" . (int)$product_id . "' GROUP BY pa.attribute_id")->rows;
681
682 if(!empty($getOcProductSpecification)){
683 foreach ($getOcProductSpecification as $product_attribute) {
684 $product_attribute_description_data = array();
685
686 $product_attribute_description_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_attribute WHERE product_id = '" . (int)$product_id . "' AND attribute_id = '" . (int)$product_attribute['attribute_id'] . "'");
687
688 foreach ($product_attribute_description_query->rows as $product_attribute_description) {
689 $product_attribute_description_data[$product_attribute_description['language_id']] = array('text' => $product_attribute_description['text']);
690 }
691
692 $productSpecification[] = array(
693 'attribute_id' => $product_attribute['attribute_id'],
694 'product_attribute_description' => $product_attribute_description_data
695 );
696 }
697 }
698 return $productSpecification;
699 }
700
701 /**
702 * [checkSpecificationEntry to get only the Amazon specification [used to hide the specification for opencart attribute]]
703 * @param array $data [description]
704 * @return [type] [description]
705 */
706 public function checkSpecificationEntry($data = array()){
707 $sql = "SELECT * FROM ".DB_PREFIX."attribute a LEFT JOIN ".DB_PREFIX."attribute_group ag ON(a.attribute_group_id = ag.attribute_group_id) WHERE a.attribute_group_id IN (SELECT account_group_id FROM ".DB_PREFIX."amazon_attribute_map) ";
708
709 if(isset($data['attribute_id'])){
710 $sql .= " AND a.attribute_id = '".(int)$data['attribute_id']."'";
711 }
712
713 if(isset($data['attribute_group_id'])){
714 $sql .= " AND a.attribute_group_id = '".(int)$data['attribute_group_id']."' AND ag.attribute_group_id = '".(int)$data['attribute_group_id']."' ";
715 }
716
717 $getSpecificationEntry = $this->db->query($sql)->row;
718
719 return $getSpecificationEntry;
720 }
721
722 public function _getAmazonVariation(){
723 $results = array();
724 $result = $this->db->query("SELECT * FROM ".DB_PREFIX."option o LEFT JOIN ".DB_PREFIX."option_description od ON(o.option_id = od.option_id) WHERE od.name = '".$this->db->escape('Amazon Variations')."' AND od.language_id = '".(int)$this->config->get('config_language_id')."' ")->row;
725
726 if(isset($result['option_id']) && $result['option_id']){
727 $query_option_value = $this->db->query("SELECT avm.*, ovd.*, ov.option_id FROM ".DB_PREFIX."amazon_variation_map avm LEFT JOIN ".DB_PREFIX."option_value ov ON(avm.variation_value_id = ov.option_value_id) LEFT JOIN ".DB_PREFIX."option_value_description ovd ON(ov.option_value_id = ovd.option_value_id) WHERE avm.variation_id = '".(int)$result['option_id']."' AND ov.option_id = '".(int)$result['option_id']."' AND ovd.language_id = '".(int)$this->config->get('config_language_id')."' ")->rows;
728
729 $combination_values = array();
730 if(!empty($query_option_value)){
731 foreach ($query_option_value as $key => $combination_value) {
732 $combination_values[] = $combination_value;
733 }
734 }
735
736 $results = array(
737 'option_id' => $result['option_id'],
738 'type' =>$result['type'],
739 'option_name' =>$result['name'],
740 'option_values' => $combination_values,
741 );
742 }
743 return $results;
744 }
745
746 public function _getProductVariation($product_id = false, $type = 'amazon_product_variation'){
747 $results = $product_option_value = array();
748
749 $result = $this->db->query("SELECT po.*, od.* FROM ".DB_PREFIX."product_option po LEFT JOIN ".DB_PREFIX."product p ON(po.product_id = p.product_id) LEFT JOIN ".DB_PREFIX."option o ON(po.option_id = o.option_id) LEFT JOIN ".DB_PREFIX."option_description od ON(po.option_id = od.option_id) LEFT JOIN ".DB_PREFIX."amazon_variation_map avm ON (o.option_id = avm.variation_id) WHERE po.product_id = '".(int)$product_id."' AND od.name = '".$this->db->escape('Amazon Variations')."' ")->row;
750
751 if(isset($result['option_id']) && $result['option_id']){
752 $query = $this->db->query("SELECT pov.*, avm.*, apvm.* FROM ".DB_PREFIX."product_option_value pov LEFT JOIN ".DB_PREFIX."option_value_description ovd ON ((pov.option_value_id = ovd.option_value_id) AND (pov.option_id = ovd.option_id)) LEFT JOIN ".DB_PREFIX."amazon_variation_map avm ON ((pov.option_value_id = avm.variation_value_id) AND (pov.option_id = avm.variation_id)) LEFT JOIN ".DB_PREFIX."amazon_product_variation_map apvm ON((pov.product_option_value_id = apvm.product_option_value_id) AND (pov.option_value_id = apvm.option_value_id)) WHERE pov.option_id = '".(int)$result['option_id']."' AND pov.product_id = '".(int)$product_id."' AND pov.product_option_id = '".(int)$result['product_option_id']."' AND ovd.language_id = '".(int)$this->config->get('config_language_id')."' ")->rows;
753
754 if(!empty($query)){
755 foreach ($query as $key => $product_option_entry) {
756 if($type == 'amazon_product_variation'){
757 $results[] = $product_option_entry['option_value_id'];
758 }
759
760 if($type == 'amazon_product_variation_value'){
761 $product_option_value[$product_option_entry['option_value_id']] = array(
762 'name' => $product_option_entry['value_name'],
763 'quantity' => $product_option_entry['quantity'],
764 'price' => $product_option_entry['price'],
765 'price_prefix'=> $product_option_entry['price_prefix'],
766 'id_type' => $product_option_entry['id_type'],
767 'id_value' => $product_option_entry['id_value'],
768 'sku' => $product_option_entry['sku'],
769 );
770 }
771 }
772 }
773 if($type == 'amazon_product_variation_value'){
774 $results[$result['option_id']] = array(
775 'option_id' => $result['option_id'],
776 'option_value' => $product_option_value,
777 );
778 }
779 }
780 return $results;
781 }
782
783 /**
784 * [checkVariationEntry to check amazon variation entry]
785 * @param array $data [description]
786 * @return [type] [description]
787 */
788 public function checkVariationEntry($data = array()){
789 $sql = "SELECT * FROM `" . DB_PREFIX . "product_option` po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN `" . DB_PREFIX . "option_description` od ON (o.option_id = od.option_id) WHERE po.option_id IN (SELECT variation_id FROM ".DB_PREFIX."amazon_variation_map) ";
790
791 if(isset($data['product_id'])){
792 $sql .= " AND po.product_id = '" . (int)$data['product_id'] . "' ";
793 }
794
795 if(isset($data['option_id'])){
796 $sql .= " AND po.option_id = '" . (int)$data['option_id'] . "' ";
797 }
798
799 $getVariationEntry = $this->db->query($sql)->row;
800
801 return $getVariationEntry;
802 }
803
804 /**
805 * [filterVariationASINEntry to check amazon product variation entry by product ASIN]
806 * @param array $data [description]
807 * @return [type] [description]
808 */
809 public function filterVariationASINEntry($data = array()){
810 $variationASINEntry = array();
811
812 $option = $this->__getOcAmazonGlobalOption();
813
814 $sql = "SELECT pov.*, avm.*, apvm.*, ovd.*, apm.account_id FROM ".DB_PREFIX."product_option_value pov LEFT JOIN ".DB_PREFIX."option_value_description ovd ON ((pov.option_value_id = ovd.option_value_id) AND (pov.option_id = ovd.option_id)) LEFT JOIN ".DB_PREFIX."amazon_variation_map avm ON ((pov.option_value_id = avm.variation_value_id) AND (pov.option_id = avm.variation_id)) LEFT JOIN ".DB_PREFIX."amazon_product_variation_map apvm ON((pov.product_option_value_id = apvm.product_option_value_id) AND (pov.option_value_id = apvm.option_value_id)) LEFT JOIN ".DB_PREFIX."amazon_product_map apm ON (apvm.product_id = apm.oc_product_id) WHERE pov.option_id = '".(int)$option['option_id']."' AND ovd.language_id = '".(int)$this->config->get('config_language_id')."' ";
815
816 if(isset($data['product_id'])){
817 $sql .= " AND apvm.product_id = '" . (int)$data['product_id'] . "' ";
818 }
819
820 if(isset($data['account_id'])){
821 $sql .= " AND apm.account_id = '" . (int)$data['account_id'] . "' ";
822 }
823
824 if(isset($data['product_option_value_id'])){
825 $sql .= " AND apvm.product_option_value_id = '" . (int)$data['product_option_value_id'] . "' ";
826 }
827
828 if(isset($data['option_value_id'])){
829 $sql .= " AND apvm.option_value_id = '" . (int)$data['option_value_id'] . "' ";
830 }
831
832 if(isset($data['id_value'])){
833 $sql .= " AND apvm.id_value = '" . $data['id_value'] . "' ";
834 }
835
836 if(isset($data['main_product_type_value'])){
837 $sql .= " AND apvm.main_product_type_value = '" . $data['main_product_type_value'] . "' ";
838 }
839
840 $variationASINEntry = $this->db->query($sql)->rows;
841
842 return $variationASINEntry;
843 }
844
845 /*------------------------------ Submit feed Section -----------------------------------*/
846
847 /**
848 * submit feed
849 * @param array $feedType
850 * @return array
851 */
852 public function submitFeed($feedType, $accountId)
853 {
854 $this->loadFile('', 'SubmitFeedSample');
855 $config = $this->_getAccountConfigData($accountId);
856 $config['feedType'] = $feedType;
857 $config['product'] = $this->product;
858 $submitFeed = new \Submitfeed((object)$config);
859 $result = $submitFeed->invokeSubmitFeed($submitFeed->service, $submitFeed->request);
860 @fclose($submitFeed->feedHandle);
861 return $result;
862 }
863
864 /**
865 * get feed submission list
866 * @param int $submissionId
867 * @return object
868 */
869 public function getFeedSubmissionList($feedId, $accountId)
870 {
871 $this->loadFile('', 'GetFeedSubmissionListSample');
872 $config = $this->_getAccountConfigData($accountId);
873 $config['submissionId'] = $feedId;
874 $feedsubmitlist = new \GetFeedSubmissionList((object)$config);
875 $feedsubmitresultDetail = $feedsubmitlist->invokeGetFeedSubmissionList($feedsubmitlist->service, $feedsubmitlist->request);
876
877 return $feedsubmitresultDetail;
878 }
879
880
881 /**
882 * getFeedSubmissionResult
883 * @param array $feedType
884 * @return array
885 */
886 public function getFeedSubmissionResult($feedId, $accountId)
887 {
888 $this->loadFile('', 'GetFeedSubmissionResultSample');
889 $config = $this->_getAccountConfigData($accountId);
890 $config['submissionId'] = $feedId;
891 $feedsubmitresult = new \GetFeedSubmissionResult((object)$config);
892 $feedsubmitresultDetail = $feedsubmitresult->invokeGetFeedSubmissionResult($feedsubmitresult->service, $feedsubmitresult->request);
893
894 return $feedsubmitresultDetail;
895 }
896
897
898 /*------------------------------ Import Order Section -----------------------------------*/
899
900 /**
901 * getOrderList to get Orders List
902 * @param array $data
903 * @return object
904 */
905 public function getOrderList($data, $accountId)
906 {
907 $this->loadFile('Orders', 'ListOrdersSample');
908 $config = $this->_getAccountConfigData($accountId);
909 $config['fromDate'] = $data['amazon_order_from'];
910 $config['toDate'] = $data['amazon_order_to'];
911 $config['recordCount'] = $data['amazon_order_maximum'] ? $data['amazon_order_maximum'] : 10;
912 $listOrders = new \Listorders((object)$config);
913 $orders = $listOrders->invokeListOrders($listOrders->service, $listOrders->request);
914
915 return $orders;
916 }
917
918 /**
919 * [ListOrders to get list of all orders for specific seller of amazon]
920 * @param [array] $data [data to fetch order like date range]
921 */
922 public function ListOrdersByNextToken($data, $accountId)
923 {
924 $this->loadFile('Orders', 'ListOrdersByNextTokenSample');
925 $config = $this->_getAccountConfigData($accountId);
926 $config['nextToken'] = $data['next_token'];
927 $listOrdersByNext = new \ListOrdersByNextToken((object)$config);
928 $amaz_orders = $listOrdersByNext->invokeListOrdersByNextToken($listOrdersByNext->service, $listOrdersByNext->request);
929 return $amaz_orders;
930 }
931
932 /**
933 * [GetOrder to get detail of an order]
934 * @param [integer] $amazonOrderId [amazon order id]
935 */
936 public function GetOrder($amazonOrderId, $accountId)
937 {
938 $this->loadFile('Orders', 'GetOrderSample');
939 $config = $this->_getAccountConfigData($accountId);
940 $config['amazonOrderId'] = $amazonOrderId;
941 $getOrder = new \Getorder((object)$config);
942 $amazon_Order = $getOrder->invokeGetOrder($getOrder->service, $getOrder->request);
943
944 return $amazon_Order;
945 }
946
947 /**
948 * [ListOrderItems to get ordered products of an order]
949 * @param [integer] $amazonOrderId [amazon order id]
950 */
951 public function ListOrderItems($amazonOrderId, $accountId)
952 {
953 $this->loadFile('Orders', 'ListOrderItemsSample');
954 $config = $this->_getAccountConfigData($accountId);
955 $config['orderId'] = $amazonOrderId;
956 $Listorderitems = new \Listorderitems((object)$config);
957 $ListorderitemsDetail = $Listorderitems->invokeListOrderItems($Listorderitems->service, $Listorderitems->request);
958
959 return $ListorderitemsDetail;
960 }
961
962 /*------------------------------ Customer Section -----------------------------------*/
963
964 /**
965 * [deleteCustomerEntry to delete amazon customer mapped entry]
966 * @param [integer] $customer_id [customer id]
967 */
968 public function deleteCustomerEntry($customer_id)
969 {
970 $this->db->query("DELETE FROM ".DB_PREFIX."amazon_customer_map WHERE oc_customer_id = '".(int)$customer_id."' ");
971 }
972
973 // to get the language indexes based on country code.
974 public function getLanguageIndex($country_code = 'IN')
975 {
976 if(isset($this->marketplaceLanguageArray[$country_code])){
977 return $this->marketplaceLanguageArray[$country_code];
978 }else{
979 return $this->marketplaceLanguageArray['IN'];
980 }
981 }
982 //check attribute group assigned to Any amazon account or not
983 public function getAccountByAttributeGroupId($attribute_group_id = false){
984 $total_count = 0;
985 if($attribute_group_id){
986 $getRecord = $this->db->query("SELECT COUNT(*) as TOTAL FROM ".DB_PREFIX."amazon_accounts WHERE wk_amazon_connector_attribute_group = '".(int)$attribute_group_id."' ")->row;
987 if(isset($getRecord['TOTAL'])){
988 $total_count = $getRecord['TOTAL'];
989 }
990 }
991 return $total_count;
992 }
993
994 //get UnmappedOcproduct with their variations and specification
995 public function getOcProductWithCombination($data = array()){
996 $product_array = array();
997 $sql = "SELECT p.*, m.name as manufacturer, pd.name, pd.description, apf.main_product_type, apf.main_product_type_value FROM ".DB_PREFIX."product p LEFT JOIN ".DB_PREFIX."product_description pd ON (p.product_id = pd.product_id) LEFT JOIN ".DB_PREFIX."amazon_product_fields apf ON(p.product_id = apf.product_id) LEFT JOIN ".DB_PREFIX."manufacturer m ON(p.manufacturer_id = m.manufacturer_id) WHERE pd.language_id = '".(int)$this->config->get('config_language_id')."' AND p.status = '1' AND p.product_id NOT IN (SELECT oc_product_id FROM ".DB_PREFIX."amazon_product_map) ";
998
999 if(!empty($data['product_ids'])){
1000 $sql .= " AND p.product_id IN (".$data['product_ids'].")";
1001 }
1002
1003 $sql .= " ORDER BY p.product_id ASC ";
1004
1005 if (isset($data['start']) || isset($data['limit'])) {
1006 if ($data['start'] < 0) {
1007 $data['start'] = 0;
1008 }
1009
1010 if ($data['limit'] < 1) {
1011 $data['limit'] = 50;
1012 }
1013
1014 $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
1015 }
1016
1017 foreach ($this->db->query($sql)->rows as $key => $product) {
1018 $combinationArray = $getCombinations = $specificationArray = array();
1019
1020 if($getCombinations = $this->_getProductVariation($product['product_id'], $type = 'amazon_product_variation_value')){
1021 foreach ($getCombinations as $option_id => $combination_array) {
1022 foreach ($combination_array['option_value'] as $key => $combination_value) {
1023 $combinationArray[$option_id][$key] = $combination_value;
1024 }
1025 }
1026 }
1027
1028 $specificationArray = $this->getProductSpecification($product['product_id']);
1029 if(isset($product['image']) && file_exists(DIR_IMAGE.$product['image'])){
1030 $image = HTTP_CATALOG.'image/'.$product['image'];
1031 }else{
1032 $image = HTTP_CATALOG.'image/placeholder.png';
1033 }
1034
1035 $product_array[] = array(
1036 'product_id' => $product['product_id'],
1037 'name' => $product['name'],
1038 'image' => $image,
1039 'model' => $product['model'],
1040 'description'=> $product['description'],
1041 'sku' => $product['sku'],
1042 'quantity' => $product['quantity'],
1043 'price' => $product['price'],
1044 'main_type' => $product['main_product_type'],
1045 'main_value' => $product['main_product_type_value'],
1046 'combinations' => $combinationArray,
1047 'specifications' => $specificationArray,
1048 'manufacturer' => $product['manufacturer'],
1049 );
1050 }
1051
1052 if(isset($data['count']) && !empty($product_array)){
1053 if(count($product_array) <= 50){
1054 $totalpages = 1;
1055 }else{
1056 $totalpages = ceil(count($product_array)/50);
1057 }
1058 return $totalpages;
1059 }else{
1060 return $product_array;
1061 }
1062 }
1063}