Jump to content

Как вывести характеристики на странице выкладки товаров?


Recommended Posts

Те на странице категории "Пылесосы", где сейчас плиткой уложены все пылесосы, каким образом можно вывести их характеристики из админки? Те, что на странице самого товара выведены таблицей.

 

Просто вынуть из ptoduct и вставить в products соответствующий блок кода - не работает, где то каким то образом выше оно получает нужные значения, но я не могу найти где. (на примере дефолтного шаблона).

 

//хочу сделать выкладку их в категории таблицей и сразу с парой характеристик.

Link to post
Share on other sites

	public function get_new_products_plugin($params, &$smarty)
	{
		if(!isset($params['visible']))
			$params['visible'] = 1;
		if(!isset($params['sort']))
			$params['sort'] = 'created';
		if(!empty($params['var']))
		{
			foreach($this->products->get_products($params) as $p)
				$products[$p->id] = $p;

			if(!empty($products))
			{
				// id выбраных товаров
				$products_ids = array_keys($products);
		
				// Выбираем варианты товаров
				$variants = $this->variants->get_variants(array('product_id'=>$products_ids, 'in_stock'=>true));
				
				// Для каждого варианта
				foreach($variants as &$variant)
				{
					// добавляем вариант в соответствующий товар
					$products[$variant->product_id]->variants[] = $variant;
				}
                
                // Выбираем свойства товаров
                $features = $this->features->get_product_options(array('product_id'=>$products_ids));
                
                // Для каждого свойства
                foreach($features as &$feature)
                {
                    // добавляем свойство в соответствующий товар
                    $products[$features->product_id]->features[] = $feature;
                }
				
				// Выбираем изображения товаров
				$images = $this->products->get_images(array('product_id'=>$products_ids));
				foreach($images as $image)
					$products[$image->product_id]->images[] = $image;
	
				foreach($products as &$product)
				{
					if(isset($product->variants[0]))
						$product->variant = $product->variants[0];
					if(isset($product->images[0]))
						$product->image = $product->images[0];
				}				
			}

			$smarty->assign($params['var'], $products);
			
		}
	}
В моем виде выглядит так функция get_new_products_plugin (я использую метод get_product_options API Features.php)

P.S. аналогично с этим методом можете использовать и в скписке товаров, чтобы не засорять свой вью запросами.

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...