Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Добавить стиль к кнопке "В закладки" если данный товар находится уже в закладках


Recommended Posts

Собственно весь вопрос в теме: Как добавить стиль к кнопке "В закладки" если данный товар находится уже в закладках?

Может кто гделал икое?

Спасипотому что!

Link to comment
Share on other sites

вот из заготовок решение, не мое, но рилииет норм.

 

Спойлер

    
catalog\model\account\wishlist.php
    
    public function getAllWishlist() {
        if ($data = $this->getWishlist()) {
            $out = array();
            foreach ($data as $key => $value) {
                $out[] = $value['product_id'];
            }
            return $out;
        } else if (isset($this->session->data['wishlist'])) {
            return $this->session->data['wishlist'];
        }

    }
    
    


    
catalog\view\theme\default\template\product\category.tpl    


вместо:
<button type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-heart"></i></button>


это:
    
    
     <button
                  <?php if(isset($AllWishlist)) { ?>
                      <?php if(in_array($product['product_id'], $AllWishlist)) { ?>
                          style="color: red"
                      <?php } ?>
                  <?php } ?>

type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>'); ChangeColor(this);"><i class="fa fa-heart"></i></button>       
            
                
                
                <script type="text/javascript">
          function ChangeColor(Element) {
            Element.style.color = 'red';
          }
          </script>
          


catalog\controller\product\category.php    

перед      
          
$data['breadcrumbs'] = array();          

это:
$this->load->model('account/wishlist');
        $data['AllWishlist'] = $this->model_account_wishlist->getAllWishlist();    
        
        
        
catalog\controller\product\product.php


перед

if ($product_info) {
            $url = '';
            
            
это:


$this->load->model('account/wishlist');
        $zol_wish = $this->model_account_wishlist->getAllWishlist();
        if (isset($product_id) && isset($zol_wish)) {
          if (in_array($product_id, $zol_wish)) {
            $data['AllWishlist'] = true;
          }
          }
          
          
          
          
catalog\view\theme\default\template\product\product.tpl


вместо:
<button type="button" data-toggle="tooltip" class="btn btn-default" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product_id; ?>');"><i class="fa fa-heart"></i></button>
          
это:          
      <button 
            <?php if(isset($AllWishlist)) { ?>
                    style="color: red" 
                  <?php } ?> 
                 type="button" data-toggle="tooltip" class="btn btn-default" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product_id; ?>'); ChangeColor(this);"><i class="fa fa-heart"></i></button>
                 
           
            <script type="text/javascript">
          function ChangeColor(Element) {
            Element.style.color = 'red';
          }
          </script>
            

    
          
          
          
 

 

Link to comment
Share on other sites

19 минут назад, anboza сказал:

и не забудьте обновить кеш всего. изменения вносятся и в могдели и в контроллеры

 

Notice: Undefined variable: this in /system/storage/modification/catalog/controller/product/category.php on line 42Notice: Trying to get property of non-object in /system/storage/modification/catalog/controller/product/category.php on line 42

Link to comment
Share on other sites

  • 2 years later...

Добрый гдень, но при возврате в каилог товаров сергдечки опять теряют цвет? был бы смысл их подкрашивать чтоб при вхогде залогиненного пользователя он в каилоге сразу увигдел что товар был отмечен! и в карточке товара осивить красное сергдечко

 

Link to comment
Share on other sites


  • 7 months later...
В 09.08.2018 в 22:18, anboza сказал:

вот из заготовок решение, не мое, но рилииет норм.

 

  Скрыть контент

    
catalog\model\account\wishlist.php
    
    public function getAllWishlist() {
        if ($data = $this->getWishlist()) {
            $out = array();
            foreach ($data as $key => $value) {
                $out[] = $value['product_id'];
            }
            return $out;
        } else if (isset($this->session->data['wishlist'])) {
            return $this->session->data['wishlist'];
        }

    }
    
    


    
catalog\view\theme\default\template\product\category.tpl    


вместо:
<button type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-heart"></i></button>


это:
    
    
     <button
                  <?php if(isset($AllWishlist)) { ?>
                      <?php if(in_array($product['product_id'], $AllWishlist)) { ?>
                          style="color: red"
                      <?php } ?>
                  <?php } ?>

type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>'); ChangeColor(this);"><i class="fa fa-heart"></i></button>       
            
                
                
                <script type="text/javascript">
          function ChangeColor(Element) {
            Element.style.color = 'red';
          }
          </script>
          


catalog\controller\product\category.php    

перед      
          
$data['breadcrumbs'] = array();          

это:
$this->load->model('account/wishlist');
        $data['AllWishlist'] = $this->model_account_wishlist->getAllWishlist();    
        
        
        
catalog\controller\product\product.php


перед

if ($product_info) {
            $url = '';
            
            
это:


$this->load->model('account/wishlist');
        $zol_wish = $this->model_account_wishlist->getAllWishlist();
        if (isset($product_id) && isset($zol_wish)) {
          if (in_array($product_id, $zol_wish)) {
            $data['AllWishlist'] = true;
          }
          }
          
          
          
          
catalog\view\theme\default\template\product\product.tpl


вместо:
<button type="button" data-toggle="tooltip" class="btn btn-default" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product_id; ?>');"><i class="fa fa-heart"></i></button>
          
это:          
      <button 
            <?php if(isset($AllWishlist)) { ?>
                    style="color: red" 
                  <?php } ?> 
                 type="button" data-toggle="tooltip" class="btn btn-default" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product_id; ?>'); ChangeColor(this);"><i class="fa fa-heart"></i></button>
                 
           
            <script type="text/javascript">
          function ChangeColor(Element) {
            Element.style.color = 'red';
          }
          </script>
            

    
          
          
          
 

 

а как вывести в модулях, Рекомендуемые, Новинки... 

Link to comment
Share on other sites


  • 4 months later...

А кто підкаже как реалізувати ике:

 

Якчто товар уже в закладках, повинна изменениятися запис замысть "в закладки" на "уже в закладках" і при клацаннет на значок закладок відкривались закладки, а не спливаюче вікно, что товар снова додано в закладки..

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

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.