Перейти до вмісту
Пошук в
  • Детальніше...
Шукати результати, які ...
Шукати результати в ...

Добавить переменную $category_id в контроллер manufacturer.php


Recommended Posts

  В 04.12.2019 в 08:23, munhgauzen сказав:

Использую проверку на  $category_id  в контроллере manufacturer.php

Expand  

об этом подробней

Надіслати
Поділитися на інших сайтах

проверка в tpl шаблоне manufacturer на соответствие id категориям

 

<?php if ($category_id == 70 || $category_id == 71 || $category_id == 72) {?>

то показываем это

<?php } else { ?> 

то показываем вот это

 <?php } ?>

Надіслати
Поділитися на інших сайтах


Как то так:

 

контроллер

$product_category = $this->model_catalog_product->getCategories($product_id);
$product_category_parent = $this->model_catalog_category->getCategory($product_category[0]['category_id']);

шаблон

<?php $parentcat = array("70", "71", "72"); ?>
<?php if (in_array(($product_category_parent), $parentcat)) { ?>
got match
<?php } else { ?>
fubar
<?php } ?>

 

Надіслати
Поділитися на інших сайтах

да но теперь ругается что undefined 

$product_category_parent

хотя в контролер я ее поставил.

 

 

 

<?php
class ControllerProductManufacturer extends Controller {
    
    public function index() {
        $this->load->language('product/manufacturer');

        $this->load->model('catalog/manufacturer');

        $this->load->model('tool/image');

        $this->document->setTitle($this->language->get('heading_title'));
        
        $product_category = $this->model_catalog_product->getCategories($product_id);
$product_category_parent = $this->model_catalog_category->getCategory($product_category[0]['category_id']);

Надіслати
Поділитися на інших сайтах


  В 04.12.2019 в 10:05, munhgauzen сказав:

class ControllerProductManufacturer extends Controller {
    
    public function index() {
        $this->load->language('product/manufacturer');

        $this->load->model('catalog/manufacturer');

        $this->load->model('tool/image');

        $this->document->setTitle($this->language->get('heading_title'));
        
        $product_category = $this->model_catalog_product->getCategories($product_id);
$product_category_parent = $this->model_catalog_category->getCategory($product_category[0]['category_id']);

Expand  

1. модель не подгужена

2. $product_id не объявлена

  • +1 1
Надіслати
Поділитися на інших сайтах

Ребята просьба помочь все таки добавить эти переменные Сам я добавил их но криво. Все равно ругается opencart.

 

: Undefined variable: product_category_parent in

/catalog/view/theme/default/template/product/manufacturer_info.tpl

 

<?php $parentcat = array("70", "71", "72"); ?>
<?php if (in_array(($product_category_parent), $parentcat)) { ?>

 

Файл manufacturer.php прикрепил

manufacturer.phpFetching info...

Надіслати
Поділитися на інших сайтах


  Цитата

$product_id = (int)$this->request->get['product_id'];

Expand  

интересно, откуда на странице производителей в   $_GET  возьмется product_id ?

Надіслати
Поділитися на інших сайтах

что вы хотите сделать?

на странице товаров производителя, вывести товары из определенных категорий как-то особо?

 

Надіслати
Поділитися на інших сайтах

    $product_category = $this->model_catalog_product->getCategories($result['product_id']);
    $categories = array();
    $fl = false;

    $parentcat = array(70, 71, 72);

    foreach ($product_category as $c) {
        if(in_array($c['category_id'], $parentcat)){
            $fl = true;
            break;
        }
    }

    $data['products'][] = array(
        // добавляем флаг
        'fl' => $fl,
        'quantity' => $result['quantity'],
        'minimum' => $result['minimum'],
        'product_id' => $result['product_id'],
        'thumb' => $image,
        'name' => $result['name'],
        'model' => $result['model'],
        'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
        'price' => $price,
        'quantity' => $result['quantity'],
        'special' => $special,
        'manufacturer' => $result['manufacturer'],
        'manufacturer_img' => $manufacturer_img,
        'tax' => $tax,
        'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
        'rating' => $result['rating'],
        'length' => round($result['length'], 2),
        'width' => round($result['width'], 2),
        'height' => round($result['height'], 2),
        'href' => $this->url->link('product/product', 'manufacturer_id=' . $result['manufacturer_id'] . '&product_id=' . $result['product_id'] . $url)
    );
<?php foreach ($products as $product) { 
  if($product['fl']){
     // если соответствует категория                 
  }else{
     // не соответсвует                    
  }
?>
    .......................

 

  • +1 1
Надіслати
Поділитися на інших сайтах

вставьте код как у меня в сообщении

это

  В 06.12.2019 в 15:21, fanatic сказав:

$product_category = $this->model_catalog_product->getCategories($result['product_id']); $categories = array(); foreach($product_category as $c){ $categories[] = $c['category_id']; }

Expand  

перед этим

  В 06.12.2019 в 15:21, fanatic сказав:

$data['products'][] = array( // добавляем в массив с товарами 'categories' => $categories, 'product_id' => $result['product_id'], 'thumb' => $image, 'name' => $result['name'], 'model' => $result['model'], 'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..', 'price' => $price, 'quantity' => $result['quantity'],

Expand  

а вы вставили перед циклом

foreach ($results as $result) {

конечно будет  

 

  В 09.12.2019 в 16:57, munhgauzen сказав:

Undefined variable: result

Expand  

 

Надіслати
Поділитися на інших сайтах

  В 09.12.2019 в 17:34, munhgauzen сказав:

Но на экране также ничего нет.

Expand  

покажите где как вставили в шаблоне.

модификаторы, обновляли?

Надіслати
Поділитися на інших сайтах

Створіть аккаунт або увійдіть для коментування

Ви повинні бути користувачем, щоб залишити коментар

Створити обліковий запис

Зареєструйтеся для отримання облікового запису. Це просто!

Зареєструвати аккаунт

Вхід

Уже зареєстровані? Увійдіть тут.

Вхід зараз
  • Зараз на сторінці   0 користувачів

    • Ні користувачів, які переглядиють цю сторінку
×
×
  • Створити...

Important Information

На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність.