Александр

Александр

Был в сети 08 апреля 2024, 13:15
Заказы принимаю
Может кому пригодиться, исправленный метод getCost:

public function getCost($with_cart = true, $only_cost = false) {
		$response = $this->ms2->invokeEvent('msOnBeforeGetOrderCost', array(
			'order' => $this,
			'cart' => $this->ms2->cart,
			'with_cart' => $with_cart,
			'only_cost' => $only_cost,
		));
		if (!$response['success']) {return $this->error($response['message']);}

		$cart = $this->ms2->cart->status();
		$cost = $with_cart
			? $cart['total_cost']
			: 0;

        $add_price = 0;
         
		/* @var msDelivery $delivery */
		if (!empty($this->order['delivery']) && $delivery = $this->modx->getObject('msDelivery', $this->order['delivery'])) {
			//$cost = $delivery->getCost($this, $cost);
			$add_price += $delivery->getCost($this, $cost) - $cost;
			$deliveryCost = $delivery->getCost($this, 0);
			
		    //	$deliveryCost = $delivery->getCost($this, 0);//Добавил переменную где получаем price доставки
		}

		/* @var msPayment $payment */
		if (!empty($this->order['payment']) && $payment = $this->modx->getObject('msPayment', $this->order['payment'])) {
			
			 $add_price += $payment->getCost($this, $cost) - $cost;
			//$cost = $payment->getCost($this, $cost);
		}
        
        $cost += $add_price;
         
		$response = $this->ms2->invokeEvent('msOnGetOrderCost', array(
			'order' => $this,
			'cart' => $this->ms2->cart,
			'with_cart' => $with_cart,
			'only_cost' => $only_cost,
			'cost' => $cost
		));
		if (!$response['success']) {return $this->error($response['message']);}
		$cost = $response['data']['cost'];

		return $only_cost
			? $cost
			: $this->success('', array('cost' => $cost, 'delivery_cost'=>$deliveryCost));//Добавил deliveryCost
	}