Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $table = $installer->getConnection()
- ->newTable($installer->getTable('table_epaisseur'))
- ->addColumn(
- 'entity_id',
- MagentoFrameworkDBDdlTable::TYPE_INTEGER,
- null,
- [
- 'identity' => true,
- 'nullable' => false,
- 'primary' => true,
- 'unsigned' => true,
- ],
- 'ID'
- )
- ->addColumn(
- 'code_epaisseur',
- MagentoFrameworkDBDdlTable::TYPE_TEXT,
- '18K',
- [],
- 'Code Epaisseur'
- )
- ->addColumn(
- 'designation_ep',
- MagentoFrameworkDBDdlTable::TYPE_TEXT,
- '18K',
- [],
- 'Designation Epaisseur'
- )
- ->addColumn(
- 'famille_ep',
- MagentoFrameworkDBDdlTable::TYPE_TEXT,
- '18K',
- [],
- 'Famille Epaisseur'
- )
- ->setComment('Epaisseur Table');
- $installer->getConnection()->createTable($table);
- }
- $installer->endSetup();
- <?php
- const EVENTNAME = 'code_epaisseur';
- const IMGURL = 'designation_ep';
- const BANNERIMGURL = 'famille_ep';
- const TABLE_Entity = 'table_epaisseur';
- /**
- * Validation failure message template definitions
- *
- * @var array
- */
- protected $_messageTemplates = [
- ValidatorInterface::ERROR_TITLE_IS_EMPTY => 'TITLE is empty',
- ];
- protected $_permanentAttributes = [self::EVENTNAME];
- /**
- * If we should check column names
- *
- * @var bool
- */
- protected $needColumnCheck = true;
- protected $groupFactory;
- /**
- * Valid column names
- *
- * @array
- */
- protected $validColumnNames = [
- self::EVENTNAME,
- self::IMGURL,
- self::BANNERIMGURL,
- ];
- /**
- * Need to log in import history
- *
- * @var bool
- */
- protected $logInHistory = true;
- protected $_validators = [];
- /**
- * @var MagentoFrameworkStdlibDateTimeDateTime
- */
- protected $_connection;
- protected $_resource;
- /**
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- public function __construct(
- MagentoFrameworkJsonHelperData $jsonHelper,
- MagentoImportExportHelperData $importExportData,
- MagentoImportExportModelResourceModelImportData $importData,
- MagentoFrameworkAppResourceConnection $resource,
- MagentoImportExportModelResourceModelHelper $resourceHelper,
- MagentoFrameworkStdlibStringUtils $string,
- ProcessingErrorAggregatorInterface $errorAggregator,
- MagentoCustomerModelGroupFactory $groupFactory
- ) {
- $this->jsonHelper = $jsonHelper;
- $this->_importExportData = $importExportData;
- $this->_resourceHelper = $resourceHelper;
- $this->_dataSourceModel = $importData;
- $this->_resource = $resource;
- $this->_connection = $resource->getConnection(MagentoFrameworkAppResourceConnection::DEFAULT_CONNECTION);
- $this->errorAggregator = $errorAggregator;
- $this->groupFactory = $groupFactory;
- }
- public function getValidColumnNames()
- {
- return $this->validColumnNames;
- }
- /**
- * Entity type code getter.
- *
- * @return string
- */
- public function getEntityTypeCode()
- {
- return 'table_epaisseur';
- }
- /**
- * Row validation.
- *
- * @param array $rowData
- * @param int $rowNum
- * @return bool
- */
- public function validateRow(array $rowData, $rowNum)
- {
- $title = false;
- if (isset($this->_validatedRows[$rowNum])) {
- return !$this->getErrorAggregator()->isRowInvalid($rowNum);
- }
- $this->_validatedRows[$rowNum] = true;
- // BEHAVIOR_DELETE use specific validation logic
- // if (MagentoImportExportModelImport::BEHAVIOR_DELETE == $this->getBehavior()) {
- if (!isset($rowData[self::EVENTNAME]) || empty($rowData[self::EVENTNAME])) {
- $this->addRowError(ValidatorInterface::ERROR_TITLE_IS_EMPTY, $rowNum);
- return false;
- }
- return !$this->getErrorAggregator()->isRowInvalid($rowNum);
- }
- /**
- * Create Advanced price data from raw data.
- *
- * @throws Exception
- * @return bool Result of operation.
- */
- protected function _importData()
- {
- if (MagentoImportExportModelImport::BEHAVIOR_DELETE == $this->getBehavior()) {
- $this->deleteEntity();
- } elseif (MagentoImportExportModelImport::BEHAVIOR_REPLACE == $this->getBehavior()) {
- $this->replaceEntity();
- } elseif (MagentoImportExportModelImport::BEHAVIOR_APPEND == $this->getBehavior()) {
- $this->saveEntity();
- }
- return true;
- }
- /**
- * Save newsletter subscriber
- *
- * @return $this
- */
- public function saveEntity()
- {
- $this->saveAndReplaceEntity();
- return $this;
- }
- /**
- * Replace newsletter subscriber
- *
- * @return $this
- */
- public function replaceEntity()
- {
- $this->saveAndReplaceEntity();
- return $this;
- }
- /**
- * Deletes newsletter subscriber data from raw data.
- *
- * @return $this
- */
- public function deleteEntity()
- {
- $listTitle = [];
- while ($bunch = $this->_dataSourceModel->getNextBunch()) {
- foreach ($bunch as $rowNum => $rowData) {
- $this->validateRow($rowData, $rowNum);
- if (!$this->getErrorAggregator()->isRowInvalid($rowNum)) {
- $rowTtile = $rowData[self::EVENTNAME];
- $listTitle[] = $rowTtile;
- }
- if ($this->getErrorAggregator()->hasToBeTerminated()) {
- $this->getErrorAggregator()->addRowToSkip($rowNum);
- }
- }
- }
- if ($listTitle) {
- $this->deleteEntityFinish(array_unique($listTitle),self::TABLE_Entity);
- }
- return $this;
- }
- /**
- * Save and replace newsletter subscriber
- *
- * @return $this
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- */
- protected function saveAndReplaceEntity()
- {
- $behavior = $this->getBehavior();
- $listTitle = [];
- while ($bunch = $this->_dataSourceModel->getNextBunch()) {
- $entityList = [];
- foreach ($bunch as $rowNum => $rowData) {
- if (!$this->validateRow($rowData, $rowNum)) {
- $this->addRowError(ValidatorInterface::ERROR_TITLE_IS_EMPTY, $rowNum);
- continue;
- }
- if ($this->getErrorAggregator()->hasToBeTerminated()) {
- $this->getErrorAggregator()->addRowToSkip($rowNum);
- continue;
- }
- $rowTtile= $rowData[self::EVENTNAME];
- $listTitle[] = $rowTtile;
- $entityList[$rowTtile][] = [
- self::EVENTNAME => $rowData[self::EVENTNAME],
- self::IMGURL => $rowData[self::IMGURL],
- self::BANNERIMGURL => $rowData[self::BANNERIMGURL],
- ];
- }
- if (MagentoImportExportModelImport::BEHAVIOR_REPLACE == $behavior) {
- if ($listTitle) {
- if ($this->deleteEntityFinish(array_unique( $listTitle), self::TABLE_Entity)) {
- $this->saveEntityFinish($entityList, self::TABLE_Entity);
- }
- }
- } elseif (MagentoImportExportModelImport::BEHAVIOR_APPEND == $behavior) {
- $this->saveEntityFinish($entityList, self::TABLE_Entity);
- }
- }
- return $this;
- }
- /**
- * Save product prices.
- *
- * @param array $priceData
- * @param string $table
- * @return $this
- */
- protected function saveEntityFinish(array $entityData, $table)
- {
- if ($entityData) {
- $tableName = $this->_connection->getTableName($table);
- $entityIn = [];
- foreach ($entityData as $id => $entityRows) {
- foreach ($entityRows as $row) {
- $entityIn[] = $row;
- }
- }
- if ($entityIn) {
- $this->_connection->insertOnDuplicate($tableName, $entityIn,[
- self::EVENTNAME,
- self::IMGURL,
- self::BANNERIMGURL
- ]);
- }
- }
- return $this;
- }
- protected function deleteEntityFinish(array $listTitle, $table)
- {
- if ($table && $listTitle) {
- try {
- $this->countItemsDeleted += $this->_connection->delete(
- $this->_connection->getTableName($table),
- $this->_connection->quoteInto('customer_group_code IN (?)', $listTitle)
- );
- return true;
- } catch (Exception $e) {
- return false;
- }
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement