1

How to get latest 5 Seller id's. Let us assume i am A Seller in backend i have option other seller block show my profile. In above mention image i update seller id it will display but now i want to automatically get latest 5 seller id Check this url This is my seller method

public function updateOtherSellersAction() {

        $fieldId = (int) $this->getRequest()->getParam('id');
        $otherSellerIds = $this->getRequest()->getParam('include_in_othersellers');
        try {
            if ($fieldId) {
                $model = Mage::getModel('marketplace/sellerprofile')->load($fieldId, 'seller_id');
                $model->setData ( 'include_in_othersellers', $otherSellerIds)->save ();
            }
        }
        catch ( Exception $e ) {
                Mage::getSingleton ( 'adminhtml/session' )->addError ( $e->getMessage () );
        }

    }

Here i want to show my other seller id

enter image description here

.phtml

<script type="text/javascript">
function updateOtherSellersField(button, fieldId)
{
    new Ajax.Request('<?php echo Mage::helper('adminhtml')->getUrl('*/*/updateOtherSellers') ?>', {
        method: 'post',
        parameters: { id: fieldId, include_in_othersellers: $(button).previous('input').getValue() },
        complete : alert("Other Sellers Block list has been updated successfully.")
    });
}
</script>

Admin grid

$this->addColumn('include_in_othersellers', array(
                'header'           => Mage::helper('marketplace')->__('Include in Other Sellers Block'),
                'align'            => 'center',
                'renderer'         => 'marketplace/adminhtml_widget_grid_column_renderer_inline',
                'index'            => 'include_in_othersellers',
        ));


<?php
class Apptha_Marketplace_Block_Adminhtml_Widget_Grid_Column_Renderer_Inline
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Input
{
    public function render(Varien_Object $row)
    {
        $list = $this->OtherSellerList($row);
        $html .= '<input type="text" name="'.$row->getId().'" value = "'.$list.'"/>';
        $html .= '<button onclick="updateOtherSellersField(this, '. $row->getId() .'); return false">' . Mage::helper('marketplace')->__('Update') . '</button>';

        return $html;
    }

    public function OtherSellerList(Varien_Object $row)
    {
        $id = $row->getData();
        foreach ($id as $_id) {
            $sellerProduct = Mage::helper('marketplace/marketplace')->getSellerCollection($_id);
            return $sellerProduct['include_in_othersellers'];

        }

    }

}
  • Explain properly what do you mean by other seller id ? Other seller id is considering in latest 5 or not. – Prashant Valanda Mar 13 '16 at 19:47
  • this is comma separated values or single value in this column include_in_othersellers – Qaisar Satti Mar 15 '16 at 5:20
  • it shows 100,101,102 like this – Magento 2 Mar 15 '16 at 5:29
  • you want to retrieve this data? – Qaisar Satti Mar 15 '16 at 5:37
  • Yes i wan to get Latest Seller Id – Magento 2 Mar 15 '16 at 5:40
2
$model = Mage::getModel('marketplace/sellerprofile')->load($fieldId); // you current seller id

echo $model->getIncludeInOthersellers(); // this will give you desired 

in renderer add this code for getting values

public function OtherSellerList(Varien_Object $row)
    {
        $id = $row->getId();
       $otherseller = Mage::getModel('marketplace/sellerprofile')->getCollection();
$otherseller->setPageSize(5)
        ;
$otherseller->getSelect()->order(new Zend_Db_Expr('RAND()'));
  $sellerid=array();
   foreach($otherseller as $seller)
    {
    $sellerid[]=$seller->getId();
     }

return implode(',',$sellerid);



    }
| improve this answer | |
  • Where i need to add controllers or phtml – Magento 2 Mar 15 '16 at 5:45
  • where you want to display it.. – Qaisar Satti Mar 15 '16 at 5:46
  • In backend only so in my question i added image there i want to display – Magento 2 Mar 15 '16 at 5:47
  • this field come from form add that field code too.. – Qaisar Satti Mar 15 '16 at 5:51
  • You mean Block file or what – Magento 2 Mar 15 '16 at 5:52
1

You need to sort collection using seller id in descending order like below

$model = Mage::getModel('marketplace/sellerprofile')->getCollection()->setOrder('seller_id', 'desc'); 
$model->getSelect()->limit(5);
| improve this answer | |
  • It's not showing check my updated question – Magento 2 Mar 13 '16 at 9:07
  • How to show that text box – Magento 2 Mar 13 '16 at 9:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.