Advertisement
Guest User

Untitled

a guest
Feb 4th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.73 KB | None | 0 0
  1. <?php
  2. namespace VUM;
  3.  
  4. class VUMOrder {
  5. private $_id;
  6. private $_fields;
  7.  
  8. private $_cart;
  9. private $_profile;
  10.  
  11. private $_payment;
  12. private $_delivery;
  13.  
  14. private $_user_id;
  15. private $_cart_user_id;
  16.  
  17. public function __construct($id = false)
  18. {
  19. $this->setId($id);
  20. }
  21.  
  22. public function setId($id)
  23. {
  24. if (!$id) {
  25. return false;
  26. }
  27.  
  28. $this->_id = $id;
  29.  
  30. $this->setFields(\CSaleOrder::GetByID($id));
  31. }
  32.  
  33. public function getId()
  34. {
  35. return $this->_id;
  36. }
  37.  
  38. public function setNote($note)
  39. {
  40. $this->_note = $note;
  41.  
  42. return $this;
  43. }
  44.  
  45. public function getNote()
  46. {
  47. return $this->_note;
  48. }
  49.  
  50. public function setUserId($user_id)
  51. {
  52. $this->_user_id = $user_id;
  53.  
  54. return $this;
  55. }
  56.  
  57. public function getUserId()
  58. {
  59. return $this->_user_id;
  60. }
  61.  
  62. public function setCartUserId($cart_user_id)
  63. {
  64. $this->_cart_user_id = $cart_user_id;
  65.  
  66. return $this;
  67. }
  68.  
  69. public function getCartUserId()
  70. {
  71. return $this->_cart_user_id;
  72. }
  73.  
  74. public function setCart(VUMOrderCart $cart)
  75. {
  76. $this->_cart = $cart;
  77.  
  78. return $this;
  79. }
  80.  
  81. public function getCart()
  82. {
  83. return $this->_cart;
  84. }
  85.  
  86. public function setProfile(VUMOrderProfile $profile)
  87. {
  88. $this->_profile = $profile;
  89.  
  90. return $this;
  91. }
  92.  
  93. public function getProfile()
  94. {
  95. return $this->_profile;
  96. }
  97.  
  98. public function setPayment(VUMOrderPayment $payment)
  99. {
  100. $this->_payment = $payment;
  101.  
  102. return $this;
  103. }
  104.  
  105. public function getPayment()
  106. {
  107. return $this->_payment;
  108. }
  109.  
  110. public function setDelivery(VUMOrderDelivery $delivery)
  111. {
  112. $this->_delivery = $delivery;
  113.  
  114. return $this;
  115. }
  116.  
  117. public function getDelivery()
  118. {
  119. return $this->_delivery;
  120. }
  121.  
  122. public function setFields($fields)
  123. {
  124. $this->_fields = $fields;
  125. return $this;
  126. }
  127.  
  128. public function setFieldByKey($key, $value)
  129. {
  130. $this->_fields[$key] = $value;
  131.  
  132. return $this;
  133. }
  134.  
  135. public function getFieldByKey($key)
  136. {
  137. return $this->_fields[$key];
  138. }
  139.  
  140. public function getFields()
  141. {
  142. return $this->_fields ? $this->_fields : array();
  143. }
  144.  
  145. public function getField($key)
  146. {
  147. return $this->_fields[$key] ? $this->_fields[$key] : false;
  148. }
  149.  
  150. public function getTotalPrice()
  151. {
  152. if ($this->getDelivery()) {
  153. return $this->getCart()->getTotalPrice() + $this->getDelivery()->getPrice();
  154. }
  155.  
  156. return $this->getCart()->getTotalPrice();
  157. }
  158.  
  159. public function notifyByEmail($location)
  160. {
  161. $user = $GLOBALS['USER']->GetByID($this->getFieldByKey('USER_ID'))->Fetch();
  162.  
  163. if ($user) {
  164. \CEvent::SendImmediate('SALE_NEW_ORDER', VUM::SITE_ID,
  165. array(
  166. 'BCC' => $user['EMAIL'],
  167. 'LOCATION' => $location,
  168. 'EMAIL' => $user['EMAIL'],
  169. 'PRICE' => getPriceFormatCurrency($this->getFieldByKey('PRICE')),
  170. 'ORDER_ID' => $this->getId(),
  171. 'ORDER_DATE' => Date($GLOBALS['DB']->DateFormatToPHP(\CLang::GetDateFormat('SHORT', VUM::SITE_ID))),
  172. 'ORDER_USER' => sprintf('%s %s', $user['NAME'], $user['LAST_NAME']),
  173. 'ORDER_LIST' => $this->getCart() ? $this->getCart()->getStringItems() : '',
  174. 'SALE_EMAIL' => \COption::GetOptionString('sale', 'order_email', sprintf('order@%s', $SERVER_NAME)),
  175. 'MOBILE' => $user['PERSONAL_MOBILE'],
  176. 'DELIVERY_PRICE' => $this->getDelivery()->getPrice(),
  177. 'USER_DESCRIPTION' => $this->getNote('VALUE'),
  178. )
  179. );
  180. }
  181. }
  182. /** Todo �������� ������������� ����� */
  183. public function save()
  184. {
  185. if (!$this->getId()) {
  186. return $this->create();
  187. }
  188.  
  189. $fields =
  190. array(
  191. 'PERSON_TYPE_ID' => $this->getProfile()->getPersonId(),
  192. 'PRICE' => $this->getTotalPrice(),
  193. 'USER_ID' => $this->getUserId(),
  194. 'FUSER_ID' => $this->getCartUserId(),
  195. 'USER_DESCRIPTION' => $this->getNote(),
  196. );
  197.  
  198. if ($this->getDelivery()) {
  199. $fields['DELIVERY_ID'] = $this->getDelivery()->getId();
  200. $fields['PRICE_DELIVERY'] = $this->getDelivery()->getPrice();
  201. $fields['PAY_SYSTEM_ID'] = $this->getDelivery()->getPaymentId();
  202. }
  203. return \CSaleOrder::Update($this->getId(), array_merge($fields, $this->getFields()));
  204. }
  205.  
  206. public function create($sendToEmail = true)
  207. {
  208. if (!$this->getCart() || ($this->getCart() && $this->getCart()->getCount() < 1)) {
  209. return false;
  210. }
  211.  
  212. $fields =
  213. array(
  214. 'LID' => VUM::SITE_ID,
  215. 'PERSON_TYPE_ID' => $this->getProfile()->getPersonId(),
  216. 'PAYED' => 'N',
  217. 'CANCELED' => 'N',
  218. 'STATUS_ID' => 'N',
  219. 'PRICE' => $this->getTotalPrice(),
  220. 'CURRENCY' => VUM::GetBaseCurrency(),
  221. 'USER_ID' => $this->getUserId(),
  222. 'FUSER_ID' => $this->getCartUserId(),
  223. 'AFFILIATE_ID' => $GLOBALS['APPLICATION']->get_cookie('SALE_AFFILIATE'),
  224. 'USER_DESCRIPTION' => $this->getNote(),
  225. );
  226. if ($this->getDelivery()) {
  227. $fields['DELIVERY_ID'] = $this->getDelivery()->getId();
  228. $fields['PRICE_DELIVERY'] = $this->getDelivery()->getPrice();
  229. $location = $this->getDelivery()->getLocation();
  230. $fields['PAY_SYSTEM_ID'] = $this->getDelivery()->getPaymentId();
  231. }
  232. if(!isset($location) && empty($location)){
  233. $location = $this->getDelivery()->getStore();
  234. if($location == '131'){
  235. $location = 'Астана';
  236. }elseif($location == '132'){
  237. $location = 'Алматы';
  238. }
  239. }
  240.  
  241. $this->setId(\CSaleOrder::Add(array_merge($fields, $this->getFields())));
  242. if ($this->getId()) {
  243. if($this->getCart()){
  244. $this->getCart()->acceptOrder($this);
  245. }
  246.  
  247. if ($this->getProfile()) {
  248. $this->getProfile()->acceptOrder($this);
  249. }
  250.  
  251. if ($sendToEmail) {
  252. $this->notifyByEmail($location);
  253. }
  254. }
  255.  
  256. return $this->getId();
  257. }
  258.  
  259. public function delete()
  260. {
  261. if ($this->getId()) {
  262. return \CSaleOrder::Delete($this->getId());
  263. }
  264.  
  265. return false;
  266. }
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement