Jump to content

Recommended Posts

Здравствуйте.

Обнаружил странный баг на странице заказа. Допустим, есть оформленный заказ, который открывается по ссылке site.com/order/395b4c2943b1735832bab94bf8eede55

Если удалить этот заказ в админке и обновить в браузере страницу с заказом, то на страницу начнут выгружаться списком все товары из ранее оформленных заказов с ценами.

Подскажите, как исправить?

В файле CartView.php функция вывода выглядит так:

 

function fetch_order()
	{
		if($url = $this->request->get('url', 'string'))
			$order = $this->orders->get_order((string)$url);
		elseif(!empty($_SESSION['order_id']))
			$order = $this->orders->get_order(intval($_SESSION['order_id']));
		else
			return false;
			
		if(!$order)
			return false;
						
		$purchases = $this->orders->get_purchases(array('order_id'=>intval($order->id)));
		if(!$purchases)
			return false;
			
		if($this->request->method('post'))
		{
			if($payment_method_id = $this->request->post('payment_method_id', 'integer'))
			{
				$this->orders->update_order($order->id, array('payment_method_id'=>$payment_method_id));
				$order = $this->orders->get_order((integer)$order->id);
			}
			elseif($this->request->post('reset_payment_method'))
			{
				$this->orders->update_order($order->id, array('payment_method_id'=>null));
				$order = $this->orders->get_order((integer)$order->id);
			}
		}
		
		$products_ids = array();
		$variants_ids = array();
		foreach($purchases as $purchase)
		{
			$products_ids[] = $purchase->product_id;
			$variants_ids[] = $purchase->variant_id;
		}
		$products = array();
		foreach($this->products->get_products(array('id'=>$products_ids)) as $p)
			$products[$p->id] = $p;
		
		$images = $this->products->get_images(array('product_id'=>$products_ids));
		foreach($images as $image)
			$products[$image->product_id]->images[] = $image;
		
		$variants = $images_ids = array();
		foreach($this->variants->get_variants(array('id'=>$variants_ids)) as $v){
			$variants[$v->id] = $v;
            if(!empty($v->images_ids))
                $images_ids = array_merge($images_ids,explode(',',$v->images_ids));
        }
		
        $temp_images = $this->products->get_images(array('id'=>$images_ids));
        $images = array();
        foreach($temp_images as $image)
        	$images[$image->id] = $image; 
	
		foreach($variants as $variant)
			$products[$variant->product_id]->variants[] = $variant;
		
		// Категория товара в заказе
		foreach($products as &$product){
    		$product->categories = $this->categories->get_categories(array('product_id'=>$product->id));
    		$product->category = reset($product->categories);        
		}

		foreach($purchases as &$purchase)
		{
			if(!empty($products[$purchase->product_id]))
				$purchase->product = $products[$purchase->product_id];
			if(!empty($variants[$purchase->variant_id]))
			{
				$purchase->variant = $variants[$purchase->variant_id];
                if(!empty($purchase->variant->images_ids))
                    $purchase->image = $images[current(explode(',',$purchase->variant->images_ids))];
			}
            
            $purchase->pre_price = $purchase->price;
            $purchase->price = floor($purchase->price*(100-$purchase->discount)/100);
		}
		
		// Способ доставки
		$delivery = $this->delivery->get_delivery($order->delivery_id);
		$this->design->assign('delivery', $delivery);
			
		$this->design->assign('order', $order);
		$this->design->assign('purchases', $purchases);

		// Способ оплаты
		if($order->payment_method_id)
		{
			$payment_method = $this->payment->get_payment_method($order->payment_method_id);
			$this->design->assign('payment_method', $payment_method);
		}
			
		// Варианты оплаты
		$payment_methods = $this->payment->get_payment_methods(array('delivery_id'=>$order->delivery_id, 'enabled'=>1));
		$this->design->assign('payment_methods', $payment_methods);

		// Все валюты
		$this->design->assign('all_currencies', $this->money->get_currencies());

		
		
		// Выводим заказ
		return $this->body = $this->design->fetch('order.tpl');
	}

 

Edited by Dmitry86
Link to post
Share on other sites
23 минуты назад, alexivchenko сказал:

Баг не в ордере, а в обработке 404 страницы. Если такого заказа нет, то и система должна выдать 404. 

У меня были кое-какие доработки, сейчас в index.php кусок кода с 404 выглядит так:

// Если все хорошо
if(($res = $view->fetch()) !== false)
{
	// Выводим результат
	header("Content-type: text/html; charset=UTF-8");	
    
    if($view->last_modified) {
        $LastModified_unix = strtotime($view->last_modified); // время последнего изменения страницы
		$LastModified = gmdate("D, d M Y H:i:s \G\M\T", $LastModified_unix);
		$IfModifiedSince = false;
		if (isset($_ENV['HTTP_IF_MODIFIED_SINCE']))
			$IfModifiedSince = strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'], 5));  
		if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
			$IfModifiedSince = strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 5));
		if ($IfModifiedSince && $IfModifiedSince >= $LastModified_unix) {
			header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
			exit;
		}
		header('Last-Modified: '. $LastModified);
    }
    
	print $res;

	// Сохраняем последнюю просмотренную страницу в переменной $_SESSION['last_visited_page']
	if(empty($_SESSION['last_visited_page']) || empty($_SESSION['current_page']) || $_SERVER['REQUEST_URI'] !== $_SESSION['current_page'])
	{
		if(!empty($_SESSION['current_page']) && !empty($_SESSION['last_visited_page']) && $_SESSION['last_visited_page'] !== $_SESSION['current_page'])
			$_SESSION['last_visited_page'] = $_SESSION['current_page'];
		$_SESSION['current_page'] = $_SERVER['REQUEST_URI'];
	}		
}
else 
{ 
	// Иначе страница об ошибке
	header("http/1.0 404 not found");
	
	// Подменим переменную GET, чтобы вывести страницу 404
	$_GET['page_url'] = '404';
	$_GET['module'] = 'PageView';
	print $view->fetch();   
}

Видимо, косяк где-то здесь?

Link to post
Share on other sites
41 минуту назад, alexivchenko сказал:

Баг не в ордере, а в обработке 404 страницы. Если такого заказа нет, то и система должна выдать 404. 

Разве вот этот код из CartView.php не должен отдавать 404?

if(!$order)
	return false;

 

Link to post
Share on other sites
41 минуту назад, Dmitry86 сказал:

У меня были кое-какие доработки, сейчас в index.php кусок кода с 404 выглядит так:


// Если все хорошо
if(($res = $view->fetch()) !== false)
{
	// Выводим результат
	header("Content-type: text/html; charset=UTF-8");	
    
    if($view->last_modified) {
        $LastModified_unix = strtotime($view->last_modified); // время последнего изменения страницы
		$LastModified = gmdate("D, d M Y H:i:s \G\M\T", $LastModified_unix);
		$IfModifiedSince = false;
		if (isset($_ENV['HTTP_IF_MODIFIED_SINCE']))
			$IfModifiedSince = strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'], 5));  
		if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
			$IfModifiedSince = strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 5));
		if ($IfModifiedSince && $IfModifiedSince >= $LastModified_unix) {
			header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
			exit;
		}
		header('Last-Modified: '. $LastModified);
    }
    
	print $res;

	// Сохраняем последнюю просмотренную страницу в переменной $_SESSION['last_visited_page']
	if(empty($_SESSION['last_visited_page']) || empty($_SESSION['current_page']) || $_SERVER['REQUEST_URI'] !== $_SESSION['current_page'])
	{
		if(!empty($_SESSION['current_page']) && !empty($_SESSION['last_visited_page']) && $_SESSION['last_visited_page'] !== $_SESSION['current_page'])
			$_SESSION['last_visited_page'] = $_SESSION['current_page'];
		$_SESSION['current_page'] = $_SERVER['REQUEST_URI'];
	}		
}
else 
{ 
	// Иначе страница об ошибке
	header("http/1.0 404 not found");
	
	// Подменим переменную GET, чтобы вывести страницу 404
	$_GET['page_url'] = '404';
	$_GET['module'] = 'PageView';
	print $view->fetch();   
}

Видимо, косяк где-то здесь?

На пальцах не понять, может и проблема в Last-Modified, а может и в еще в другом. 
я могу вам скинуть кусок кода, который работает через composer, поймете в чем ошибка?

Надо смотреть на месте  

Link to post
Share on other sites
Только что, alexivchenko сказал:

На пальцах не понять, может и проблема в Last-Modified, а может и в еще в другом. 
я могу вам скинуть кусок кода, который работает через composer, поймете в чем ошибка?

Надо смотреть на месте  

попробую, конечно, спасибо)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...