Помощь Добавить опции в колонку Прайс Листа

yurets86

Постоялец
Заблокирован
Регистрация
25 Сен 2011
Сообщения
135
Реакции
39
  • Автор темы
  • Заблокирован
  • #1
Переделываю вывод модуля Для просмотра ссылки Войди или Зарегистрируйся под себя, столкнулся с проблемой, что не получается вывести каждую опцию в отдельную колонку
Эксперты Опенкарта- помогите пожалуйста, ocstote 1.5.5.1.1

<?php
class ControllerMyocPricelist extends Controller {
private $default_limits = array(50,75,100,150,200,250);

public function index() {
$this->language->load('myoc/pricelist');

$this->document->setTitle($this->language->get('heading_title'));

$this->data['breadcrumbs'] = array();

$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home'),
'separator' => false
);

$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('product/pricelist'),
'separator' => $this->language->get('text_separator')
);

$this->data['heading_title'] = $this->language->get('heading_title');

$this->document->setDescription($product_info['meta_description']);
$this->document->setKeywords($product_info['meta_keyword']);

$this->data['text_empty'] = $this->language->get('text_empty');
$this->data['button_continue'] = $this->language->get('button_continue');

$this->data['continue'] = $this->url->link('common/home', '', 'SSL');

$this->pricelist();

if ($product_info['seo_h1']) {
$this->data['heading_title'] = $product_info['seo_h1'];
} else {
$this->data['heading_title'] = $product_info['name'];
}


if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/myoc/pricelist.tpl')) {
$this->template = $this->config->get('config_template') . '/template/myoc/pricelist.tpl';
} else {
$this->template = 'default/template/myoc/pricelist.tpl';
}


$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);

$this->response->setOutput($this->render());
}

public function printable() {
if($this->config->get('myocwpl_login') && !$this->customer->isLogged()) {
$this->session->data['redirect'] = $this->url->link('product/pricelist', '', 'SSL');

$this->redirect($this->url->link('account/login', '', 'SSL'));
}
if($this->config->get('myocwpl_login') && $this->customer->isLogged() && (!$this->config->get('myocwpl_customer_group') || !in_array($this->customer->getCustomerGroupId(), $this->config->get('myocwpl_customer_group')))) {
$this->redirect($this->url->link('product/pricelist', '', 'SSL'));
}
//header info

if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$this->data['base'] = $this->config->get('config_ssl');
} else {
$this->data['base'] = $this->config->get('config_url');
}

$this->data['links'] = $this->document->getLinks();
$this->data['lang'] = $this->language->get('code');
$this->data['direction'] = $this->language->get('direction');

if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
$server = HTTPS_SERVER . 'image/';
} else {
$server = HTTP_SERVER . 'image/';
}

if ($this->config->get('config_icon') && file_exists(DIR_IMAGE . $this->config->get('config_icon'))) {
$this->data['icon'] = $server . $this->config->get('config_icon');
} else {
$this->data['icon'] = '';
}

$this->data['name'] = $this->config->get('config_name');

if ($this->config->get('config_logo') && file_exists(DIR_IMAGE . $this->config->get('config_logo'))) {
$this->data['logo'] = $server . $this->config->get('config_logo');
} else {
$this->data['logo'] = '';
}

$this->data['store_url'] = $this->data['base'];
$this->data['store_title'] = $this->config->get('config_title');
$this->data['store_address'] = nl2br($this->config->get('config_address'));
$this->data['store_email'] = $this->config->get('config_email');
$this->data['store_telephone'] = $this->config->get('config_telephone');

//pricelist
$this->language->load('myoc/pricelist');

$this->document->setTitle($this->language->get('heading_title'));

$this->data['title'] = $this->document->getTitle();

$this->data['heading_title'] = $this->language->get('heading_title');

$this->data['text_empty'] = $this->language->get('text_empty');

$this->pricelist();

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/myoc/pricelist_print.tpl')) {
$this->template = $this->config->get('config_template') . '/template/myoc/pricelist_print.tpl';
} else {
$this->template = 'default/template/myoc/pricelist_print.tpl';
}

$this->response->setOutput($this->render());
}

private function pricelist()
{
$this->load->model('catalog/product');
$this->load->model('catalog/category');
$this->load->model('tool/image');

if (isset($this->request->get['catid'])) {
$catid = $this->request->get['catid'];
} else {
$catid = 0;
}

if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'pd.name';
}

if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}

if (isset($this->request->get['limit'])) {
$limit = $this->request->get['limit'];
} else {
$limit = $this->default_limits[0];
}

if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}

$this->data['text_limit'] = $this->language->get('text_limit');
$this->data['text_category'] = $this->language->get('text_category');
$this->data['text_print'] = $this->language->get('text_print');
$this->data['text_discount'] = $this->language->get('text_discount');

$this->data['column_number'] = $this->language->get('column_number');
$this->data['column_name'] = $this->language->get('column_name');
$this->data['column_rating'] = $this->language->get('column_rating');
$this->data['column_price'] = $this->language->get('column_price');

$this->data['button_cart'] = $this->language->get('button_cart');

$url = ''; //column header sort href

if ($order == 'ASC') {
$url .= '&order=DESC';
} else {
$url .= '&order=ASC';
}

if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}

if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}

if (isset($this->request->get['catid'])) {
$url .= '&catid=' . $this->request->get['catid'];
}

$this->data['sort_name'] = $this->url->link('product/pricelist', '&sort=pd.name' . $url, 'SSL');
$this->data['sort_model'] = $this->url->link('product/pricelist', '&sort=p.model' . $url, 'SSL');
$this->data['sort_rating'] = $this->url->link('product/pricelist', '&sort=rating' . $url, 'SSL');
$this->data['sort_price'] = $this->url->link('product/pricelist', '&sort=p.price' . $url, 'SSL');
$this->data['sort_quantity'] = $this->url->link('product/pricelist', '&sort=p.quantity' . $url, 'SSL');

$url = ''; //limits

if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}

if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}

if (isset($this->request->get['catid'])) {
$url .= '&catid=' . $this->request->get['catid'];
}

$this->data['limits'] = array();

foreach($this->default_limits as $default_limit) {
$this->data['limits'][] = array(
'value' => $default_limit,
'href' => $this->url->link('product/pricelist', $url . '&limit='. $default_limit, 'SSL')
);
}

$url = ''; //categories

if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}

if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}

if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}

$this->data['categories'] = array();

$categories = $this->getCategories(0);
foreach($categories as $category)
{
$path = $this->getPath($category['category_id']);
if($path) {
$this->data['categories'][$path] = array(
'category_id' => $category['category_id'],
'parent_id' => $category['parent_id'],
'name' => $path,
'href' => $this->url->link('product/pricelist', $url . '&catid='. $category['category_id'], 'SSL'),
);
}
ksort($this->data['categories']);
}
array_unshift($this->data['categories'], array(
'category_id' => 0,
'parent_id' => 0,
'name' => $this->language->get('text_all_products'),
'href' => $this->url->link('product/pricelist', $url, 'SSL'),
));

$url = ''; //redirect, pagination href

if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}

if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}

if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}

if (isset($this->request->get['catid'])) {
$url .= '&catid=' . $this->request->get['catid'];
}

$data = array(
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit,
);

if($catid) {
$data['filter_category_id'] = $catid;
}
$this->data['catid'] = $catid;

$product_total = $this->model_catalog_product->getTotalProducts($data);

if((($page - 1) * $limit) > $product_total) {
$this->redirect($this->url->link('product/pricelist', $url, 'SSL'));
}

$this->data['products'] = array();

$products = $this->model_catalog_product->getProducts($data);



foreach($products as $product_info) {
if ($this->config->get('config_customer_price') && !$this->customer->isLogged()) {
$product_info['price'] = false;
}

$discount_query = $this->model_catalog_product->getProductDiscounts($product_info['product_id']);

$discounts = array();

if($product_info['price']) {
foreach ($discount_query as $discount) {
$discounts[] = array(
'quantity' => $discount['quantity'],
'price' => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
);
}
}

$this->data['products'][$product_info['product_id']] = array(
'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),
'name' => $product_info['name'],
'attribute_groups' => $this->model_catalog_product->getProductAttributes($result['product_id']),
'special' => $product_info['special'] ? $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : false,
'description' => nl2br($this->word_trim(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 25, TRUE)),

'price' => $product_info['price'] ? $this->currency->format($this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax'))) : false,
);
}

$pagination = new Pagination();
$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->text = $this->language->get('text_pagination');
$pagination->url = $this->url->link('product/pricelist', $url . '&page={page}', 'SSL');

$this->data['pagination'] = $pagination->render();

//print button
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}

$this->data['print'] = $this->url->link('product/pricelist/printable', $url, 'SSL');

$this->data['sort'] = $sort;
$this->data['order'] = $order;
$this->data['limit'] = $limit;
}

private function getCategories($category_id) {
$category_data = array();

$this->load->model('catalog/category');
$categories = $this->model_catalog_category->getCategories($category_id);

foreach ($categories as $category) {
$category_data[] = $category;

$children = $this->getCategories($category['category_id']);

if ($children) {
$category_data = array_merge($children, $category_data);
}

$this->data['sorts'] = array();
}

return $category_data;
}

private function getPath($category_id) {
$this->load->model('catalog/category');
$category_info = $this->model_catalog_category->getCategory($category_id);
if(!$category_info) {
return false;
}
if ($category_info['parent_id']) {
return $this->getPath($category_info['parent_id']) . $this->language->get('text_separator') . $category_info['name'];
}
return $category_info['name'];
}

private function word_trim($string, $count, $ellipsis = FALSE) {
$words = explode(' ', $string);
if (count($words) > $count){
array_splice($words, $count);
$string = implode(' ', $words);
if (is_string($ellipsis)){
$string .= $ellipsis;
} elseif ($ellipsis){
$string .= '&hellip;';
}
}
return $string;
}
}
?>

<?php echo $header; ?>
<link rel="stylesheet" type="text/css" href="catalog/view/theme/elektro_dark/stylesheet/priceList.css" />
<!-- new bread -->
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $i=> $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><?php if($i+1<count($breadcrumbs)) { ?>
<a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
<?php } else { ?>
<?php echo $breadcrumb['text']; ?><?php } ?>
<?php } ?>
</div>
<?php echo $column_left; ?><?php echo $column_right; ?>
<div id="content"><?php echo $content_top; ?>
<h1><?php echo $heading_title; ?></h1>
<?php if (!isset($error_customer_group)) { ?>

<div class="filter-control">
<div class="fleft">
<strong><?php echo $text_category; ?></strong>
<select name="category_id" onchange="location = this.value;">
<?php foreach($categories as $category){ ?>
<?php if ($category['parent_id'] == 0) { ?>
<option value="<?php echo $category['href']; ?>"
<?php if($catid == $category['category_id']) { ?> selected="selected"<?php } ?>><?php echo $category['name']; ?>
</option>
<?php }?>
<?php } ?>
</select>
</div>
<div class="fright">
<strong><?php echo $text_limit; ?></strong> <select name="limit" onchange="location = this.value;">
<?php foreach($limits as $limit_value) { ?>
<option value="<?php echo $limit_value['href']; ?>"<?php if($limit == $limit_value['value']) { ?> selected="selected"<?php } ?>><?php echo $limit_value['value']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="print-control">
<div class="fright">
<a href="<?php echo $print; ?>" class="button" target="_blank"><span><?php echo $text_print; ?></span></a>
</div>
</div>
<div class="pricelist">
<table>
<thead>
<tr>
<th class="name">Название</th>
<th class="name">Описание</th>
<th class="name">Опции</th>
<th class="name">Цена</th>
</tr>
</thead>
<tbody>
<?php if(!empty($products)) { ?>
<?php foreach($products as $product_id => $product) { ?>
<tr>
<td class="name">
<a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
</td>
<td class="desc">
<?php echo $product['description']; ?>
</td>

<td>
<?php if($product['attribute_groups']) { ?>
<table>
<?php foreach($product['attribute_groups'] as $attribute_group) { ?>
<thead><!--названия групп-->
<tr>
<td colspan="2"><?php echo $attribute_group['name']; ?></td>
</tr>
</thead><!---->
<tbody>
<?php foreach($attribute_group['attribute'] as $attribute) { ?>
<tr>
<td><?php echo $attribute['name']; ?></td>
<td><?php echo $attribute['text']; ?></td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
</table>
<?php } ?>

</td>

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

<?php } else { ?>-<?php } ?>
</td>
</tr>
<?php } ?>
<?php } else { ?>
<tr><td colspan="8" class="tcenter"><?php echo $text_empty; ?></td></tr>
<?php } ?>
</tbody>
</table>
<div class="pagination"><?php echo $pagination; ?></div>
</div>

<?php } else { ?>
<div class="content"><?php echo $text_empty; ?></div>
<div class="buttons">
<div class="right"><a href="<?php echo $continue; ?>" class="button"><span><?php echo $button_continue; ?></span></a></div>
</div>
<?php } ?>
<div class="bottom"></div>
<?php echo $content_bottom; ?></div>
<?php echo $footer; ?>
 
Спроси у автора модуля, я с ним общался, он адекватный но занятой чел.
Правда реально пока не купил у него мод ничего толком не добился ;-
 
  • Автор темы
  • Заблокирован
  • #3
а как вообще получить атрибуты ?
через
Код:
$this->data['attribute_groups'] = $this->model_catalog_product->getProductAttributes($this->request->get['product_id']);

не получается
 
Атрибуты выводятся в шаблоне через цикл:
Код:
<?php foreach($product['attribute_groups'] as $attribute_group) { ?>
.........
Незнаю поможет тебе или нет, просто скажу тебе идею как я выводил (просто в карточке товара, не через этот модуль) характеристики в столбец, т.к не нашел как получить отдельно каждый атрибут.
Создал группу атрибутов (у меня Варианты камней)
В нее добавил 4 нужных мне значения: Название камней Кол-во камней Вес камня (карат) Вид огранки
В самом товаре скажем в Название камней я вносил 2-3 наименования и их разделял любыми символами, скажем **, т.е Изумруд ** Топаз
Затем в карточке товара переделал вывод атрибутов, и делаю замену ** на <hr> (можешь через <br>)
Код:
  <table class="attribute">
      <?php foreach ($attribute_groups as $attribute_group) { ?>
      <thead>
        <tr>
          <td><?php echo $attribute_group['name']; ?></td>
        </tr>
      </thead>
      <tbody>
        <tr>
        <?php foreach ($attribute_group['attribute'] as $attribute) { ?>

          <td><?php echo $attribute['name']; ?></td>

        <?php } ?>
        </tr>

      <tr>
        <?php foreach ($attribute_group['attribute'] as $attribute) { ?>

          <td class="atrib-descr"><?php echo str_replace("**", "<hr>", $attribute['text']); ?></td>

        <?php } ?>
        </tr>

      </tbody>
      <?php } ?>
    </table>
  </div>
  <?php } ?>

Вот как это выглядит в карточке товара - Для просмотра ссылки Войди или Зарегистрируйся
Вот как в админке в товаре - Для просмотра ссылки Войди или Зарегистрируйся
 
  • Автор темы
  • Заблокирован
  • #5
цикл как вывести я нашел, просто я переделываю модуль прайса, а он работает через свой контроллер, а вот как в контроллер загрузить атрибуты, не могу понять
 
Пробуй сделать по аналогии, Vqmod во вложении..
 

Вложения

  • Product_Options_price.rar
    2,3 KB · Просмотры: 19
  • Автор темы
  • Заблокирован
  • #8
Получилось вывести, но не получается заменить пустые записи на "-"

Код:
<?php foreach ($product['attribute_groups'] as $attribute_group) { ?>
  <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
    <td class="attr">
    <?php if (!empty($attribute['text'])) { ?>
      <?php echo $attribute['text']; ?>
    <?php } else { ?>
      <?php echo ' - '?>
    <?php } ?>
    </td>                                              
 <?php } ?>
<?php } ?>
 
Получилось вывести, но не получается заменить пустые записи на "-"

Код:
<?php foreach ($product['attribute_groups'] as $attribute_group) { ?>
  <?php foreach ($attribute_group['attribute'] as $attribute) { ?>
    <td class="attr">
    <?php if (!empty($attribute['text'])) { ?>
      <?php echo $attribute['text']; ?>
    <?php } else { ?>
      <?php echo ' - '?>
    <?php } ?>
    </td>                                             
<?php } ?>
<?php } ?>
Получилось сделать? можешь кинуть ?
 
  • Автор темы
  • Заблокирован
  • #10
Получилось сделать? можешь кинуть ?
привет, да получилось, но это было пол года назад, делал клиентосу одному, но кода не сохранилось и возможности взять у него тоже нет
 
Назад
Сверху