Jump to content

Need to know how to add option for inline edit and update values in render list


Recommended Posts

I have created the render list as like below code, I have created new module and in controller I have written the code as like this,

public function renderList()
    {
        $sql = new DbQuery();
        $sql->select('pa.*, pr.price as proprice, if(pr.active = 1 , true, false) as prostatus, pl.name as pname, ag.id_attribute_group, ag.is_color_group, agl.name AS group_name, al.name AS attribute_name, a.id_attribute, pa.unit_price_impact');
        $sql->from('product_attribute', 'pa');
        $sql->leftJoin('product_attribute_combination', 'pac', 'pac.id_product_attribute = pa.id_product_attribute');
        $sql->leftJoin('attribute', 'a', 'a.id_attribute = pac.id_attribute');
        $sql->leftJoin('product', 'pr', 'pr.id_product = pa.id_product');
        $sql->leftJoin('product_lang', 'pl', 'pl.id_product = pr.id_product AND pl.id_lang = 1');
        $sql->leftJoin('attribute_group', 'ag', 'ag.id_attribute_group = a.id_attribute_group');
        $sql->leftJoin('attribute_lang', 'al', '(a.id_attribute = al.id_attribute AND al.id_lang = 1)');
        $sql->leftJoin('attribute_group_lang', 'agl', '(ag.id_attribute_group = agl.id_attribute_group AND agl.id_lang = 1)');
        //$sql->where('pr.active = 1');
        $sql->orderBy('pa.id_product_attribute');
        $links = Db::getInstance()->ExecuteS($sql);

        // CONTENT
        $fields_list = array(
            'pname' => array(
                'title' => $this->trans('Product', array(), 'Admin.Global'),
                'align' => 'center',            // Align Col (not header)
                //'width' => 50,                // header search : width
                'type'  => 'text',
                'class' => 'fixed-width-xs',    // class css
                'search' => true,              // header search : display
                'orderby' => true,              // header search : order

            ),
            'attribute_name' => array(
                'title' => $this->l('Attribute'),
                'type' => 'text',
            ),
            'reference' => array(
                'title' => $this->l('Reference'),
                'type' => 'text',
            ),
            'price' => array(
                'title' => $this->trans('Impact Price Tax(Excl)', array(), 'Admin.Global'),
                'type' => 'text',
                'inline' => true,
            ),
            'proprice' => array(
                'title' => $this->trans('Price Tax(Excl)', array(), 'Admin.Global'),
                'type' => 'text',
            ),
            'prostatus' => array(
                'title' => $this->l('Status'),
                'type' => 'bool',
                'align' => 'center',
                'active' => 'status',
                'ajax' => true,
            )
        );


        // TOOLBAR
        $this->initToolbar();

       
        $helper = new HelperList();
        
        $helper->orderBy = 'id_product';
        $helper->orderWay = 'DESC';
        $helper->bulk_actions = true;       // bulk_actions
       
        $helper->shopLinkType = '';
        $helper->no_link = true;       // Content line is clickable if false
        $helper->simple_header = false; // false = search header, true = not header. No filters, no paginations and no sorting.
        $helper->actions = array('');
        $helper->show_toolbar = false;
        $helper->module = $this;
        $helper->listTotal =  count($links);
        $helper->_default_pagination = 50;
        $helper->toolbar_scroll = true;
        $helper->identifier = 'id_product_attribute';
        $helper->title = $this->l('Product Combination Price List');
        $helper->table = 'product_attribute';
        $helper->token = Tools::getAdminTokenLite('BulkPriceUpdate');
        $helper->currentIndex = self::$currentIndex.'&details';
        
        return $helper->generateList($links, $fields_list);
    }

Now I can see this listing in admin page. Now I need to update price column alone as inline edit text field by that I can update the each product combination price from this listing itself. I have to create dynamic form for each row and I need to update this field value into database. I need to know how to create text box in this listing and how to submit this text box value to controller to update in ps_product_attribute  table. Please help any one I 'm trying last 1 week for this solution.

Link to comment
Share on other sites

Hello:

In the lists there is a field of type 'type' => 'editable' (\ admin123 \ themes \ default \ template \ helpers \ list \ list_content.tpl line 122 in PS 1.7). The problem you are going to have next is knowing how to send such information to the controller to process it. You may have to do it through ajax.

 

Link to comment
Share on other sites

Hello, 

Thanks for your reply, I have tried as your suggestion 

'price' => array(
                'title' => $this->trans('Impact Price Tax(Excl)', array(), 'Admin.Global'),
                'type' => 'editable',
                'ajax' => true,
            ),

But still it showing like label, couldn't display as editable field. Could you pleases help me on this.

Edited by rvkvino (see edit history)
Link to comment
Share on other sites

23 hours ago, rvkvino said:

Hello, 

Thanks for your reply, I have tried as your suggestion 

'price' => array(
                'title' => $this->trans('Impact Price Tax(Excl)', array(), 'Admin.Global'),
                'type' => 'editable',
                'ajax' => true,
            ),

But still it showing like label, couldn't display as editable field. Could you pleases help me on this.

You need to add and 'id' field:

'price' => array(
                'title' => $this->trans('Impact Price Tax(Excl)', array(), 'Admin.Global'),
                'type' => 'editable',
                'ajax' => true,

                'id' => 'unique_id'
            ),

You need to check the file I mentioned before to understand better what are this field options.

Regards

Link to comment
Share on other sites

Thanks for your response, I have tried with id even though it didn't work. Even I have checked with  unique id for each column but didn't work.

I have done this by using callbacks as like below code,

'callback' => 'editableCombinationPriceMethod',

and then in call back method

public function editableCombinationPriceMethod($value, $product)
    {
        return '<form class="qty active" method="post" id="form_'.(int)$product['id_product_attribute'].'" action="'.self::$currentIndex.'&id_product_attribute='.(int)$product['id_product_attribute'].'&changeCombinationPrice&token='.Tools::getAdminTokenLite('BulkPriceUpdate').'"><div class="ps-number edit-qty hover-buttons text-right" style="display:flex;" placeholder="0"><input type="number" step="any" name="price" class="form-control" value="'.number_format($value, 2,'.','').'" /><button type="submit" form="form_'.(int)$product['id_product_attribute'].'" class="check-button"><i class="material-icons list-action-enable">done</i></button></div></form>';
    }

Now it's working but it everything is in server side. For every time update the field value it submit the page and reload and re-render the page. It taking much time to update a single field value update.

And I'm getting struggle to update the field value by using ajax. My controller method is not triggering for ajax call.

For simple I have tried the below Ajax method but it not working(I feel didn't create proper method to update the ajax call)

'prostatus' => array(
                'title' => $this->l('Status'),
                'type' => 'bool',
                'align' => 'center',
                'active' => 'status',
                'ajax'     => true,
            )

When I click on this field ajax call getting trigger like https://domain.in/admincp/index.php?controller=BulkPriceUpdate&amp;id_product_attribute=44&amp;statusproduct_attribute&amp;action=statusproduct_attribute&amp;ajax=1&amp;token=c32bcae851932156b02f99f76f603686

But I don't know in which name I have to create a method in my controller, I have tried as like below method names but no use,

public function statusproduct_attribute(){
        $id_product_attribute = (int)Tools::getValue('id_product_attribute');
        echo "IDP: ".$id_product_attribute;
    }
    public function ajaxStatusProduct_Attribute(){
        $id_product_attribute = (int)Tools::getValue('id_product_attribute');
        echo "IDP: ".$id_product_attribute;
    }
     public function ajaxstatusproduct_attribute(){
        $id_product_attribute = (int)Tools::getValue('id_product_attribute');
        echo "IDP: ".$id_product_attribute;
    }

Could you please help me to solve these 2 issue 

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
×
×
  • Create New...