Tutorial Extension  1.0.0
SellerDeck Extensions - Tutorial Extension
ajax.php
1 <?php
2 date_default_timezone_set('GMT');
3 
4 header('Content-Type: application/json');
5 
6 require_once('../../framework/bootstrap.php');
7 
8 function UnLockError($aUnLockReturnValue, $sProductReference, $sUnLock = 'lock')
9  {
10  if (arr_get($aUnLockReturnValue, 'response.status', 'success') != 'success')
11  {
12  $sErrorMessage = "There was an error {$sUnLock}ing the product. " . arr_get($aUnLockReturnValue, 'response.returns.item.message', '');
13  $aData = ['bError' => 1, 'sErrorMessage' => $sErrorMessage];
14  \SDExtension\Helper\CLogger::get(LOG_CHANNEL_NAME)->addError($sErrorMessage);
15  return $aData;
16  }
17  return false;
18  }
19 
20 list($oCatalogDB, $oShippingDB) = SDExtension\DB\CDataBaseFactory::createAll(SDExtension\CConfig::get('sdd-configuration.database'));
21 $oProductTable = new \SDExtension\DB\Table\CProduct($oCatalogDB);
22 
23 $aData = [];
24 
25 switch (arr_get($_GET, 'function'))
26  {
27  case 'lookup':
28  $sProductReference = arr_get($_POST, 'product-reference', ' ');
29  $aData = $oProductTable->LoadByID(SQL_TYPE_STRING . $sProductReference);
30  if (empty($aData))
31  {
32  $aData = ['bError' => 1, 'sErrorMessage' => 'Product not found.'];
33  }
34  break;
35  case 'update':
36  $sProductReference = arr_get($_POST, 'product-reference', ' ');
37  $sShortDescription = arr_get($_POST, 'product-description', '');
38  $oSDApiSoapJobs = CreateSDApiSoapJobs();
39  $aLockReturnValue = $oSDApiSoapJobs->ProductLockAndUnlock($sProductReference, "lock");
40  $vLockErrorValue = UnLockError($aLockReturnValue, $sProductReference, "lock");
41  if ($vLockErrorValue !== false)
42  {
43  $aData = $vLockErrorValue;
44  break;
45  }
46  $oProductTable->UpdateSave(['Full description' => $sShortDescription, 'Product Reference' => SQL_TYPE_STRING . $sProductReference]);
47  $aUnlockReturnValue = $oSDApiSoapJobs->ProductLockAndUnlock($sProductReference, "unlock");
48  $vUnlockErrorValue = UnLockError($aUnlockReturnValue, $sProductReference, "unlock");
49  if ($vUnlockErrorValue !== false)
50  {
51  $aData = $vUnlockErrorValue;
52  }
53  break;
54  default:
55  break;
56  }
57 
58 echo json_encode($aData);
static get($sChannel="default", $sLogRoot="")
Definition: CLogger.php:90
static createAll($aConfiguration)