Untitled

mail@pastecode.io avatar
unknown
php
a year ago
2.9 kB
1
Indexable
Never
protected function renderForm()
    {

       

        
//        $img_url = ImageManager::thumbnail(
//            $logoPath,
//            'carrier_mini_' . $this->l('ID') . '.jpg',
//            34
//        );
       // $img_url = ImageManager::thumbnail($logoPath, $logoPath, 350,
        //    'jpg', true, true);
       // $image_size = file_exists($logoPath) ? filesize($logoPath) / 1000 : false;
        //var_dump($this->id);


        $fields = array(
            'id_carrier' => array(
                'title' => $this->l('ID'),
                'width' => 140,
                'type' => 'text',
            ),
           'custom_image' => array(
                'title' => 'Logo',
                'type' => 'text',
                'align' => 'center',
                'callback' => 'printCarrierIcon',            
            ),
            'name' => array(
                'title' => $this->l('Name'),
                'width' => 140,
                'type' => 'text',
            ),
            'service_fees' => array(
                'title' => 'Frais de préparation',
                'width' => 60,
                'type' => 'text',
            )
        );

        $helper = new HelperList();
        $helper->shopLinkType = '';
        $helper->simple_header = false;
        $helper->token = Tools::getAdminTokenLite('AdminModules');

        $helper->actions = array('edit');

        $helper->identifier = 'id_carrier';
        $helper->show_toolbar = true;
        $helper->title = 'Frais de préparation';

        /*$helper->fieldImageSettings = array(
            'name' => 'logo',
            'dir' => 's',
        );*/

        $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->sibling->name;
        //$carrier_list = CarrierCore::getCarriers(Context::getContext()->language->id, false, false, false, null, CarrierCore::ALL_CARRIERS);

         $sql = 'SELECT `' . _DB_PREFIX_ . 'carrier`.id_carrier,0 as custom_image,`' . _DB_PREFIX_ . 'carrier`.name,`' . _DB_PREFIX_ . 'fa_carrier_services`.services_fees
                 FROM `' . _DB_PREFIX_ . 'carrier` 
                 LEFT JOIN `' . _DB_PREFIX_ . 'fa_carrier_services` ON `' . _DB_PREFIX_ . 'carrier`.id_carrier = `' . _DB_PREFIX_ . 'fa_carrier_services`.carrier_id_carrier
                 WHERE `' . _DB_PREFIX_ . 'carrier`.active = 1 and `' . _DB_PREFIX_ . 'carrier`.deleted = 0';

        $list = Db::getInstance()->ExecuteS($sql);

        for($i = 0; $i < count($list); $i++){ 
            $logoPath = _PS_TMP_IMG_DIR_ .'/carrier_mini_'. $list[$i]['id_carrier'] . '_1.jpg';
            $this->fields_value[0]['image'] = $logoPath;
        }

        return $helper->generateList($list, $fields);
    }

    public function printCarrierIcon($value)
    {
        return '<span class="label label-primary">Test Label</span>';
    }