OpenCart 🇺🇦

Схема

public mixed orderHandle ( $order )

Аргументы

Аргумент Возможный тип Описание
$order

Описание

Метод пока еще не документирован.

Исходный код

$this->load->model('checkout/order');
$this->load->model('openbay/ebay_order');

/**
 * Check the order is not locked
 */
if($this->model_openbay_ebay_order->lockExists($order->smpId) == true){
	return;
}

/* force array type */
if(!is_array($order->txn)) { $order->txn = array($order->txn); }

$order_id = $this->model_openbay_ebay_order->find($order->smpId);

$createdHours = (int)$this->config->get('openbaypro_created_hours');
if($createdHours == 0 || $createdHours == ''){ $createdHours = 24; } //This is a fallback value.

$from = date("Y-m-d H:i:00", mktime(date("H")-(int)$createdHours, date("i"), date("s"), date("m"), date("d"), date("y")));
$this->openbay->ebay->log('Accepting orders newer than: '.$from);

if($order_id != false){
	$order_loaded   = $this->model_checkout_order->getOrder($order_id);
	$order_history  = $this->model_openbay_ebay_order->getHistory($order_id);

	$this->openbay->ebay->log('Order ID: '.$order_id.' -> Updating');

	/* check user details to see if we have now been passed the user info */
	/* if we have these details then we have the rest of the delivery info */
	if(!empty($order->address->name) && !empty($order->address->street1)){
		$this->openbay->ebay->log('User info found');
		if($this->model_openbay_ebay_order->hasUser($order_id) == false){
			$user       = $this->handleUserAccount($order);
			/* update if the user details have not been assigned to the order */
			$this->updateOrderWithConfirmedData($order_id, $order, $user);
			$this->openbay->ebay->log('Order ID: '.$order_id.' -> Updated with user info');
		}
	}else{
		$this->openbay->ebay->log('No user info');
	}

	if($order->shipping->status == 'Shipped' && ($order_loaded['order_status_id'] != $this->default_shipped_id) && $order->payment->status == 'Paid'){
		$this->model_openbay_ebay_order->update($order_id, $this->default_shipped_id);
		$this->openbay->ebay->log('Order ID: '.$order_id.' -> Shipped');
	}elseif($order->payment->status == 'Paid' && isset($order->payment->date) && $order->shipping->status != 'Shipped' && ($order_loaded['order_status_id'] != $this->default_paid_id)){
		$this->model_openbay_ebay_order->update($order_id, $this->default_paid_id);
		$this->model_openbay_ebay_order->updatePaymentDetails($order_id, $order);


		if($this->config->get('openbaypro_stock_allocate') == 1){
			$this->openbay->ebay->log('Stock allocation is set to allocate stock when an order is paid');
			$this->model_openbay_ebay_order->addOrderLines($order, $order_id);
			$this->externalApplicationNotify($order_id);
		}

		$this->openbay->ebay->log('Order ID: '.$order_id.' -> Paid');
	}elseif(($order->payment->status == 'Refunded' || $order->payment->status == 'Unpaid') && ($order_loaded['order_status_id'] != $this->default_refunded_id) && in_array($this->default_paid_id, $order_history)){
		/* @todo what happens if the order has never been paid? - need to find a cancelled in ebay flag*/
		$this->model_openbay_ebay_order->update($order_id, $this->default_refunded_id);
		$this->model_openbay_ebay_order->cancel($order_id);
		$this->openbay->ebay->log('Order ID: '.$order_id.' -> Refunded');
	}elseif($order->payment->status == 'Part-Refunded' && ($order_loaded['order_status_id'] != $this->default_part_refunded_id) && in_array($this->default_paid_id, $order_history)){
		$this->model_openbay_ebay_order->update($order_id, $this->default_part_refunded_id);
		$this->openbay->ebay->log('Order ID: '.$order_id.' -> Part Refunded');
	}else{
		$this->openbay->ebay->log('Order ID: '.$order_id.' -> No Update');
	}
}else{
	$this->openbay->ebay->log('Created: '.$order->order->created);

	if(isset($order->order->checkoutstatus)){
		$this->openbay->ebay->log('Checkout: '.$order->order->checkoutstatus);
	}
	if(isset($order->payment->date)){
		$this->openbay->ebay->log('Paid date: '.$order->payment->date);
	}
	/**
	 * @TODO - FOLLOWING ORDER STATE TESTS REQUIRED
	 *
	 * - single item order, not checked out but then marked as paid. i.e. user wants to pay by manual method such as cheque
	 * - multi item order, same as above. Is this possible? i dont think the order will combine if checkout not done.
	 */

	if($this->config->get('ebay_import_unpaid') == 1){
		$this->openbay->ebay->log('Set to import unpaid orders');
	}else{
		$this->openbay->ebay->log('Ignore unpaid orders');
	}

	if(($order->order->created >= $from || (isset($order->payment->date) && $order->payment->date >= $from)) && (isset($order->payment->date) || $this->config->get('ebay_import_unpaid') == 1) ){

		$this->openbay->ebay->log('Creating new order');

		/* need to create the order without creating customer etc */
		$order_id = $this->create($order);
		$this->openbay->ebay->log('Order ID: '.$order_id.' -> Created.');

		/* add link */
		$this->model_openbay_ebay_order->orderLinkCreate((int)$order_id, (int)$order->smpId);

		/* check user details to see if we have now been passed the user info, if we have these details then we have the rest of the delivery info */
		if(!empty($order->address->name) && !empty($order->address->street1)){
			$this->openbay->ebay->log('User info found.');
			if($this->model_openbay_ebay_order->hasUser($order_id) == false){
				$user = $this->handleUserAccount($order);
				/* update if the user details have not been assigned to the order */
				$this->updateOrderWithConfirmedData($order_id, $order, $user);
				$this->openbay->ebay->log('Order ID: '.$order_id.' -> Updated with user info.');
			}
		}else{
			$this->openbay->ebay->log('No user information.');
		}

		//new order, set to pending initially.
		$this->model_openbay_ebay_order->confirm($order_id, $this->default_pending_id, '[eBay Import:' . (int)$order->smpId . ']');
		$this->openbay->ebay->log('Order ID: '.$order_id.' -> Pending');
		$order_status_id = $this->default_pending_id;

		//order has been paid
		if($order->payment->status == 'Paid'){
			$this->model_openbay_ebay_order->update($order_id, $this->default_paid_id);
			$this->openbay->ebay->log('Order ID: '.$order_id.' -> Paid');
			$order_status_id = $this->default_paid_id;

			if($this->config->get('openbaypro_stock_allocate') == 1){
				$this->openbay->ebay->log('Stock allocation is set to allocate stock when an order is paid');
				$this->model_openbay_ebay_order->addOrderLines($order, $order_id);
				$this->externalApplicationNotify($order_id);
			}
		}

		//order has been refunded
		if($order->payment->status == 'Refunded'){
			$this->model_openbay_ebay_order->update($order_id, $this->default_refunded_id);
			$this->model_openbay_ebay_order->cancel($order_id);
			$this->openbay->ebay->log('Order ID: '.$order_id.' -> Refunded');
			$order_status_id = $this->default_refunded_id;
		}

		//order is part refunded
		if($order->payment->status == 'Part-Refunded'){
			$this->model_openbay_ebay_order->update($order_id, $this->default_part_refunded_id);
			$this->openbay->ebay->log('Order ID: '.$order_id.' -> Part Refunded');
			$order_status_id = $this->default_part_refunded_id;
		}

		//order payment is clearing
		if($order->payment->status == 'Clearing'){
			$this->model_openbay_ebay_order->update($order_id, $this->default_pending_id);
			$this->openbay->ebay->log('Order ID: '.$order_id.' -> Clearing');
			$order_status_id = $this->default_pending_id;
		}

		//order is marked shipped
		if($order->shipping->status == 'Shipped'){
			$this->model_openbay_ebay_order->update($order_id, $this->default_shipped_id);
			$this->openbay->ebay->log('Order ID: '.$order_id.' -> Shipped');
			$order_status_id = $this->default_shipped_id;
		}

		// Admin Alert Mail
		if($this->config->get('openbaypro_confirmadmin_notify') == 1) {
			$this->openbay->newOrderAdminNotify($order_id, $order_status_id);
		}
	}
}

if($this->config->get('openbaypro_stock_allocate') == 0){
	$this->openbay->ebay->log('Stock allocation is set to allocate stock when an item is bought');
	$this->model_openbay_ebay_order->addOrderLines($order, $order_id);
	$this->externalApplicationNotify($order_id);
}

if(!empty($order->cancelled)){
	$this->openbay->ebay->log('There are cancelled items in the order');
	$this->model_openbay_ebay_order->removeOrderLines($order->cancelled, $order_id);
}

//remove the lock.
$this->model_openbay_ebay_order->lockDelete($order->smpId);