Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.18 KB | None | 0 0
  1. $table = $installer->getConnection()
  2. ->newTable($installer->getTable('table_epaisseur'))
  3. ->addColumn(
  4. 'entity_id',
  5. MagentoFrameworkDBDdlTable::TYPE_INTEGER,
  6. null,
  7. [
  8. 'identity' => true,
  9. 'nullable' => false,
  10. 'primary' => true,
  11. 'unsigned' => true,
  12. ],
  13. 'ID'
  14. )
  15.  
  16. ->addColumn(
  17. 'code_epaisseur',
  18. MagentoFrameworkDBDdlTable::TYPE_TEXT,
  19. '18K',
  20. [],
  21. 'Code Epaisseur'
  22. )
  23.  
  24. ->addColumn(
  25. 'designation_ep',
  26. MagentoFrameworkDBDdlTable::TYPE_TEXT,
  27. '18K',
  28. [],
  29. 'Designation Epaisseur'
  30. )
  31. ->addColumn(
  32. 'famille_ep',
  33. MagentoFrameworkDBDdlTable::TYPE_TEXT,
  34. '18K',
  35. [],
  36. 'Famille Epaisseur'
  37. )
  38.  
  39. ->setComment('Epaisseur Table');
  40.  
  41. $installer->getConnection()->createTable($table);
  42.  
  43.  
  44. }
  45. $installer->endSetup();
  46.  
  47. <?php
  48.  
  49. const EVENTNAME = 'code_epaisseur';
  50. const IMGURL = 'designation_ep';
  51. const BANNERIMGURL = 'famille_ep';
  52.  
  53.  
  54. const TABLE_Entity = 'table_epaisseur';
  55.  
  56. /**
  57. * Validation failure message template definitions
  58. *
  59. * @var array
  60. */
  61. protected $_messageTemplates = [
  62. ValidatorInterface::ERROR_TITLE_IS_EMPTY => 'TITLE is empty',
  63. ];
  64.  
  65. protected $_permanentAttributes = [self::EVENTNAME];
  66. /**
  67. * If we should check column names
  68. *
  69. * @var bool
  70. */
  71. protected $needColumnCheck = true;
  72. protected $groupFactory;
  73. /**
  74. * Valid column names
  75. *
  76. * @array
  77. */
  78. protected $validColumnNames = [
  79.  
  80. self::EVENTNAME,
  81. self::IMGURL,
  82. self::BANNERIMGURL,
  83.  
  84. ];
  85.  
  86. /**
  87. * Need to log in import history
  88. *
  89. * @var bool
  90. */
  91. protected $logInHistory = true;
  92.  
  93. protected $_validators = [];
  94.  
  95.  
  96. /**
  97. * @var MagentoFrameworkStdlibDateTimeDateTime
  98. */
  99. protected $_connection;
  100. protected $_resource;
  101.  
  102. /**
  103. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  104. */
  105. public function __construct(
  106. MagentoFrameworkJsonHelperData $jsonHelper,
  107. MagentoImportExportHelperData $importExportData,
  108. MagentoImportExportModelResourceModelImportData $importData,
  109. MagentoFrameworkAppResourceConnection $resource,
  110. MagentoImportExportModelResourceModelHelper $resourceHelper,
  111. MagentoFrameworkStdlibStringUtils $string,
  112. ProcessingErrorAggregatorInterface $errorAggregator,
  113. MagentoCustomerModelGroupFactory $groupFactory
  114. ) {
  115. $this->jsonHelper = $jsonHelper;
  116. $this->_importExportData = $importExportData;
  117. $this->_resourceHelper = $resourceHelper;
  118. $this->_dataSourceModel = $importData;
  119. $this->_resource = $resource;
  120. $this->_connection = $resource->getConnection(MagentoFrameworkAppResourceConnection::DEFAULT_CONNECTION);
  121. $this->errorAggregator = $errorAggregator;
  122. $this->groupFactory = $groupFactory;
  123. }
  124. public function getValidColumnNames()
  125. {
  126. return $this->validColumnNames;
  127. }
  128.  
  129. /**
  130. * Entity type code getter.
  131. *
  132. * @return string
  133. */
  134. public function getEntityTypeCode()
  135. {
  136. return 'table_epaisseur';
  137. }
  138.  
  139. /**
  140. * Row validation.
  141. *
  142. * @param array $rowData
  143. * @param int $rowNum
  144. * @return bool
  145. */
  146. public function validateRow(array $rowData, $rowNum)
  147. {
  148.  
  149. $title = false;
  150.  
  151. if (isset($this->_validatedRows[$rowNum])) {
  152. return !$this->getErrorAggregator()->isRowInvalid($rowNum);
  153. }
  154.  
  155. $this->_validatedRows[$rowNum] = true;
  156. // BEHAVIOR_DELETE use specific validation logic
  157. // if (MagentoImportExportModelImport::BEHAVIOR_DELETE == $this->getBehavior()) {
  158. if (!isset($rowData[self::EVENTNAME]) || empty($rowData[self::EVENTNAME])) {
  159. $this->addRowError(ValidatorInterface::ERROR_TITLE_IS_EMPTY, $rowNum);
  160. return false;
  161. }
  162.  
  163. return !$this->getErrorAggregator()->isRowInvalid($rowNum);
  164. }
  165.  
  166.  
  167. /**
  168. * Create Advanced price data from raw data.
  169. *
  170. * @throws Exception
  171. * @return bool Result of operation.
  172. */
  173. protected function _importData()
  174. {
  175. if (MagentoImportExportModelImport::BEHAVIOR_DELETE == $this->getBehavior()) {
  176. $this->deleteEntity();
  177. } elseif (MagentoImportExportModelImport::BEHAVIOR_REPLACE == $this->getBehavior()) {
  178. $this->replaceEntity();
  179. } elseif (MagentoImportExportModelImport::BEHAVIOR_APPEND == $this->getBehavior()) {
  180. $this->saveEntity();
  181. }
  182.  
  183. return true;
  184. }
  185. /**
  186. * Save newsletter subscriber
  187. *
  188. * @return $this
  189. */
  190. public function saveEntity()
  191. {
  192. $this->saveAndReplaceEntity();
  193. return $this;
  194. }
  195. /**
  196. * Replace newsletter subscriber
  197. *
  198. * @return $this
  199. */
  200. public function replaceEntity()
  201. {
  202. $this->saveAndReplaceEntity();
  203. return $this;
  204. }
  205. /**
  206. * Deletes newsletter subscriber data from raw data.
  207. *
  208. * @return $this
  209. */
  210. public function deleteEntity()
  211. {
  212. $listTitle = [];
  213. while ($bunch = $this->_dataSourceModel->getNextBunch()) {
  214. foreach ($bunch as $rowNum => $rowData) {
  215. $this->validateRow($rowData, $rowNum);
  216. if (!$this->getErrorAggregator()->isRowInvalid($rowNum)) {
  217. $rowTtile = $rowData[self::EVENTNAME];
  218. $listTitle[] = $rowTtile;
  219. }
  220. if ($this->getErrorAggregator()->hasToBeTerminated()) {
  221. $this->getErrorAggregator()->addRowToSkip($rowNum);
  222. }
  223. }
  224. }
  225. if ($listTitle) {
  226. $this->deleteEntityFinish(array_unique($listTitle),self::TABLE_Entity);
  227. }
  228. return $this;
  229. }
  230. /**
  231. * Save and replace newsletter subscriber
  232. *
  233. * @return $this
  234. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  235. * @SuppressWarnings(PHPMD.NPathComplexity)
  236. */
  237. protected function saveAndReplaceEntity()
  238. {
  239. $behavior = $this->getBehavior();
  240. $listTitle = [];
  241. while ($bunch = $this->_dataSourceModel->getNextBunch()) {
  242. $entityList = [];
  243. foreach ($bunch as $rowNum => $rowData) {
  244. if (!$this->validateRow($rowData, $rowNum)) {
  245. $this->addRowError(ValidatorInterface::ERROR_TITLE_IS_EMPTY, $rowNum);
  246. continue;
  247. }
  248. if ($this->getErrorAggregator()->hasToBeTerminated()) {
  249. $this->getErrorAggregator()->addRowToSkip($rowNum);
  250. continue;
  251. }
  252.  
  253. $rowTtile= $rowData[self::EVENTNAME];
  254. $listTitle[] = $rowTtile;
  255. $entityList[$rowTtile][] = [
  256. self::EVENTNAME => $rowData[self::EVENTNAME],
  257. self::IMGURL => $rowData[self::IMGURL],
  258. self::BANNERIMGURL => $rowData[self::BANNERIMGURL],
  259.  
  260. ];
  261. }
  262. if (MagentoImportExportModelImport::BEHAVIOR_REPLACE == $behavior) {
  263. if ($listTitle) {
  264. if ($this->deleteEntityFinish(array_unique( $listTitle), self::TABLE_Entity)) {
  265. $this->saveEntityFinish($entityList, self::TABLE_Entity);
  266. }
  267. }
  268. } elseif (MagentoImportExportModelImport::BEHAVIOR_APPEND == $behavior) {
  269. $this->saveEntityFinish($entityList, self::TABLE_Entity);
  270. }
  271. }
  272. return $this;
  273. }
  274. /**
  275. * Save product prices.
  276. *
  277. * @param array $priceData
  278. * @param string $table
  279. * @return $this
  280. */
  281. protected function saveEntityFinish(array $entityData, $table)
  282. {
  283. if ($entityData) {
  284. $tableName = $this->_connection->getTableName($table);
  285. $entityIn = [];
  286. foreach ($entityData as $id => $entityRows) {
  287. foreach ($entityRows as $row) {
  288. $entityIn[] = $row;
  289. }
  290. }
  291. if ($entityIn) {
  292. $this->_connection->insertOnDuplicate($tableName, $entityIn,[
  293. self::EVENTNAME,
  294. self::IMGURL,
  295. self::BANNERIMGURL
  296.  
  297. ]);
  298. }
  299. }
  300. return $this;
  301. }
  302. protected function deleteEntityFinish(array $listTitle, $table)
  303. {
  304. if ($table && $listTitle) {
  305. try {
  306. $this->countItemsDeleted += $this->_connection->delete(
  307. $this->_connection->getTableName($table),
  308. $this->_connection->quoteInto('customer_group_code IN (?)', $listTitle)
  309. );
  310. return true;
  311. } catch (Exception $e) {
  312. return false;
  313. }
  314.  
  315. } else {
  316. return false;
  317. }
  318. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement