integration-helper/integration-version-magento-client

1.0.26 2025-01-08 15:13 UTC

README

Usage

Default:

Add Configuration in System Admin Config (Api Url, Api Key, Api Secret Key or Token)

use IntegrationHelper\IntegrationVersionMagentoClient\Import\AbstractImportClient;

class ImportProcess extends AbstractImportClient
{
    public function import()
    {
        foreach ($this->itemsData() as $itemsData) {
            //... prepare $itemsData to import
            //..save $itemsData
        }
    }

    public function getSourceCode(): string
    {
        return self::SOURCE_CODE;
    }

    public function callbackAfterClearOldData(): void
    {
        // TODO: Implement callbackAfterClearOldData() method.
    }

    public function callbackBeforeSaveLatestHash(): void
    {
    }

    public function callbackAfterReturnData(): void
    {
        // TODO: Implement callbackAfterReturnData() method.
    }

    public function callbackBeforeGetItem(): void
    {
        // TODO: Implement callbackBeforeGetItem() method.
    }

    public function callbackBeforeStart(): void
    {
    }
}

Custom:

Add Configuration in System Admin Config (Api Url, Api Key, Api Secret Key or Token)

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <virtualType name="Vendor\ApiAppIntegrationVersion\ApiRequest\EngineApiRequest"
                 type="IntegrationHelper\IntegrationVersionMagentoClient\ApiRequest\BaseApiRequest">
        <arguments>
            <argument name="configProvider" xsi:type="object">Vendor\ApiAppIntegrationVersion\Model\ConfigProvider</argument>
            <argument name="getCachedToken" xsi:type="object">IntegrationHelper\IntegrationVersionMagentoClient\ApiRequest\GetCachedToken</argument>
            <argument name="type" xsi:type="string">engine_api_request</argument>
            <argument name="name" xsi:type="string">Engine Api Request</argument>
        </arguments>
    </virtualType>

    <virtualType
        name="Vendor\ApiAppIntegrationVersion\Service\EngineIntegrationVersionManager"
        type="IntegrationHelper\IntegrationVersionMagentoClient\Service\IntegrationVersionManager"
    >
        <arguments>
            <argument name="apiRequest" xsi:type="object">Vendor\ApiAppIntegrationVersion\ApiRequest\EngineApiRequest</argument>
        </arguments>
    </virtualType>

    <type name="Vendor\ApiAppIntegrationVersion\Service\RunImports">
        <arguments>
            <argument name="integrationVersionManager" xsi:type="object">Vendor\ApiAppIntegrationVersion\Service\EngineIntegrationVersionManager</argument>
        </arguments>
    </type>
</config>

Get Deleted Identities

public function __construct(
        protected IntegrationVersionManager $integrationVersionManager
    ){}

 public function deleteOldData() {
    $tableName = $integrationVersion->getTableName();
        $connection = $this->resourceConnection->getConnection();
        $page = 1;
        while(true) {
            $query = $connection->select()->from($tableName, $integrationVersion->getIdentityColumn())
                ->limitPage($page++, 10000);
            $identities = $connection->fetchCol($query);
            if(!$identities) break;
            $deletedIdentities = $this->integrationVersionManager
                ->getDeletedIdentities(self::SOURCE_CODE, $identities);

            if($deletedIdentities) {
                $connection->deleteFromSelect(
                    $connection->select()->from($tableName)->where($integrationVersion->getIdentityColumn() . ' IN (?)', $deletedIdentities)
                );
            }
        }
       
    
 }