valantic-spryker/customer-storage

Allows to publish non privacy related customer data into storage.

1.0.8 2023-09-28 09:58 UTC

README

Minimum PHP Version

Description

  • Allows to publish non privacy related customer data into storage.

Install

  • composer require valantic-spryker/customer-storage
  • register publisher plugins
    // Zed\Publisher\PublisherDependencyProvider.php
    /**
     * @return array
     */
    private function getCustomerStoragePlugins(): array
    {
        return [
            CustomerStorageConfig::PUBLISH_CUSTOMER => [
                new CustomerWritePublisherPlugin(),
                new CustomerDeletePublisherPlugin(),
                new CustomerGroupToCustomerWritePublisherPlugin(),
                new CustomerGroupToCustomerDeletePublisherPlugin(),
                new CustomerAddressWritePublisherPlugin(),
            ],
        ];
    }
  • create customer storage queues
 // Client\RabbitMq\RabbitMqConfig.php
     /**
     * @return array
     */
    protected function getPublishQueueConfiguration(): array
    {
        return [
            [...]
            CustomerStorageConfig::PUBLISH_CUSTOMER,
            [...]
        ];
    }

    /**
     * @return array
     */
    protected function getSynchronizationQueueConfiguration(): array
    {
        return [
            [...]
            CustomerStorageConfig::SYNC_CUSTOMER_STORAGE,
            [...]
        ];
    }

    /**
     * @return \ArrayObject
     */
    protected function getQueueOptions(): ArrayObject
    {
        $queueOptionCollection = parent::getQueueOptions();

        $queueOptionCollection->append($this->createQueueOptionTransfer(CustomerStorageConfig::SYNC_CUSTOMER_STORAGE, CustomerStorageConfig::SYNC_CUSTOMER_STORAGE_ERROR));
    
        return $queueOptionCollection;
    }
  • add processor to queue:worker command
    // Zed\Queue\QueueDependencyProvider.php
        /**
     * @param \Spryker\Zed\Kernel\Container $container
     *
     * @return array<\Spryker\Zed\Queue\Dependency\Plugin\QueueMessageProcessorPluginInterface>
     */
    protected function getProcessorMessagePlugins(Container $container): array
    {
        [...]
            CustomerStorageConfig::PUBLISH_CUSTOMER => new EventQueueMessageProcessorPlugin(),
            CustomerStorageConfig::SYNC_CUSTOMER_STORAGE => new SynchronizationStorageQueueMessageProcessorPlugin(),
        [...]
    }
    
  • if you use default customer importer, ensure customer-storage publisher event is triggered
    // Zed\CustomerImport\Business\Model\CustomerImporterPlugin
    public function import(array $data): void
    {
        [...]
            QueueImporterPublisher::addEvent(
                CustomerStorageConfig::PUBLISH_CUSTOMER_WRITE,
                $idCustomer,
            );
        [...]
    }
            
  • configure the data you like to expose
    // Zed\CustomerStorage\Business\Mapper\CustomerStorageMapper
    protected function getCustomerStorageData(SpyCustomerEntityTransfer $customerEntityTransfer): array
    {
        $data = [];
        $data['idCustomer'] = $customerEntityTransfer->getIdCustomer();
        $data['customerGroup'] = ($customerEntityTransfer->getSpyCustomerGroupToCustomers()->count() > 0) ? ($customerEntityTransfer->getSpyCustomerGroupToCustomers()[0]->getCustomerGroup()?->getName()) : null;
        $data['sponsorReference'] = $customerEntityTransfer->getSponsorReference();
        $data['priceGroup'] = $customerEntityTransfer->getPriceGroup();
        $data['store'] = $customerEntityTransfer->getSpyStore()?->getName();
        $data['country'] = $customerEntityTransfer->getBillingAddress()?->getCountry()?->getName();
        $data['zipCode'] = $customerEntityTransfer->getBillingAddress()?->getZipCode();

        return $data;
    }
  • if you like to use console publisher:trigger-events customer -> register publisher plugin
    // Zed\Publisher\PublisherDependencyProvider
    [...]
    new CustomerPublisherTriggerPlugin(),
    [...]

HowTos Cli

PHP Container: docker run -it --rm --name my-running-script -v "$PWD":/data spryker/php:latest bash

Run Tests: codecept run --env standalone

Fixer: vendor/bin/phpcbf --standard=phpcs.xml --report=full src/ValanticSpryker/

Disable opcache: mv /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini /usr/local/etc/php/conf.d/docker-php-ext-opcache.iniold

XDEBUG:

  • ip addr | grep '192.'

  • $docker-php-ext-enable xdebug

  • configure phpstorm (add 127.0.0.1 phpstorm server with name valantic)

  • $PHP_IDE_CONFIG=serverName=valantic php -dxdebug.mode=debug -dxdebug.client_host=192.168.87.39 -dxdebug.start_with_request=yes ./vendor/bin/codecept run --env standalone

  • Run Tests with coverage: XDEBUG_MODE=coverage vendor/bin/codecept run --env standalone --coverage --coverage-xml --coverage-html

use nodejs

  • docker run -it --rm --name my-running-script -v "$PWD":/data node:18 bash