Jump to content

Recommended Posts

Здравствуйте, я стараюсь сам изменить встроенные рекомендуемые товары.

Всего меняю два файла:

 

1) в папке с шаблоном - файл Product.tpl

<!--Related Products-->
 <?php if ($products) { ?>
 <div class="box">
 <div class="box-heading"><?php echo $tab_related; ?> (<?php echo count($products); ?>)</div>
   <div class="box-content">
   <div class="box-product">
   
   
      <?php foreach ($products as $product) { ?>
      <div class="itemcolumns">
      <div>
        <?php if ($product['thumb']) { ?>
        <div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" /></a></div>
        <?php } ?>
        <div class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></div>
        <?php if ($product['price']) { ?>
        <div class="price">
          <?php if (!$product['special']) { ?>
          <?php echo $product['price']; ?>
          <?php } else { ?>
          <span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
          <?php } ?>
        </div>
        <?php } ?>
        <div class="cart"><input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" /></div>
         <?php if ($this->config->get('config_review_status')) { ?>
      <div class="rating"><img src="catalog/view/theme/univer/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
      <?php } ?>
        </div>
        </div>
      <?php } ?>

      
      </div>
  </div>
  </div>
  <?php } ?>
<!--end Related Products-->

2)И Контроллер Product.php

 

Я дал рекомендуемым товарам увеличенную картинку:

if ($result['image']) {
					$image1 = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_popup_width'), $this->config->get('config_image_popup_height'));
				} else {
					$image1 = false;
				}
 

Добавил вывод характеристик:

$wi = (int)$result['width'];
$le = (int)$result['length'];
$he = (int)$result['height'];

Для счастья нужно только одно - добавить выбор цвета - который сделан по принципу Опции->картинка (Options - Image).

Я запарился:

 

Для основного продукта текст в контроллере:

$this->data['options'] = array();
			
			foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option) { 
				if ($option['type'] == 'select' || $option['type'] == 'radio' || $option['type'] == 'checkbox' || $option['type'] == 'image') { 
					$option_value_data = array();
					
					foreach ($option['option_value'] as $option_value) {
						if (!$option_value['subtract'] || ($option_value['quantity'] > 0)) {
							if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option_value['price']) {
								$price = $this->currency->format($this->tax->calculate($option_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
							} else {
								$price = false;
							}
							
							$option_value_data[] = array(
								'product_option_value_id' => $option_value['product_option_value_id'],
								'option_value_id'         => $option_value['option_value_id'],
								'name'                    => $option_value['name'],
								'image'                   => $this->model_tool_image->resize($option_value['image'], 50, 50),
								'price'                   => $price,
								'price_prefix'            => $option_value['price_prefix']
							);
						}
					}
					
					$this->data['options'][] = array(
						'product_option_id' => $option['product_option_id'],
						'option_id'         => $option['option_id'],
						'name'              => $option['name'],
						'type'              => $option['type'],
						'option_value'      => $option_value_data,
						'required'          => $option['required']
					);					
				} elseif ($option['type'] == 'text' || $option['type'] == 'textarea' || $option['type'] == 'file' || $option['type'] == 'date' || $option['type'] == 'datetime' || $option['type'] == 'time') {
					$this->data['options'][] = array(
						'product_option_id' => $option['product_option_id'],
						'option_id'         => $option['option_id'],
						'name'              => $option['name'],
						'type'              => $option['type'],
						'option_value'      => $option['option_value'],
						'required'          => $option['required']
					);						
				}
			}
 

 

 

Помогите сдвинуться с места. Мне нужно Прикрутить значения опций к переменной $Result

 

 

Share this post


Link to post
Share on other sites

Ну-же, помогите, не могу разобраться с

foreach ($this->model_catalog_product->getProductOptions($this->request->get['product_id']) as $option)

пробовал

foreach ($this->model_catalog_product->getProductRelated->getProductOptions($this->request->get['product_id']) as $option2) 

не помогает

Share this post


Link to post
Share on other sites

Может быть, стоит еще посмотреть файлы в каталогах /model/ и /language/ и дать ссылку на нужную страницу сайта, чтобы Ванги могли, наконец, увидеть ошибки на странице? Или, на крайняк, скриншот с ошибкой...

Share this post


Link to post
Share on other sites
foreach ($this->model_catalog_product->getProductRelated->getProductOptions($result['product_id']) as $option2)

Share this post


Link to post
Share on other sites

Fatal error: Call to a member function getProductOptions() on a non-object in W:\home\test1.ru\www\vqmod\vqcache\vq2-catalog_controller_product_product.php on line 527

 

Спасибо за помощь, просидел ещё прилично над этим вопросом но пока без результата, мне кажется привязать опции самое тяжелое...

 



$this->data['options'] = array();
			
			foreach ($this->model_catalog_product->getProductRelated->getProductOptions($result['product_id']) as $option2) { 
				if ($option2['type'] == 'select' || $option2['type'] == 'radio' || $option2['type'] == 'checkbox' || $option2['type'] == 'image') { 
					$option2_value_data = array();
					
					foreach ($option2['option_value'] as $option2_value) {
						if (!$option2_value['subtract'] || ($option2_value['quantity'] > 0)) {
							if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option2_value['price']) {
								$price2 = $this->currency->format($this->tax->calculate($option2_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
							} else {
								$price2 = false;
							}
							
							$option2_value_data[] = array(
								'product_option_value_id' => $option2_value['product_option_value_id'],
								'option_value_id'         => $option2_value['option_value_id'],
								'name'                    => $option2_value['name'],
								'image'                   => $this->model_tool_image->resize($option2_value['image'], 50, 50),
								'price'                   => $price2,
								'price_prefix'            => $option2_value['price_prefix']
							);
						}
					}
					
					$this->data['options'][] = array(
						'product_option_id' => $option2['product_option_id'],
						'option_id'         => $option2['option_id'],
						'name'              => $option2['name'],
						'type'              => $option2['type'],
						'option2_value'      => $option2_value_data,
						'required'          => $option2['required']
					);					
				} elseif ($option2['type'] == 'text' || $option2['type'] == 'textarea' || $option2['type'] == 'file' || $option2['type'] == 'date' || $option2['type'] == 'datetime' || $option2['type'] == 'time') {
					$this->data['options'][] = array(
						'product_option_id' => $option2['product_option_id'],
						'option_id'         => $option2['option_id'],
						'name'              => $option['name'],
						'type'              => $option2['type'],
						'option_value'      => $option2['option_value'],
						'required'          => $option2['required']
					);						
				}
			}
			


 

Share this post


Link to post
Share on other sites

ну а это "...model_catalog_product->getProductRelated->getProductOptions..." кто будет убирать?

foreach ($this->model_catalog_product->getProductRelated->getProductOptions($result['product_id']) as $option2)
>>

foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option2)

Share this post


Link to post
Share on other sites

Если не изменить на 

$this->data['options2'][] = array

то он вываливает все возможные опции к основному товару.

 

Спасибо, из-за невнимательности были ошибки в Php теперь буду пробовать привязать к этим переменным шаблон...

Share this post


Link to post
Share on other sites

так далее по тексту (в разумных пределах) должно быть "$option2".

проверяй.

Share this post


Link to post
Share on other sites

Почти вышел этот сегмент:

Код контролера выправил для всех типов опций (по идее он верен):



$this->data['options2'] = array();
			
			foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option2) { 
				if ($option2['type'] == 'select' || $option2['type'] == 'radio' || $option2['type'] == 'checkbox' || $option2['type'] == 'image') { 
					$option2_value_data = array();
					
					foreach ($option2['option_value'] as $option2_value) {
						if (!$option2_value['subtract'] || ($option2_value['quantity'] > 0)) {
							if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option2_value['price']) {
								$price2 = $this->currency->format($this->tax->calculate($option2_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
							} else {
								$price2 = false;
							}
							
							$option2_value_data[] = array(
								'product_option_value_id' => $option2_value['product_option_value_id'],
								'option_value_id'         => $option2_value['option_value_id'],
								'name'                    => $option2_value['name'],
								'image'                   => $this->model_tool_image->resize($option2_value['image'], 50, 50),
								'price'                   => $price2,
								'price_prefix'            => $option2_value['price_prefix']
							);
						}
					}
					
					$this->data['options2'][] = array(
						'product_option_id' => $option2['product_option_id'],
						'option_id'         => $option2['option_id'],
						'name'              => $option2['name'],
						'type'              => $option2['type'],
						'option2_value'      => $option2_value_data,
						'required'          => $option2['required']
					);					
				} elseif ($option2['type'] == 'text' || $option2['type'] == 'textarea' || $option2['type'] == 'file' || $option2['type'] == 'date' || $option2['type'] == 'datetime' || $option2['type'] == 'time') {
					$this->data['options2'][] = array(
						'product_option_id' => $option2['product_option_id'],
						'option_id'         => $option2['option_id'],
						'name'              => $option2['name'],
						'type'              => $option2['type'],
						'option_value'      => $option2['option_value'],
						'required'          => $option2['required']
					);						
				}
			}
			

 

 

И приступил к шаблону:

 

 
    <!--Related Products-->
 <?php if ($products) { ?>
 <div class="box">
 <div class="box-heading"><?php echo $tab_related; ?> (<?php echo count($products); ?>)</div>
   <div class="box-content">
   <div class="box-product">


	
   
      <?php foreach ($products as $product) { ?>
      <div class="itemcolumns">
      <div>
        <?php if ($product['thumb']) { ?>
        <div class="image" ><a href="<?php echo $product['popa']; ?>" ><img src="<?php echo $product['thumb']; ?>" data-zoom-

image="<?php echo $product['popa']; ?>" alt="<?php echo $product['name']; ?>" /></a></div>
        <?php } ?>
        <div class="name"><?php echo $product['name']; ?></div>



<?php if ($product['wi'] > 0) { ?>
        <span>Размеры (ШхГхВ):</span>     <div class="name"><?php echo $product['le']; echo " x "; echo $product['wi']; echo " x 

"; echo $product['he']; ?>



</div>
<?php } ?>





<div class="name">
     

      <?php if ($options2) { ?>
      
        <h2><?php echo $text_option; ?></h2>
        <br />
        <?php foreach ($options2 as $option2) { ?>
        
        <?php if ($option2['type'] == 'image') { ?>
        <div id="option2-<?php echo $option2['product_option_id']; ?>" class="option">
          <?php if ($option2['required']) { ?>
          <span class="required">*</span>
          <?php } ?>
          <b><?php echo $option2['name']; ?>:</b><br />
          <table class="option-image">
            <?php foreach ($option2['option2_value'] as $option2_value) { ?>
            <tr>
              <td style="width: 1px;"><input type="radio" name="option2[<?php echo $option2['product_option_id']; ?>]" value="<?

php echo $option2_value['product_option_value_id']; ?>" id="option2-value-<?php echo $option2_value['product_option_value_id']; 

?>" /></td>
              <td><label for="option2-value-<?php echo $option2_value['product_option_value_id']; ?>"><img src="<?php echo 

$option2_value['image']; ?>" alt="<?php echo $option2_value['name'] . ($option2_value['price'] ? ' ' . $option2_value

['price_prefix'] . $option2_value['price'] : ''); ?>" /></label></td>
              <td><label for="option2-value-<?php echo $option2_value['product_option_value_id']; ?>"><?php echo $option2_value

['name']; ?>
                  <?php if ($option2_value['price']) { ?>
                  (<?php echo $option2_value['price_prefix']; ?><?php echo $option2_value['price']; ?>)
                  <?php } ?>
                </label></td>
            </tr>
            <?php } ?>
          </table>
        </div>
        <br />
        <?php } ?>
        
      
      <?php } ?>


<?php } ?>





</div>






        <?php if ($product['price']) { ?>
        <div class="price">
          <?php if (!$product['special']) { ?>
          <?php echo $product['price']; ?>
          <?php } else { ?>
          <span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; 

?></span>
          <?php } ?>
        </div>
        <?php } ?>
        <div class="cart"><input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product

['product_id']; ?>');" class="button" /></div>
         <?php if ($this->config->get('config_review_status')) { ?>
      <div class="rating"><img src="catalog/view/theme/univer/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo 

$product['reviews']; ?>" /></div>
      <?php } ?>
        </div>
        </div>
      <?php } ?>

      
      </div>
  </div>
  </div>
  <?php } ?>
<!--end Related Products-->

 

Фиолетовым помечен фрагмент, отвечающий за опцию именно картинкой. Всё работает, НО сайт присваевает всем товарам одни и те же цвета, которые берёт у последнего товара в ряду))) Подразумеваю, что я не задал какой-то цикл неким образом связанный с переменной $products

 

aab3f2e03b60.png

Share this post


Link to post
Share on other sites

какое еще

$this->data['options2']
??? :?

 

...
			$this->data['products'] = array();
			$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
			foreach ($results as $result) {
				if ($result['image']) {
...
				$this->data['products'][] = array(
					'product_id' => $result['product_id'],
...
>>

...
			$this->data['products'] = array();
			$results = $this->model_catalog_product->getProductRelated($this->request->get['product_id']);
			foreach ($results as $result) {
				
				foreach ($this->model_catalog_product->getProductOptions($result['product_id']) as $option2) {
					$relatedProductOptions
					if ($option2['type'] == 'select' || $option2['type'] == 'radio' || $option2['type'] == 'checkbox' || $option2['type'] == 'image') { 
						$option2_value_data = array();
						
						foreach ($option2['option_value'] as $option2_value) {
							if (!$option2_value['subtract'] || ($option2_value['quantity'] > 0)) {
								if ((($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) && (float)$option2_value['price']) {
									$price = $this->currency->format($this->tax->calculate($option2_value['price'], $product_info['tax_class_id'], $this->config->get('config_tax')));
								} else {
									$price = false;
								}
								
								$option2_value_data[] = array(
									'product_option_value_id' => $option2_value['product_option_value_id'],
									'option_value_id'         => $option2_value['option_value_id'],
									'name'                    => $option2_value['name'],
									'image'                   => $this->model_tool_image->resize($option2_value['image'], 50, 50),
									'price'                   => $price,
									'price_prefix'            => $option2_value['price_prefix']
								);
							}
						}
						
						$relatedProductOptions[] = array(
							'product_option_id' => $option2['product_option_id'],
							'option_id'         => $option2['option_id'],
							'name'              => $option2['name'],
							'type'              => $option2['type'],
							'option_value'      => $option2_value_data,
							'required'          => $option2['required']
						);
					} elseif ($option2['type'] == 'text' || $option2['type'] == 'textarea' || $option2['type'] == 'file' || $option2['type'] == 'date' || $option2['type'] == 'datetime' || $option2['type'] == 'time') {
						$relatedProductOptions[] = array(
							'product_option_id' => $option2['product_option_id'],
							'option_id'         => $option2['option_id'],
							'name'              => $option2['name'],
							'type'              => $option2['type'],
							'option_value'      => $option2['option_value'],
							'required'          => $option2['required']
						);
					}
				}
				
				if ($result['image']) {
...
				$this->data['products'][] = array(
					'options' => $relatedProductOptions,
					'product_id' => $result['product_id'],
...

Share this post


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
You are posting as a guest. If you have an account, please sign in.
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.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.