Comment les données unserialize de la colonne Sales_Flat_Order_Payment (de additional_information) à afficher dans la grille de mesure?

magento.stackexchange https://magento.stackexchange.com/questions/12329

Question

Je suis à la recherche d'un moyen de paiement à l'information d'affichage dans une grille.

J'ai remarqué qu'il ya une additional_information colonne à l'intérieur de table sales_flat_order_payment qui contient la plupart des données dont j'ai besoin, mais est publié en feuilleton.

a:10:{s:19:"paypal_ec_create_ba";N;s:8:"CC_BRAND";...

Le problème est que je dois montrer certaines de ces données dans la grille de manière filtrables!

Y at-il un moyen de unserialize ces valeurs?

J'apprécierait des suggestions sur la façon d'obtenir ces données dans un format admissible.

J'ai ajouté un fichier Renderer.php à mon module

class Custom_Module_Block_Adminhtml_Order_Grid_Renderer_Payment extends

Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{

    public function render(Varien_Object $row)
    {
        $value = unserialize($row->getData('additional_information'));

        return $value;
    }
}

Et voici ma grille

<?php

class Custom_Module_Block_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
{

    public function __construct()
    {
        parent::__construct();
        $this->setId('sales_order_grid');
        $this->setUseAjax(true);
        $this->setDefaultSort('created_at');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
    }

    protected function _getCollectionClass()
    {
        return 'sales/order_grid_collection';
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());

        $collection->getSelect()->joinLeft(array('sales_flat_order_payment'),
            'parent_id=main_table.entity_id',array('additional_information'));

        $collection->getSelect()->joinLeft(array('spt'=>'sales_payment_transaction'),
            'spt.transaction_id=main_table.entity_id',array('spt.payment_id', 'spt.txn_id'));

        $collection->getSelect()->joinLeft(array('sfo'=>'sales_flat_order'),
            'sfo.entity_id=main_table.entity_id',array('sfo.customer_email',
            'sfo.weight','sfo.discount_description','sfo.increment_id','sfo.store_id',
            'sfo.created_at','sfo.status','sfo.base_grand_total','sfo.grand_total'));

        $collection->getSelect()->joinLeft(array('ops' => 'ops_alias'),
            'ops.customer_id=main_table.entity_id', array('alias','brand', 'payment_method'));

        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _paymentFilter($collection, $column)
    {
        if (!$value = $column->getFilter()->getValue()) {
            return $this;
        }
        $value = ($column->getFilter()->getValue());
        $this->getCollection()->getSelect()->where(
            "sales_flat_order_payment.additional_information like ?"
            , "%$value%");
        return $this;
    }

    protected function _prepareColumns()
    {
        $this->addColumn('order_id', array(
            'header' => Mage::helper('sales')->__('Order Id'),
            'align' =>'left',
            'index' => 'increment_id',
            'filter_index'=>'sfo.increment_id',
        ));

        $this->addColumn("created_at", array(
            "header" => Mage::helper("sales")->__("Order Date"),
            "index" => "created_at",
            'filter_index'=>'sfo.created_at',
            "type" => "date",
        ));

        $this->addColumn("billing_name", array(
            "header" => Mage::helper("sales")->__("Billing Name"),
            "index" => "billing_name",
        ));

        $this->addColumn('customer_email', array(
            'header' => Mage::helper('sales')->__('Customer Email'),
            'index' => 'customer_email',
            'filter_index' => 'sfo.customer_email',
            'width' => '50px',
        ));

        /* Additional Payment Information*/

        $this->addColumn('additional_information', array(
            'header'    => Mage::helper('sales')->__('Payment Information'),
            'filter_condition_callback' => array($this, '_paymentFilter'),
            'renderer' => 'Custom_Module_Block_Adminhtml_Order_Grid_Renderer_Payment'
        ));

        $this->addColumn('payment_id', array(
            'header'        => Mage::helper('sales')->__('Payment ID'),
            'align'         => 'right',
            'index'         => 'payment_id',
            'filter_index' => 'spt.payment_id',
        ));

        $this->addColumn('grand_total', array(
            'header' => Mage::helper('sales')->__('Order Total'),
            'index' => 'grand_total',
            'filter_index'=>'sfo.grand_total',
            'type'  => 'currency',
            'currency' => 'order_currency_code',
        ));

        $this->addColumn('status', array(
            'header' => Mage::helper('sales')->__('Status'),
            'index' => 'status',
            'filter_index'=>'sfo.status',
            'type'  => 'options',
            'width' => '70px',
            'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
        ));

        if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
            $this->addColumn('action',
                array(
                    'header'    => Mage::helper('sales')->__('Action'),
                    'width'     => '50px',
                    'type'      => 'action',
                    'getter'     => 'getId',
                    'actions'   => array(
                        array(
                            'caption' => Mage::helper('sales')->__('View'),
                            'url'     => array('base'=>'adminhtml/sales_order/view'),
                            'field'   => 'order_id'
                        )
                    ),
                    'filter'    => false,
                    'sortable'  => false,
                    'index'     => 'stores',
                    'is_system' => true,
                ));
        }

        $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
        $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel'));

        return parent::_prepareColumns();
    }



    public function getRowUrl($row)
    {
        //return $this->getUrl("*/*/edit", array("id" => $row->getId()));
    }

    public function getGridUrl()
    {
        return $this->getUrl('*/*/grid', array('_current' => true));
    }

}

En utilisant le moteur de rendu, je suis incapable de désérialiser les données à afficher dans mon Grid.php bien que les données ne sont pas affichés correctement et doit être séparé en son propre colonnes:

class Custom_Module_Block_Adminhtml_Order_Grid_Renderer_Payment extends

Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract{

    public function render(Varien_Object $row)
    {
        $value = ($row->getData('additional_information'));

        print_r(unserialize($value));
    }
}

Les données renvoyées dans Grid.php

 Array ( [paypal_express_checkout_shipping_method] => [paypal_payer_id] =>
Était-ce utile?

La solution

Cette question vous pouvez résoudre en personnalisant le fichier renderer. Vous pouvez chercher le format de base de données par requête personnalisée ainsi.

Pour exemple. Prodid.php

<?php
class Mage_Adminhtml_Block_Sales_Order_Renderer_Prodid extendsMage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{

    public function render(Varien_Object $row){
        $url = $this->getUrl('*/*/edit', array(
            'store'=>$this->getRequest()->getParam('store'),
            'id'=>$row->getId())
        );
        $exploding = explode('sales_order/edit/id/',$url);
        //print_r($exploding);
        $id = explode('/',$exploding[1]);
        //print_r($id);
        $myId = $id[0];
        //echo $myId;
        $write = Mage::getSingleton('core/resource')->getConnection('core_write');

        // now $write is an instance of Zend_Db_Adapter_Abstract
        $readresult=$write->query("SELECT product_id FROM `sales_flat_order_item` WHERE `order_id` =$myId "); 
        while ($row = $readresult->fetch() ) {
            $productid = $row['product_id'];
             $myprodid .= $productid.',';

        }
        $myprodid2 = substr($myprodid,0,-1);
            return $myprodid2;
    }

}
?>

Cela vous donnera le résultat souhaité dans mon cas, il était id produit

Ensuite, l'appelant dans le fichier de la grille serait comme

$this->addColumn('ids', array(
        'header'    => Mage::helper('sales')->__('Product ID'),
        'width'     => '100px',
        'index'     => 'ids',
        'type'      => 'text',
        'filter'    => false,
        'sortable'  => false,
        'renderer'  => 'Mage_Adminhtml_Block_Sales_Order_Renderer_Prodid'
    ));

Le filtre = false false et triables supprimera l'a href des en-têtes et ne vous montrera que les données.

Si vous voulez les faire sortable, alors vous devrez passer l'identifiant d'index unique correspondant.

S'il vous plaît part si quelque chose ne sait pas ici.

Autres conseils

$order = Mage::getModel('sales/order');

$order->load(ORDER_ID);

$payment = $order->getPayment();

$info = $payment->getAdditionalInformation();

Vous devrez peut-être utiliser le code suivant si les informations ne contient pas ce que vous cherchez à ce stade (moins le vardump):

$payments = Mage::getModel('sales/order_payment_transaction')->getCollection()
            ->addPaymentIdFilter($payment->getId());

        foreach ($payments as $itme)
        {
            $addInfo = $item->getAdditionalInformation());
            var_dump($addInfo,true);
        }

J'ai réussi à résoudre le problème avec la solution suivante,

Dans mon Renderer / Payment.php

private $_type = 'paymentId';

public function render(Varien_Object $row)
{
    $value = unserialize($row->getData('additional_information'));

    return $value[$this->_type];
}

obtient la valeur « ID de paiement » de la colonne de additional_information qui est ensuite linéarisées dans la fonction.

Pour les autres valeurs que je avais besoin, je créé des fichiers dans le dossier Renderer

Brand.php

private $_type='CC_BRAND';

public function render(Varien_Object $row)
{
    $value = unserialize($row->getData('additional_information'));

    return $value[$this->_type];
}

Ensuite, dans le Grid.php

Ajoutez le générateur de la colonne

$this->addColumn('additional_information_brand', array(
    'header' => Mage::helper('sales')->__('Payment Brand'),
    'filter_condition_callback' => array($this, '_paymentFilter'),
    'type' => 'options',
    'options' => array("VISA", "MasterCard"),
    'renderer' => 'Company_Module_Block_Adminhtml_Order_Grid_Renderer_Brand'
));

Et pour obtenir le filtre

  protected function _paymentFilter($collection, $column)
    {
                      case "additional_information_brand":
                {

                    $this->getCollection()->getSelect()->where(
                        "sfop.additional_information like ?"
                        , '%CC_BRAND";s:'.strlen($value).':"%'.$value.'%');
                    break;
                }
    }

Vous voudrez peut-être utiliser un commutateur pour les filtres!

Peut-être essayer passer un $key comme paramètre pour getAdditionalInformation()?

Comme getAdditionalInformation('paypal_express_checkout_shipping_method') ou getAdditionalInformation($key)?

Hope u trouver la solution

Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange
scroll top