Jump to content

Welcome, Guest!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

  • 0
Pedalman

incompatibility with BELVG Sticker module

Question

Hello

I do not know whether there is a difference between PS1.6 and TB's image controller but my BELVG Sticker PRO module fails to create my "sticker badges" on product thumb.

Here is code of two admin controller overrides it needs:

AdminImportController.php

<?php

class AdminImportController extends AdminImportControllerCore
{
    public function __construct()
    {
        parent::__construct();

        if (Tools::getValue('entity') == $this->entities[$this->l('Products')]) {
            $this->available_fields['belvg_stickerspro'] =  array('label' => $this->l('Belvg StickersPro'));
        }
    }

    
    public function productImport()
    {
        parent::productImport();

        $this->receiveTab();
        $handle = $this->openCsvFile();
        for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++)
        {
            if (Tools::getValue('convert')) {
                $line = $this->utf8EncodeArray($line);
            }

            $info = AdminImportController::getMaskedRow($line);

            if (Tools::getValue('forceIDs') && isset($info['id']) && (int)$info['id']) {
                $product = new Product((int)$info['id']);
            } elseif (Tools::getValue('match_ref') && array_key_exists('reference', $info)) {
                $datas = Db::getInstance()->getRow('
                            SELECT p.`id_product`
                            FROM `'._DB_PREFIX_.'product` p
                            '.Shop::addSqlAssociation('product', 'p').'
                            WHERE p.`reference` = "'.pSQL($info['reference']).'"
                        ');
                if (isset($datas['id_product']) && $datas['id_product']) {
                    $product = new Product((int)$datas['id_product']);
                } else {
                    $product = new Product();
                }
            } elseif (array_key_exists('id', $info) && (int)$info['id'] && Product::existsInDatabase((int)$info['id'], 'product')) {
                $product = new Product((int)$info['id']);
            } else {
                //$product = new Product();
                continue;
            }

            //Belvg StickersPro logic
            $belvg_stickerspro_module = Module::getInstanceByName('belvg_stickerspro');
            if (is_object($belvg_stickerspro_module) && $belvg_stickerspro_module->id) {
                $stickers = explode($this->multiple_value_separator, $info['belvg_stickerspro']);
                if (count($stickers)) {
                    $ids_stickers = array();
                    foreach ($stickers as $sticker) {
                        if ($sticker) {
                            $ids_stickers[$sticker] = 1;
                        }
                    }

                    if (count($ids_stickers)) {
                        $sticker_flag = TRUE;
                        $sticker_flag &= BelvgStickersProProduct::deleteDataForProduct((int)$product->id, $ids_stickers, Context::getContext()->shop->id);
                        $sticker_flag &= BelvgStickersProProduct::setDataForProduct((int)$product->id, $ids_stickers, Context::getContext()->shop->id);
                        if ($sticker_flag) {
                            $sticker_flag &= $belvg_stickerspro_module->applyStickersToImage($product->id, $ids_stickers);
                            if ($sticker_flag) {
                                $sticker_flag &= BelvgStickersProIndexer::deleteItemsByProductId((int)$product->id);
                            }
                        }
                    }
                }
            }
        }
        
        $this->closeCsvFile($handle);
    }
}

AdminImagesController.php

class AdminImagesController extends AdminImagesControllerCore
{

    /**
     * AdminImagesController::__construct()
     * 
     * @return void
     */
    public function __construct()
    {
        require_once (_PS_MODULE_DIR_ .
            'belvg_stickerspro/classes/Belvg_StickersPro.php');

        parent::__construct();
        $this->fields_list['stickers'] = array(
            'title' => $this->l('Stickers'),
            'width' => 50,
            'align' => 'center',
            'type' => 'bool',
            'callback' => 'printEntityActiveIcon',
            'orderby' => FALSE); //Belvg StickersPro

        $this->_select .= 'belvg_sit.stickers';
        $this->_join .= ('LEFT JOIN `' . _DB_PREFIX_ .
            'belvg_stickerspro_image_type` belvg_sit ON (a.`id_image_type` = belvg_sit.`id_image_type`)');

        $this->fields_form['input'][] = array(
            'type' => 'switch',
            'label' => $this->l('Stickers'),
            'name' => 'stickers',
            'required' => FALSE,
            'class' => 't',
            'is_bool' => TRUE,
            'hint' => $this->l('This type will be used for stickers feature.'),
            'values' => array(
                array(
                    'id' => 'stickers_on',
                    'value' => 1,
                    'label' => $this->l('Enabled')),
                array(
                    'id' => 'stickers_off',
                    'value' => 0,
                    'label' => $this->l('Disabled')),
                )); //Belvg StickersPro
    }

    /**
     * AdminImagesController::renderForm()
     * 
     * @return
     */
    public function renderForm()
    {
        if (is_object($this->object)) {
            $stickerspro_values = BelvgStickersProModel::getImageTypesData($this->object->
                id);
            if (!empty($stickerspro_values)) {
                $this->fields_value['stickers'] = $stickerspro_values['stickers'];
                //$this->fields_value['sticker_height'] = $stickerspro_values['sticker_height'];
                //$this->fields_value['sticker_width'] = $stickerspro_values['sticker_width'];
            }
        }

        return parent::renderForm();
    }

    /**
     * AdminImagesController::postProcess()
     * 
     * @return
     */
    public function postProcess()
    {
        $return = parent::postProcess();

        //$id_image_type = Tools::getValue('id_image_type');
        $stickers = Tools::getValue('stickers');
        $products = Tools::getValue('products');
        if (empty($this->errors)) {
            $is_add = Tools::getValue('submitAddimage_type');
            if ($is_add) {
                //$is_exists = BelvgStickersProModel::checkExistsByImageTypeId($id_image_type);
                //if (!$is_exists) {
                $object = $this->loadObject();

                if (!$products) {
                    $stickers = 0;
                }

                BelvgStickersProModel::addTypeByImageTypeId($object->id, $stickers['stickers']);

                //}
            }
        }

        return $return;
    }

    /**
     * AdminImagesController::processDelete()
     * 
     * @return bool
     */
    public function processDelete()
    {
        $return = parent::processDelete();

        $id_image_type = Tools::getValue('id_image_type');
        BelvgStickersProModel::deleteTypeByImageTypeId($id_image_type);

        return $return;
    }

    public function renderList()
    {
        $html = parent::renderList();
        $this->context->smarty->assign(array(
            'belvg_stickerspro_submit' => $this->context->link->getAdminLink('AdminStickersPro'),
            'belvg_stickerspro_list' => BelvgStickersProIndexer::getItems(0, 0),
            'belvg_stickerspro_last_records' => BelvgStickersProIndexer::getItems(0, 5),
        ));
        $html .= $this->context->smarty->fetch(_PS_MODULE_DIR_ . '/belvg_stickerspro/views/templates/admin/indexer.tpl');

        return $html;
    }
} 

 

Can someone see on the run if there is a conflict or might provide a solution?

Edited by Pedalman
corrected content of 2nd override

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hello

I could get it working again after totally deleting module's folder and also! /img/belvg_stickerspro. Eventually I could install it as new module and stickers appeared again. I want to add that resetting and normal deinstall did not work. So, all is fine at the moment.

Thank you

Share this post


Link to post
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

×