PageRenderTime 25ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/storecommander/ead6f6fce09/SC/lib/ord/product/ord_product_get.php

https://gitlab.com/ptisky/API_prestashop
PHP | 188 lines | 148 code | 9 blank | 31 comment | 23 complexity | 87848728040b7b572467e4f6131b146c MD5 | raw file
  1. <?php
  2. /**
  3. * Store Commander
  4. *
  5. * @category administration
  6. * @author Store Commander - support@storecommander.com
  7. * @version 2015-09-15
  8. * @uses Prestashop modules
  9. * @since 2009
  10. * @copyright Copyright &copy; 2009-2015, Store Commander
  11. * @license commercial
  12. * All rights reserved! Copying, duplication strictly prohibited
  13. *
  14. * *****************************************
  15. * * STORE COMMANDER *
  16. * * http://www.StoreCommander.com *
  17. * * V 2015-09-15 *
  18. * *****************************************
  19. *
  20. * Compatibility: PS version: 1.1 to 1.6.1
  21. *
  22. **/
  23. $id_order=Tools::getValue('id_order');
  24. // get order status
  25. $orderStatusPS = OrderState::getOrderStates($sc_agent->id_lang);
  26. $orderStatus=array();
  27. foreach($orderStatusPS AS $status)
  28. {
  29. $orderStatus[$status['id_order_state']]=$status;
  30. }
  31. function getRowsFromDB(){
  32. global $id_order,$orderStatus;
  33. $yesno=array(0=>_l('No'),1=>_l('Yes'));
  34. $sql = '
  35. SELECT od.*
  36. FROM '._DB_PREFIX_.'order_detail od
  37. WHERE od.id_order IN ('.pSQL($id_order).')
  38. ORDER BY od.id_order_detail';
  39. $res=Db::getInstance()->ExecuteS($sql);
  40. $xml='';
  41. foreach ($res AS $history)
  42. {
  43. $actual_quantity_in_stock = SCI::getProductQty($history['product_id'], $history['product_attribute_id'], $history['id_warehouse']);
  44. /*if($history['product_id']==7)
  45. $actual_quantity_in_stock = 1;*/
  46. // Dans le cas où le stock au moment de la commande
  47. // est négatif, il faut utiliser la différence
  48. // de stock pour savoir combien de produits il y a
  49. // actuellement par rapport au passage de la commande
  50. // Exemple : -15 à la commande et -10 actuellement => 5 en stock
  51. if($history['product_quantity_in_stock']<0 && $actual_quantity_in_stock>=$history['product_quantity_in_stock'])
  52. $actual_quantity_in_stock -= $history['product_quantity_in_stock'];
  53. // IN STOCK
  54. if (version_compare(_PS_VERSION_, '1.4.0.0', '>='))
  55. {
  56. $history['instock']=0;
  57. $color_instock = "";
  58. $order_in_stock=($history['product_quantity_in_stock'] >= $history['product_quantity'] ? 1 : 0);
  59. if($order_in_stock==1)
  60. $history['instock']=1;
  61. else
  62. {
  63. $total_qty_wanted = 0;
  64. if(!empty($history['product_id']))
  65. {
  66. $sql_details = "SELECT product_quantity FROM "._DB_PREFIX_."order_detail WHERE product_id='".intval($history['product_id'])."' AND product_attribute_id='".intval($history['product_attribute_id'])."'";
  67. $res_details=Db::getInstance()->ExecuteS($sql_details);
  68. foreach($res_details as $res_detail)
  69. {
  70. $total_qty_wanted += $res_detail["product_quantity"];
  71. }
  72. if($actual_quantity_in_stock >= $history['product_quantity'])
  73. $history['instock']=1;
  74. if($actual_quantity_in_stock<$total_qty_wanted && $actual_quantity_in_stock>0)
  75. {
  76. $history['instock']=3;
  77. $color_instock = "#FF9900";
  78. }
  79. }
  80. }
  81. if($history['instock']==0 && empty($color_instock))
  82. $color_instock = "#FF0000";
  83. }
  84. if($history['instock']==2)
  85. $instock = _l("Insufficient current total stock");
  86. elseif($history['instock']==3)
  87. $instock = _l("Partial");
  88. else
  89. $instock = $yesno[$history['instock']];
  90. $xml.=("<row id='".$history['id_order_detail']."'>");
  91. $xml.=("<cell style=\"color:#999999\">".$history['id_order_detail']."</cell>");
  92. $xml.=("<cell>".$history['id_order']."</cell>");
  93. $xml.=("<cell>".$history['product_id']."</cell>");
  94. $xml.=("<cell>".$history['product_attribute_id']."</cell>");
  95. $xml.=("<cell><![CDATA[".$history['product_name']."]]></cell>");
  96. $xml.=("<cell>".$history['product_quantity']."</cell>");
  97. $xml.=("<cell>".$actual_quantity_in_stock."</cell>");
  98. if (version_compare(_PS_VERSION_, '1.2.0.0', '>='))
  99. $xml.=("<cell>".$history['product_quantity_in_stock']."</cell>");
  100. if (version_compare(_PS_VERSION_, '1.4.0.0', '>='))
  101. $xml.="<cell".(!empty($color_instock)?' bgColor="'.$color_instock.'" style="color:#FFFFFF"':'').">".$instock."</cell>";
  102. if (version_compare(_PS_VERSION_, '1.2.0.0', '>='))
  103. $xml.=("<cell>".$history['product_quantity_refunded']."</cell>");
  104. $xml.=("<cell>".$history['product_quantity_return']."</cell>");
  105. $xml.=("<cell>".number_format($history['product_price'], 6, '.', '')."</cell>");
  106. $xml.=("<cell><![CDATA[".$history['product_ean13']."]]></cell>");
  107. if (version_compare(_PS_VERSION_, '1.4.0.0', '>='))
  108. $xml.=("<cell><![CDATA[".$history['product_upc']."]]></cell>");
  109. $xml.=("<cell><![CDATA[".$history['product_reference']."]]></cell>");
  110. $xml.=("<cell><![CDATA[".$history['product_supplier_reference']."]]></cell>");
  111. $xml.=("<cell>".number_format($history['product_weight'], 6, '.', '')."</cell>");
  112. if (version_compare(_PS_VERSION_, '1.5.0.0', '<'))
  113. {
  114. $xml.=("<cell><![CDATA[".$history['tax_name']."]]></cell>");
  115. $xml.=("<cell>".$history['tax_rate']."</cell>");
  116. }
  117. $xml.=("</row>");
  118. }
  119. return $xml;
  120. }
  121. //XML HEADER
  122. if ( stristr($_SERVER["HTTP_ACCEPT"],"application/xhtml+xml") ) {
  123. header("Content-type: application/xhtml+xml"); } else {
  124. header("Content-type: text/xml");
  125. }
  126. echo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  127. $xml=getRowsFromDB();
  128. ?>
  129. <rows id="0">
  130. <head>
  131. <beforeInit>
  132. <call command="attachHeader"><param><![CDATA[#numeric_filter,#numeric_filter,#numeric_filter,#numeric_filter,#text_filter,#numeric_filter,#numeric_filter<?php if (version_compare(_PS_VERSION_, '1.2.0.0', '>=')){ ?>,#numeric_filter<?php } ?><?php if (version_compare(_PS_VERSION_, '1.4.0.0', '>=')){ ?>,#select_filter<?php } ?><?php if (version_compare(_PS_VERSION_, '1.2.0.0', '>=')){ ?>,#numeric_filter<?php } ?>,#numeric_filter,#numeric_filter,#text_filter<?php if (version_compare(_PS_VERSION_, '1.4.0.0', '>=')){ ?>,#text_filter<?php } ?>,#text_filter,#text_filter,#numeric_filter<?php if (version_compare(_PS_VERSION_, '1.5.0.0', '<')){ ?>,#numeric_filter,#numeric_filter<?php } ?>]]></param></call>
  133. <call command="attachFooter"><param><![CDATA[,,,,,#stat_total]]></param></call>
  134. </beforeInit>
  135. <column id="id_order_detail" width="45" type="ro" align="right" sort="int"><?php echo _l('id order detail')?></column>
  136. <column id="id_order" width="45" type="ro" align="right" sort="int"><?php echo _l('id order')?></column>
  137. <column id="product_id" width="45" type="ro" align="right" sort="int"><?php echo _l('id product')?></column>
  138. <column id="product_attribute_id" width="45" type="ro" align="right" sort="int"><?php echo _l('id product attribute')?></column>
  139. <column id="product_name" width="150" type="edtxt" align="left" sort="str"><?php echo _l('Name')?></column>
  140. <column id="product_quantity" width="50" type="edtxt" align="right" sort="int"><?php echo _l('Quantity orded')?></column>
  141. <column id="actual_quantity_in_stock" width="50" type="ro" align="right" sort="int"><?php echo _l('Current qty in stock')?></column>
  142. <?php if (version_compare(_PS_VERSION_, '1.2.0.0', '>=')) { ?>
  143. <column id="product_quantity_in_stock" width="50" type="ro" align="right" sort="int"><?php echo _l('Qty in stock at time of order')?></column>
  144. <?php } ?>
  145. <?php if (version_compare(_PS_VERSION_, '1.4.0.0', '>=')) { ?>
  146. <column id="instock" width="45" type="ro" align="right" sort="int"><?php echo _l('In stock')?></column>
  147. <?php } ?>
  148. <?php if (version_compare(_PS_VERSION_, '1.2.0.0', '>=')) { ?>
  149. <column id="product_quantity_refunded" width="50" type="ro" align="right" sort="int"><?php echo _l('Qty refunded')?></column>
  150. <?php } ?>
  151. <column id="product_quantity_return" width="50" type="ro" align="right" sort="int"><?php echo _l('Qty returned')?></column>
  152. <column id="product_price" width="60" type="edn" align="right" sort="int" format="0.00"><?php echo _l('Price excl. Tax')?></column>
  153. <column id="product_ean13" width="70" type="edtxt" align="left" sort="str"><?php echo _l('EAN13')?></column>
  154. <?php
  155. if (version_compare(_PS_VERSION_, '1.4.0.0', '>='))
  156. {
  157. ?>
  158. <column id="product_upc" width="70" type="edtxt" align="left" sort="str"><?php echo _l('UPC')?></column>
  159. <?php
  160. }
  161. ?>
  162. <column id="product_reference" width="70" type="edtxt" align="left" sort="str"><?php echo _l('Reference')?></column>
  163. <column id="product_supplier_reference" width="70" type="edtxt" align="left" sort="str"><?php echo _l('Supplier reference')?></column>
  164. <column id="product_weight" width="70" type="edn" align="right" sort="str" format="0.00"><?php echo _l('Weight')?></column>
  165. <?php
  166. if (version_compare(_PS_VERSION_, '1.5.0.0', '<'))
  167. {
  168. ?>
  169. <column id="tax_name" width="70" type="edtxt" align="left" sort="str"><?php echo _l('Tax')?></column>
  170. <column id="tax_rate" width="70" type="edn" align="right" sort="str"><?php echo _l('Tax rate')?></column>
  171. <?php
  172. }
  173. ?>
  174. </head>
  175. <?php
  176. echo '<userdata name="uisettings">'.uisettings::getSetting('ord_product').'</userdata>'."\n";
  177. echo $xml;
  178. ?>
  179. </rows>