skip to Main Content

I have a custom import script that works fine.

I would like to remove one of the behaviors from the drop down menu.

As I dont want to allow for appends to the custom table, only replace or deletes.

Custom Import Behaviour

3

Answers


  1. Chosen as BEST ANSWER

    So, found the answer

    1. Create a new Folder:

    YourVendorNameYourModuleNameModelSourceImportBehavior

    1. Create a new file called Basic.php in this folder

    in the funtion _toArray() I commented out the Append Option

    public function toArray()
    {
        return [
            MagentoImportExportModelImport::BEHAVIOR_REPLACE => __('Replace'),
            MagentoImportExportModelImport::BEHAVIOR_DELETE => __('Delete')
        ];
    }
    
    1. In your import.xml change the path from the magento path to your new Basic.php file.

      <entity name="import_custom" label="Custom Import - Product Price Matrix" model="YourVendorNameYourModuleNameModelImportCustomImport" behaviorModel="YourVendorNameYourModuleNameModelSourceImportBehaviorBasic" />

    Regards Brendan


  2. Enter Below code custom behaviorModel class file of your custom module.

    for example :

    VendorNameYourModuleNameModelSourceImportBehaviorBasic.php

    /**
     * {@inheritdoc}
     */
    public function getCode()
    {
        return 'custom_module_entity';
    }
    

    Please note you can take any string except “custom”;

    Login or Signup to reply.
  3. Both toArray and getCode function needs to be modified in custom behavior file. Here is the complete solution.

    etc/import.xml

    <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_ImportExport:etc/import.xsd">
        <entity name="promotion_price" label="Promotion Price" model="UnioncoopCustomImportModelImportPromotionPrice"
                behaviorModel="VendorCustomImportModelSourceImportBehaviorBasic" />
    </config>
    

    Vendor/CustomImport/Model/Source/Import/Behavior/Basic.php

    <?php
    
    namespace VendorCustomImportModelSourceImportBehavior;
    
    use MagentoImportExportModelImport;
    
    class Basic extends MagentoImportExportModelSourceImportBehaviorBasic
    {
        public function toArray()
        {
            return [
                Import::BEHAVIOR_APPEND => __('Add/Update'),
                Import::BEHAVIOR_DELETE => __('Delete')
            ];
        }
    
        public function getCode()
        {
            return 'promotion_price'; // add your entity name
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search