SHARE
TWEET

Untitled

a guest Aug 19th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  namespace MyModuleModelSave;
  3.  use MyModuleModelResourceModelSaveCollectionFactory;
  4.  class DataProvider extends MagentoUiDataProviderAbstractDataProvider
  5. {
  6. /**
  7.  * @param string $name
  8.  * @param string $primaryFieldName
  9.  * @param string $requestFieldName
  10.  * @param CollectionFactory $contactCollectionFactory
  11.  * @param array $meta
  12.  * @param array $data
  13.  */
  14.  
  15. public function __construct(
  16.     $name,
  17.     $primaryFieldName,
  18.     $requestFieldName,
  19.     CollectionFactory $contactCollectionFactory,
  20.     array $meta = [],
  21.     array $data = []
  22. ) {
  23.     $this->collection = $contactCollectionFactory->create();
  24.  
  25.     parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
  26. }
  27.  
  28. public function getData()
  29. {
  30.     if (isset($this->loadedData)) {
  31.         return $this->loadedData;
  32.     }
  33.  
  34.     $items = $this->collection->getItems();
  35.     $this->loadedData = array();
  36.  
  37.     /** @var Customer $customer */
  38.     foreach ($items as $contact) {
  39.         // notre fieldset s'apelle "contact" d'ou ce tableau pour que magento puisse retrouver ses datas :
  40.         $this->loadedData[$contact->getId()]['contact'] = $contact->getData();
  41.     }
  42.  
  43.  
  44.     return $this->loadedData;
  45.  
  46. }
  47. }
  48.      
  49. <?php
  50.  
  51.  namespace MyModuleModelResourceModelSave;
  52.  
  53.  use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
  54.  
  55.  class Collection extends AbstractCollection
  56. {
  57. public function _construct()
  58. {
  59.     $this->_init('MyModuleModelSave', 'MyModuleModelResourceModelSave');
  60.  
  61. }
  62. }
  63.      
  64. public function _initSelect()
  65.      {
  66.         parent::_initSelect();
  67.  
  68.         $this->getSelect()->joinLeft(
  69.         ['secondTable' => $this->getTable('SECOND_TABLE_NAME')],
  70.         'main_table.COULMN_NAME_TO_JOIN_TABLE1 = secondTable.COULMN_NAME_TO_JOIN_TABLE2',
  71.         ['COLUMN_U_WANT_TO_ADD'=>'COLUMN_NAME_OF_NEW_COLUMN']
  72.         );
  73.         $this->addFilterToMap('COLUMN_U_WANT_TO_ADD', 'secondTable.COLUMN_NAME_OF_NEW_COLUMN');
  74.      }
  75.      
  76. use MagentoFrameworkModelResourceModelDbCollectionAbstractCollection;
  77.  
  78. class Collection extends AbstractCollection
  79. {
  80.     protected $_idFieldName = 'entity_id';
  81.     /**
  82.      * Collection constructor
  83.      *
  84.      *
  85.      * @param  EntityFactoryInterface $entityFactory
  86.      * @param  LoggerInterface $logger
  87.      * @param  FetchStrategyInterface $fetchStrategy
  88.      * @param  ManagerInterface $eventManager
  89.      * @param  StoreManagerInterface $storeManager
  90.      * @param  AdapterInterface $connection
  91.      * @param  AbstractDb $resource
  92.      */
  93.     public function __construct(
  94.         MagentoFrameworkDataCollectionEntityFactoryInterface $entityFactory,
  95.         PsrLogLoggerInterface $logger,
  96.         MagentoFrameworkDataCollectionDbFetchStrategyInterface $fetchStrategy,
  97.         MagentoFrameworkEventManagerInterface $eventManager,
  98.         MagentoStoreModelStoreManagerInterface $storeManager,
  99.         MagentoFrameworkDBAdapterAdapterInterface $connection = null,
  100.         MagentoFrameworkModelResourceModelDbAbstractDb $resource = null
  101.     ) {
  102.         $this->_init('MyModuleModelSave', 'MyModuleModelResourceModelSave');
  103.         $this->storeManager = $storeManager;
  104.         parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
  105.     }
  106.     /**
  107.      *
  108.      *  Filtering Data By Query on the Basis of Filtering Criteria
  109.      *
  110.      *
  111.      */
  112.  
  113.     protected function _initSelect()
  114.     {
  115.         parent::_initSelect();
  116.         $this->getSelect()->where('main_table.reserved_order_id NOT IN (SELECT sales_order.increment_id  FROM sales_order) ');
  117.     }
  118. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top