PHP code example of valantic-spryker / customer-storage

1. Go to this page and download the library: Download valantic-spryker/customer-storage library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

valantic-spryker / customer-storage example snippets


    // Zed\Publisher\PublisherDependencyProvider.php
    /**
     * @return array
     */
    private function getCustomerStoragePlugins(): array
    {
        return [
            CustomerStorageConfig::PUBLISH_CUSTOMER => [
                new CustomerWritePublisherPlugin(),
                new CustomerDeletePublisherPlugin(),
                new CustomerGroupToCustomerWritePublisherPlugin(),
                new CustomerGroupToCustomerDeletePublisherPlugin(),
                new CustomerAddressWritePublisherPlugin(),
            ],
        ];
    }

 // 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;
    }

    // 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(),
        [...]
    }
    


    // Zed\CustomerImport\Business\Model\CustomerImporterPlugin
    public function import(array $data): void
    {
        [...]
            QueueImporterPublisher::addEvent(
                CustomerStorageConfig::PUBLISH_CUSTOMER_WRITE,
                $idCustomer,
            );
        [...]
    }
            

    // 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;
    }

    // Zed\Publisher\PublisherDependencyProvider
    [...]
    new CustomerPublisherTriggerPlugin(),
    [...]