Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace VUM;
- class VUMOrder {
- private $_id;
- private $_fields;
- private $_cart;
- private $_profile;
- private $_payment;
- private $_delivery;
- private $_user_id;
- private $_cart_user_id;
- public function __construct($id = false)
- {
- $this->setId($id);
- }
- public function setId($id)
- {
- if (!$id) {
- return false;
- }
- $this->_id = $id;
- $this->setFields(\CSaleOrder::GetByID($id));
- }
- public function getId()
- {
- return $this->_id;
- }
- public function setNote($note)
- {
- $this->_note = $note;
- return $this;
- }
- public function getNote()
- {
- return $this->_note;
- }
- public function setUserId($user_id)
- {
- $this->_user_id = $user_id;
- return $this;
- }
- public function getUserId()
- {
- return $this->_user_id;
- }
- public function setCartUserId($cart_user_id)
- {
- $this->_cart_user_id = $cart_user_id;
- return $this;
- }
- public function getCartUserId()
- {
- return $this->_cart_user_id;
- }
- public function setCart(VUMOrderCart $cart)
- {
- $this->_cart = $cart;
- return $this;
- }
- public function getCart()
- {
- return $this->_cart;
- }
- public function setProfile(VUMOrderProfile $profile)
- {
- $this->_profile = $profile;
- return $this;
- }
- public function getProfile()
- {
- return $this->_profile;
- }
- public function setPayment(VUMOrderPayment $payment)
- {
- $this->_payment = $payment;
- return $this;
- }
- public function getPayment()
- {
- return $this->_payment;
- }
- public function setDelivery(VUMOrderDelivery $delivery)
- {
- $this->_delivery = $delivery;
- return $this;
- }
- public function getDelivery()
- {
- return $this->_delivery;
- }
- public function setFields($fields)
- {
- $this->_fields = $fields;
- return $this;
- }
- public function setFieldByKey($key, $value)
- {
- $this->_fields[$key] = $value;
- return $this;
- }
- public function getFieldByKey($key)
- {
- return $this->_fields[$key];
- }
- public function getFields()
- {
- return $this->_fields ? $this->_fields : array();
- }
- public function getField($key)
- {
- return $this->_fields[$key] ? $this->_fields[$key] : false;
- }
- public function getTotalPrice()
- {
- if ($this->getDelivery()) {
- return $this->getCart()->getTotalPrice() + $this->getDelivery()->getPrice();
- }
- return $this->getCart()->getTotalPrice();
- }
- public function notifyByEmail($location)
- {
- $user = $GLOBALS['USER']->GetByID($this->getFieldByKey('USER_ID'))->Fetch();
- if ($user) {
- \CEvent::SendImmediate('SALE_NEW_ORDER', VUM::SITE_ID,
- array(
- 'BCC' => $user['EMAIL'],
- 'LOCATION' => $location,
- 'EMAIL' => $user['EMAIL'],
- 'PRICE' => getPriceFormatCurrency($this->getFieldByKey('PRICE')),
- 'ORDER_ID' => $this->getId(),
- 'ORDER_DATE' => Date($GLOBALS['DB']->DateFormatToPHP(\CLang::GetDateFormat('SHORT', VUM::SITE_ID))),
- 'ORDER_USER' => sprintf('%s %s', $user['NAME'], $user['LAST_NAME']),
- 'ORDER_LIST' => $this->getCart() ? $this->getCart()->getStringItems() : '',
- 'SALE_EMAIL' => \COption::GetOptionString('sale', 'order_email', sprintf('order@%s', $SERVER_NAME)),
- 'MOBILE' => $user['PERSONAL_MOBILE'],
- 'DELIVERY_PRICE' => $this->getDelivery()->getPrice(),
- 'USER_DESCRIPTION' => $this->getNote('VALUE'),
- )
- );
- }
- }
- /** Todo �������� ������������� ����� */
- public function save()
- {
- if (!$this->getId()) {
- return $this->create();
- }
- $fields =
- array(
- 'PERSON_TYPE_ID' => $this->getProfile()->getPersonId(),
- 'PRICE' => $this->getTotalPrice(),
- 'USER_ID' => $this->getUserId(),
- 'FUSER_ID' => $this->getCartUserId(),
- 'USER_DESCRIPTION' => $this->getNote(),
- );
- if ($this->getDelivery()) {
- $fields['DELIVERY_ID'] = $this->getDelivery()->getId();
- $fields['PRICE_DELIVERY'] = $this->getDelivery()->getPrice();
- $fields['PAY_SYSTEM_ID'] = $this->getDelivery()->getPaymentId();
- }
- return \CSaleOrder::Update($this->getId(), array_merge($fields, $this->getFields()));
- }
- public function create($sendToEmail = true)
- {
- if (!$this->getCart() || ($this->getCart() && $this->getCart()->getCount() < 1)) {
- return false;
- }
- $fields =
- array(
- 'LID' => VUM::SITE_ID,
- 'PERSON_TYPE_ID' => $this->getProfile()->getPersonId(),
- 'PAYED' => 'N',
- 'CANCELED' => 'N',
- 'STATUS_ID' => 'N',
- 'PRICE' => $this->getTotalPrice(),
- 'CURRENCY' => VUM::GetBaseCurrency(),
- 'USER_ID' => $this->getUserId(),
- 'FUSER_ID' => $this->getCartUserId(),
- 'AFFILIATE_ID' => $GLOBALS['APPLICATION']->get_cookie('SALE_AFFILIATE'),
- 'USER_DESCRIPTION' => $this->getNote(),
- );
- if ($this->getDelivery()) {
- $fields['DELIVERY_ID'] = $this->getDelivery()->getId();
- $fields['PRICE_DELIVERY'] = $this->getDelivery()->getPrice();
- $location = $this->getDelivery()->getLocation();
- $fields['PAY_SYSTEM_ID'] = $this->getDelivery()->getPaymentId();
- }
- if(!isset($location) && empty($location)){
- $location = $this->getDelivery()->getStore();
- if($location == '131'){
- $location = 'Астана';
- }elseif($location == '132'){
- $location = 'Алматы';
- }
- }
- $this->setId(\CSaleOrder::Add(array_merge($fields, $this->getFields())));
- if ($this->getId()) {
- if($this->getCart()){
- $this->getCart()->acceptOrder($this);
- }
- if ($this->getProfile()) {
- $this->getProfile()->acceptOrder($this);
- }
- if ($sendToEmail) {
- $this->notifyByEmail($location);
- }
- }
- return $this->getId();
- }
- public function delete()
- {
- if ($this->getId()) {
- return \CSaleOrder::Delete($this->getId());
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement