├── .github └── workflows │ └── lint.yaml ├── .gitignore ├── .php-cs-fixer.php ├── Api └── ClientInterface.php ├── Assets └── img │ ├── prestashop.png │ └── woocommerce.png ├── Command └── TransactionImportCommand.php ├── Config └── config.php ├── Controller ├── AjaxController.php └── TransactionController.php ├── Email ├── Helper │ └── ParamsHelper.php ├── Parser.php ├── Tag │ ├── TransactionProductTag.php │ └── TransactionTag.php ├── TransactionParser.php └── TransactionProductsParser.php ├── Entity ├── Product.php ├── ProductRepository.php ├── Transaction.php ├── TransactionProduct.php └── TransactionRepository.php ├── EventListener ├── EmailSubscriber.php ├── LeadListSubscriber.php ├── LeadUiSubscriber.php ├── ProductObjectSubscriber.php └── SyncSubscriber.php ├── Integration ├── EcommerceAbstractIntegration.php ├── EcommerceIntegrationInterface.php ├── PrestashopIntegration.php └── WooCommerceIntegration.php ├── LICENSE.md ├── Makefile ├── MauticEcommerceBundle.php ├── Migrations └── Version_0_0_1.php ├── Model ├── Customer.php ├── Order.php ├── OrderProduct.php └── Product.php ├── Prestashop ├── Api │ └── Client.php ├── Form │ └── Type │ │ └── ConfigFormType.php └── Normalizer │ ├── CustomerNormalizer.php │ ├── OrderNormalizer.php │ ├── OrderProductNormalizer.php │ └── ProductNormalizer.php ├── README.md ├── Segment └── Query │ └── Filter │ └── PurchaseProductFilterQueryBuilder.php ├── Sync ├── Config.php ├── DataExchange │ ├── Internal │ │ ├── Product.php │ │ └── ProductObjectHelper.php │ ├── ReportBuilder.php │ ├── SyncDataExchange.php │ └── ValueNormalizer.php └── Mapping │ ├── Field │ ├── Field.php │ ├── FieldRepository.php │ └── MappedFieldInfo.php │ └── Manual │ └── MappingManualFactory.php ├── Templating └── Helper │ └── MoneyHelper.php ├── Tests └── Email │ ├── Helper │ └── ParamsHelperTest.php │ ├── ParserTest.php │ ├── Tag │ ├── TransactionProductTagTest.php │ └── TransactionTagTest.php │ ├── TransactionParserTest.php │ └── TransactionProductsParserTest.php ├── Translations └── en_US │ ├── config.json │ └── messages.ini ├── Views ├── Contact │ ├── tab.html.php │ └── tabContent.html.php └── Transaction │ ├── index.html.php │ └── list.html.php ├── WooCommerce ├── Api │ └── Client.php ├── Form │ └── Type │ │ └── ConfigFormType.php └── Normalizer │ ├── CustomerNormalizer.php │ ├── OrderNormalizer.php │ ├── OrderProductNormalizer.php │ └── ProductNormalizer.php ├── composer.json ├── phpstan-baseline.neon └── phpstan.neon.dist /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | types: [ opened, synchronize, reopened, ready_for_review ] 9 | 10 | concurrency: 11 | group: ${{ github.workflow }}-${{ github.ref }} 12 | cancel-in-progress: true 13 | 14 | jobs: 15 | lint: 16 | name: 'Lint' 17 | runs-on: ubuntu-latest 18 | timeout-minutes: 5 19 | # Do not run on Draft PRs 20 | if: "!github.event.pull_request || github.event.pull_request.draft == false" 21 | 22 | steps: 23 | 24 | - name: 'Checkout' 25 | uses: actions/checkout@v3 26 | 27 | - name: 'Setup PHP' 28 | uses: shivammathur/setup-php@v2 29 | with: 30 | coverage: "none" 31 | extensions: "json" 32 | ini-values: "memory_limit=-1" 33 | php-version: "7.4" 34 | tools: "symfony" 35 | 36 | - name: 'Determine composer cache directory' 37 | id: composer-cache 38 | run: echo "::set-output name=directory::$(composer config cache-dir)" 39 | 40 | - name: "Cache dependencies installed with composer" 41 | uses: actions/cache@v3 42 | with: 43 | path: ${{ steps.composer-cache.outputs.directory }} 44 | key: "composer-${{ hashFiles('composer.json') }}" 45 | restore-keys: "composer-" 46 | 47 | - name: 'Install dependencies & setup project' 48 | id: install 49 | run: make install@integration 50 | 51 | - name: 'Lint PhpStan' 52 | if: always() && steps.install.outcome == 'success' 53 | run: make lint.phpstan@integration 54 | 55 | - name: 'Lint PHP CS Fixer' 56 | if: always() && steps.install.outcome == 'success' 57 | run: make lint.php-cs-fixer@integration 58 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | .php-cs-fixer.cache 3 | composer.lock 4 | .php-version 5 | -------------------------------------------------------------------------------- /.php-cs-fixer.php: -------------------------------------------------------------------------------- 1 | in(__DIR__) 5 | ; 6 | 7 | return (new PhpCsFixer\Config()) 8 | ->setRiskyAllowed(true) 9 | ->setUsingCache(true) 10 | ->setFinder($finder) 11 | ->setRules([ 12 | '@Symfony' => true, 13 | 'array_syntax' => ['syntax' => 'short'], 14 | 'concat_space' => ['spacing' => 'one'], 15 | 'declare_strict_types' => true, 16 | 'native_function_invocation' => ['include' => ['@compiler_optimized']], 17 | 'ordered_imports' => true, 18 | 'php_unit_namespaced' => true, 19 | 'php_unit_method_casing' => false, 20 | 'phpdoc_annotation_without_dot' => false, 21 | 'phpdoc_summary' => false, 22 | 'phpdoc_order' => true, 23 | 'phpdoc_trim_consecutive_blank_line_separation' => true, 24 | 'psr_autoloading' => true, 25 | 'single_line_throw' => false, 26 | 'simplified_null_return' => false, 27 | 'yoda_style' => [], 28 | ]) 29 | ; 30 | -------------------------------------------------------------------------------- /Api/ClientInterface.php: -------------------------------------------------------------------------------- 1 | integrationsHelper = $integrationsHelper; 43 | $this->objectMappingRepository = $objectMappingRepository; 44 | $this->transactionRepository = $transactionRepository; 45 | $this->registry = $registry; 46 | $this->leadRepository = $leadRepository; 47 | $this->productRepository = $productRepository; 48 | } 49 | 50 | protected function configure(): void 51 | { 52 | $this 53 | ->addArgument('integrationName', InputArgument::REQUIRED) 54 | ; 55 | } 56 | 57 | protected function execute(InputInterface $input, OutputInterface $output): int 58 | { 59 | $integrationName = $input->getArgument('integrationName'); 60 | 61 | $integration = $this->integrationsHelper->getIntegration($integrationName); 62 | 63 | if (!$integration instanceof EcommerceAbstractIntegration) { 64 | throw new \Exception( 65 | sprintf('The integration %s must extends %s', $integrationName, EcommerceAbstractIntegration::class) 66 | ); 67 | } 68 | 69 | $entityManager = $this->registry->getManager(); 70 | $client = $integration->getClient(); 71 | 72 | $page = 1; 73 | 74 | do { 75 | $orders = $client->getOrders($page++, 10); 76 | 77 | foreach ($orders as $order) { 78 | $this->processOrder($integrationName, $order); 79 | } 80 | 81 | $entityManager->flush(); 82 | $entityManager->clear(); 83 | } while (\count($orders) > 0); 84 | 85 | return 1; 86 | } 87 | 88 | private function processOrder(string $integrationName, Order $order): void 89 | { 90 | $lead = $this->objectMappingRepository->getInternalObject( 91 | $integrationName, 92 | MappingManualFactory::CUSTOMER_OBJECT, 93 | $order->customerId, 94 | 'lead' 95 | ); 96 | 97 | if ($lead === null) { 98 | // no lead found 99 | return; 100 | } 101 | 102 | $lead = $this->leadRepository->getEntity($lead['internal_object_id']); 103 | 104 | $transaction = Transaction::fromOrder($lead, $order); 105 | 106 | foreach ($order->products as $orderProduct) { 107 | $internalProduct = $this->objectMappingRepository->getInternalObject( 108 | $integrationName, 109 | MappingManualFactory::PRODUCT_OBJECT, 110 | $orderProduct->productId, 111 | 'product' 112 | ); 113 | 114 | if ($internalProduct === null) { 115 | continue; 116 | } 117 | 118 | $productEntity = $this->productRepository->find($internalProduct['internal_object_id']); 119 | if ($productEntity === null) { 120 | continue; 121 | } 122 | 123 | $transaction->addProduct($productEntity, $orderProduct->quantity); 124 | } 125 | 126 | $this->transactionRepository->createOrUpdate($transaction); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /Config/config.php: -------------------------------------------------------------------------------- 1 | 'Ecommerce', 10 | 'description' => 'Retrieve data from various ecommerce solutions', 11 | 'version' => '0.0.2', 12 | 'author' => 'elao', 13 | 'routes' => [ 14 | 'main' => [ 15 | 'mautic_ecommerce_transaction_index' => [ 16 | 'path' => '/ecommerce/transactions/{page}', 17 | 'controller' => 'MauticEcommerceBundle:Transaction:index', 18 | ], 19 | ], 20 | ], 21 | 'menu' => [ 22 | 'main' => [ 23 | 'priority' => 75, 24 | 'items' => [ 25 | 'mautic_ecommerce.menu.transactions' => [ 26 | 'id' => 'mautic_ecommerce_transaction_index', 27 | 'iconClass' => 'fa-euro', 28 | 'route' => 'mautic_ecommerce_transaction_index', 29 | ], 30 | ], 31 | ], 32 | ], 33 | 'services' => [ 34 | 'commands' => [ 35 | 'mautic_ecommerce.command.transaction_import' => [ 36 | 'class' => Bundle\Command\TransactionImportCommand::class, 37 | 'arguments' => [ 38 | 'mautic.integrations.helper', 39 | 'mautic.integrations.repository.object_mapping', 40 | 'mautic_ecommerce.repository.transaction', 41 | 'mautic.lead.repository.lead', 42 | 'mautic_ecommerce.repository.product', 43 | 'doctrine', 44 | ], 45 | 'tag' => 'console.command', 46 | ], 47 | ], 48 | 'sync' => [ 49 | 'mautic_ecommerce.sync.repository.fields' => [ 50 | 'class' => Bundle\Sync\Mapping\Field\FieldRepository::class, 51 | 'arguments' => [ 52 | 'mautic.helper.cache_storage', 53 | ], 54 | ], 55 | 'mautic_ecommerce.sync.mapping_manual.factory' => [ 56 | 'class' => Bundle\Sync\Mapping\Manual\MappingManualFactory::class, 57 | 'arguments' => [ 58 | 'mautic_ecommerce.sync.repository.fields', 59 | 'mautic.integrations.helper', 60 | ], 61 | ], 62 | 'mautic_ecommerce.sync.data_exchange' => [ 63 | 'class' => Bundle\Sync\DataExchange\SyncDataExchange::class, 64 | 'arguments' => [ 65 | 'mautic_ecommerce.sync.data_exchange.report_builder', 66 | ], 67 | ], 68 | 'mautic_ecommerce.sync.data_exchange.report_builder' => [ 69 | 'class' => Bundle\Sync\DataExchange\ReportBuilder::class, 70 | 'arguments' => [ 71 | 'mautic_ecommerce.sync.repository.fields', 72 | 'mautic.integrations.helper', 73 | ], 74 | ], 75 | 'mautic_ecommerce.sync.data_exchange.product_object_helper' => [ 76 | 'class' => Bundle\Sync\DataExchange\Internal\ProductObjectHelper::class, 77 | 'arguments' => [ 78 | 'mautic_ecommerce.repository.product', 79 | ], 80 | ], 81 | ], 82 | 'integrations' => [ 83 | 'mautic.integration.prestashop' => [ 84 | 'class' => Bundle\Integration\PrestashopIntegration::class, 85 | 'arguments' => [ 86 | 'mautic_ecommerce.sync.repository.fields', 87 | 'mautic_ecommerce.sync.mapping_manual.factory', 88 | 'mautic_ecommerce.sync.data_exchange', 89 | ], 90 | 'tags' => [ 91 | 'mautic.integration', 92 | 'mautic.basic_integration', 93 | 'mautic.config_integration', 94 | 'mautic.sync_integration', 95 | ], 96 | ], 97 | 'mautic.integration.woocommerce' => [ 98 | 'class' => Bundle\Integration\WooCommerceIntegration::class, 99 | 'arguments' => [ 100 | 'mautic_ecommerce.sync.repository.fields', 101 | 'mautic_ecommerce.sync.mapping_manual.factory', 102 | 'mautic_ecommerce.sync.data_exchange', 103 | ], 104 | 'tags' => [ 105 | 'mautic.integration', 106 | 'mautic.basic_integration', 107 | 'mautic.config_integration', 108 | 'mautic.sync_integration', 109 | ], 110 | ], 111 | ], 112 | 'events' => [ 113 | 'mautic_ecommerce.subscriber.lead' => [ 114 | 'class' => Bundle\EventListener\LeadListSubscriber::class, 115 | 'arguments' => [ 116 | 'mautic.lead.provider.typeOperator', 117 | ], 118 | ], 119 | 'mautic_ecommerce.subscriber.sync' => [ 120 | 'class' => Bundle\EventListener\SyncSubscriber::class, 121 | 'tag' => 'kernel.event_subscriber', 122 | ], 123 | 'mautic_ecommerce.subscriber.product_object' => [ 124 | 'class' => Bundle\EventListener\ProductObjectSubscriber::class, 125 | 'arguments' => [ 126 | 'mautic_ecommerce.sync.data_exchange.product_object_helper', 127 | ], 128 | 'tag' => 'kernel.event_subscriber', 129 | ], 130 | 'mautic_ecommerce_subscriber.email' => [ 131 | 'class' => Bundle\EventListener\EmailSubscriber::class, 132 | 'tag' => 'kernel.event_subscriber', 133 | 'arguments' => [ 134 | '@mautic_ecommerce.email.parser', 135 | '@translator', 136 | ], 137 | ], 138 | 'mautic_ecommerce.subscriber.ui.lead' => [ 139 | 'class' => LeadUiSubscriber::class, 140 | 'tag' => 'kernel.event_subscriber', 141 | 'arguments' => [ 142 | 'mautic_ecommerce.repository.transaction', 143 | ], 144 | ], 145 | ], 146 | 'repositories' => [ 147 | 'mautic_ecommerce.repository.transaction' => [ 148 | 'class' => Bundle\Entity\TransactionRepository::class, 149 | 'arguments' => [ 150 | 'doctrine', 151 | ], 152 | ], 153 | 'mautic_ecommerce.repository.product' => [ 154 | 'class' => Doctrine\ORM\EntityRepository::class, 155 | 'factory' => ['@doctrine.orm.entity_manager', 'getRepository'], 156 | 'arguments' => [ 157 | Bundle\Entity\Product::class, 158 | ], 159 | ], 160 | ], 161 | 'others' => [ 162 | Bundle\Segment\Query\Filter\PurchaseProductFilterQueryBuilder::getServiceId() => [ 163 | 'class' => Bundle\Segment\Query\Filter\PurchaseProductFilterQueryBuilder::class, 164 | ], 165 | 'mautic_ecommerce.email.parser' => [ 166 | 'class' => Bundle\Email\Parser::class, 167 | 'arguments' => [ 168 | '@mautic_ecommerce.repository.transaction', 169 | ], 170 | ], 171 | ], 172 | 'helpers' => [ 173 | 'mautic_ecommerce.templating.helper.money' => [ 174 | 'class' => Bundle\Templating\Helper\MoneyHelper::class, 175 | 'alias' => 'ecommerce_money', 176 | ], 177 | ], 178 | ], 179 | ]; 180 | -------------------------------------------------------------------------------- /Controller/AjaxController.php: -------------------------------------------------------------------------------- 1 | getProductRepository(); 18 | $term = $request->query->get('filter'); 19 | 20 | $products = $productRepository->search($term); 21 | 22 | return new JsonResponse( 23 | array_merge( 24 | ['success' => true], 25 | array_map(static function (Product $product): array { 26 | return ['value' => $product->getName(), 'id' => $product->getId()]; 27 | }, $products) 28 | ) 29 | ); 30 | } 31 | 32 | public function getProductRepository(): ProductRepository 33 | { 34 | /** @var ProductRepository $repository */ 35 | $repository = $this->get('mautic_ecommerce.repository.product'); 36 | 37 | return $repository; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Controller/TransactionController.php: -------------------------------------------------------------------------------- 1 | setListFilters('ecommerceTransaction'); 25 | 26 | /** @var PageHelperFactoryInterface $pageHelperFacotry */ 27 | $pageHelperFacotry = $this->get('mautic.page.helper.factory'); 28 | $pageHelper = $pageHelperFacotry->make('mautic.ecommerceTransaction', $page); 29 | 30 | // on récupère la pagination 31 | $limit = $pageHelper->getLimit(); 32 | $start = $pageHelper->getStart(); 33 | 34 | // on récupère les filtres 35 | // on récupère le order by 36 | 37 | // on récupère la liste des entitités qui match tout ça 38 | $transactions = $this->getTransactionRepository()->getAllTransactions($start, $limit); 39 | // on récupère le nombre d'entité "total" 40 | $count = $this->getTransactionRepository()->getAllTransactionsCount(); 41 | 42 | if ($count && $count < ($start + 1)) { 43 | // si on est après la dernière page, on doit rediriger sur la dernière page 44 | $lastPage = $pageHelper->countPage($count); 45 | $returnUrl = $this->generateUrl('mautic_ecommerce_transaction_index', ['page' => $lastPage]); 46 | $pageHelper->rememberPage($lastPage); 47 | 48 | return $this->postActionRedirect( 49 | [ 50 | 'returnUrl' => $returnUrl, 51 | 'viewParameters' => ['page' => $lastPage], 52 | 'contentTemplate' => 'MauticEcommerceBundle:Transaction:index', 53 | 'passthroughVars' => [ 54 | 'activeLink' => '#mautic_ecommerce_transaction_index', 55 | 'mauticContent' => 'ecommerceTransaction', 56 | ], 57 | ] 58 | ); 59 | } 60 | 61 | $pageHelper->rememberPage($page); 62 | 63 | // template différent si requete ajax ? 64 | $tmpl = $this->request->isXmlHttpRequest() ? $this->request->get('tmpl', 'index') : 'index'; 65 | 66 | return $this->delegateView( 67 | [ 68 | 'viewParameters' => [ 69 | 'items' => $transactions, 70 | 'page' => $page, 71 | 'limit' => $limit, 72 | 'tmpl' => $tmpl, 73 | 'totalItems' => $count, 74 | ], 75 | 'contentTemplate' => 'MauticEcommerceBundle:Transaction:list.html.php', 76 | 'passthroughVars' => [ 77 | 'activeLink' => '#mautic_ecommerce_transaction_index', 78 | 'mauticContent' => 'ecommerceTransaction', 79 | 'route' => $this->generateUrl('mautic_ecommerce_transaction_index', ['page' => $page]), 80 | ], 81 | ] 82 | ); 83 | } 84 | 85 | private function getTransactionRepository(): TransactionRepository 86 | { 87 | return $this->get('mautic_ecommerce.repository.transaction'); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /Email/Helper/ParamsHelper.php: -------------------------------------------------------------------------------- 1 | transactionRepository = $transactionRepository; 18 | $this->transactionParser = new TransactionParser(); 19 | } 20 | 21 | /** 22 | * @param array|Lead $lead 23 | */ 24 | public function parse(string $content, $lead): string 25 | { 26 | preg_match_all('/{last_transaction((?:[^{}]|{[^}]*})*)}(.*){\/last_transaction}/msU', $content, $matches); 27 | 28 | if (empty($matches[0])) { 29 | return $content; 30 | } 31 | 32 | $transaction = $this->transactionRepository->findLatest($lead); 33 | 34 | foreach ($matches[0] as $key => $transactionWrapper) { 35 | $transactionContent = $matches[2][$key]; 36 | 37 | if ($transaction !== null) { 38 | $parsedContent = $this->transactionParser->parse($transactionContent, $transaction); 39 | } 40 | 41 | $content = str_replace($transactionWrapper, $parsedContent ?? '', $content); 42 | } 43 | 44 | return $content; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Email/Tag/TransactionProductTag.php: -------------------------------------------------------------------------------- 1 | transactionProduct = $transactionProduct; 20 | $this->tag = $tag; 21 | $this->params = $params; 22 | } 23 | 24 | public function getValue(): string 25 | { 26 | switch ($this->tag) { 27 | case 'quantity': 28 | return (string) $this->transactionProduct->getQuantity(); 29 | case 'name': 30 | return $this->transactionProduct->getProduct()->getName(); 31 | case 'unit_price': 32 | return (string) ($this->transactionProduct->getProduct()->getUnitPrice() / 100); 33 | default: 34 | return "Unknown ({$this->tag})"; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Email/Tag/TransactionTag.php: -------------------------------------------------------------------------------- 1 | transaction = $transaction; 18 | $this->tag = $tag; 19 | $this->params = $params; 20 | } 21 | 22 | public function getValue(): string 23 | { 24 | switch ($this->tag) { 25 | case 'price': 26 | return (string) ($this->transaction->getPriceWithTaxes() / 100); 27 | case 'nb_products': 28 | return (string) $this->transaction->getNbProducts(); 29 | case 'date': 30 | $format = $this->params['format'] ?? 'd/m/Y H:i:s'; 31 | 32 | return $this->transaction->getDate()->format($format); 33 | default: 34 | return "Unknown ({$this->tag})"; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Email/TransactionParser.php: -------------------------------------------------------------------------------- 1 | transactionProductsParser = new TransactionProductsParser(); 18 | } 19 | 20 | public function parse(string $content, Transaction $transaction): string 21 | { 22 | $content = $this->parseTransaction($content, $transaction); 23 | 24 | return $this->transactionProductsParser->parse($content, $transaction); 25 | } 26 | 27 | private function parseTransaction(string $content, Transaction $transaction): string 28 | { 29 | preg_match_all('/{transaction:([^ }]+)( [^}]+)?}/', $content, $tags); 30 | 31 | if (empty($tags[1])) { 32 | return $content; 33 | } 34 | 35 | foreach ($tags[1] as $tagIndex => $tag) { 36 | $transactionTag = new TransactionTag($transaction, $tag, ParamsHelper::parse($tags[2][$tagIndex] ?? '')); 37 | 38 | $content = str_replace($tags[0][$tagIndex], $transactionTag->getValue(), $content); 39 | } 40 | 41 | return $content; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Email/TransactionProductsParser.php: -------------------------------------------------------------------------------- 1 | getProducts() as $transactionProduct) { 28 | $itemsContent .= $this->parseItem($template, $transactionProduct); 29 | } 30 | 31 | return str_replace($transactionProductMatches[0], $itemsContent, $content); 32 | } 33 | 34 | private function parseItem(string $template, TransactionProduct $transactionProduct): string 35 | { 36 | preg_match_all('/{product:([^ }:]+)(:([^ }:]+))?( [^}]+)?}/', $template, $tags); 37 | 38 | if (empty($tags)) { 39 | return $template; 40 | } 41 | 42 | foreach ($tags[1] as $tagIndex => $tag) { 43 | $transactionProductTag = new TransactionProductTag($transactionProduct, $tag, ParamsHelper::parse($tags[3][$tagIndex] ?? '')); 44 | 45 | $template = str_replace($tags[0][$tagIndex], $transactionProductTag->getValue(), $template); 46 | } 47 | 48 | return $template; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Entity/Product.php: -------------------------------------------------------------------------------- 1 | 46 | * 47 | * @ORM\OneToMany(targetEntity=TransactionProduct::class, mappedBy="product") 48 | */ 49 | private Collection $transactions; 50 | 51 | public function __construct() 52 | { 53 | $this->transactions = new ArrayCollection(); 54 | } 55 | 56 | public function getId(): int 57 | { 58 | return $this->id; 59 | } 60 | 61 | public function getName(): string 62 | { 63 | return $this->name; 64 | } 65 | 66 | public function setName(string $name): void 67 | { 68 | $this->name = $name; 69 | } 70 | 71 | public function getUnitPrice(): int 72 | { 73 | return $this->unitPrice; 74 | } 75 | 76 | public function setUnitPrice(int $unitPrice): void 77 | { 78 | $this->unitPrice = $unitPrice; 79 | } 80 | 81 | public function getCreatedAt(): \DateTimeImmutable 82 | { 83 | return $this->createdAt; 84 | } 85 | 86 | public function setCreatedAt(\DateTimeImmutable $createdAt): void 87 | { 88 | $this->createdAt = $createdAt; 89 | } 90 | 91 | public function getUpdatedAt(): \DateTimeImmutable 92 | { 93 | return $this->updatedAt; 94 | } 95 | 96 | public function setUpdatedAt(\DateTimeImmutable $updatedAt): void 97 | { 98 | $this->updatedAt = $updatedAt; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Entity/ProductRepository.php: -------------------------------------------------------------------------------- 1 | createQueryBuilder('product'); 17 | 18 | $queryBuilder 19 | ->andWhere('product.name LIKE :name') 20 | ->setParameter('name', '%' . $term . '%') 21 | ; 22 | 23 | $queryBuilder->orderBy('product.name', 'ASC'); 24 | 25 | return $queryBuilder->getQuery()->getResult(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Entity/Transaction.php: -------------------------------------------------------------------------------- 1 | 55 | */ 56 | private Collection $products; 57 | 58 | public function __construct( 59 | Lead $lead, 60 | int $id, 61 | \DateTimeImmutable $date, 62 | int $priceWithoutTaxes, 63 | int $priceWithTaxes, 64 | int $nbProducts 65 | ) { 66 | $this->lead = $lead; 67 | $this->id = $id; 68 | $this->date = $date; 69 | $this->priceWithoutTaxes = $priceWithoutTaxes; 70 | $this->priceWithTaxes = $priceWithTaxes; 71 | $this->nbProducts = $nbProducts; 72 | 73 | $this->products = new ArrayCollection(); 74 | } 75 | 76 | public function getLead(): Lead 77 | { 78 | return $this->lead; 79 | } 80 | 81 | public function getId(): int 82 | { 83 | return $this->id; 84 | } 85 | 86 | public function getDate(): \DateTimeImmutable 87 | { 88 | return $this->date; 89 | } 90 | 91 | public function getPriceWithoutTaxes(): int 92 | { 93 | return $this->priceWithoutTaxes; 94 | } 95 | 96 | public function getPriceWithTaxes(): int 97 | { 98 | return $this->priceWithTaxes; 99 | } 100 | 101 | public function getNbProducts(): int 102 | { 103 | return $this->nbProducts; 104 | } 105 | 106 | public function addProduct(Product $product, int $quantity): void 107 | { 108 | $this->products->set($product->getId(), new TransactionProduct($this, $product, $quantity)); 109 | } 110 | 111 | /** 112 | * @return Collection 113 | */ 114 | public function getProducts() 115 | { 116 | return $this->products; 117 | } 118 | 119 | public function update(Transaction $transaction): void 120 | { 121 | $this->date = $transaction->date; 122 | $this->priceWithoutTaxes = $transaction->priceWithoutTaxes; 123 | $this->priceWithTaxes = $transaction->priceWithTaxes; 124 | $this->nbProducts = $transaction->nbProducts; 125 | 126 | $this->products = new ArrayCollection(); 127 | 128 | /** @var TransactionProduct $product */ 129 | foreach ($transaction->products as $product) { 130 | $this->addProduct($product->getProduct(), $product->getQuantity()); 131 | } 132 | } 133 | 134 | public static function fromOrder(Lead $lead, Order $order): self 135 | { 136 | return new self( 137 | $lead, 138 | $order->id, 139 | $order->date, 140 | $order->priceWithoutTaxes, 141 | $order->priceWithTaxes, 142 | $order->nbProducts, 143 | ); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Entity/TransactionProduct.php: -------------------------------------------------------------------------------- 1 | transaction = $transaction; 42 | $this->product = $product; 43 | $this->quantity = $quantity; 44 | } 45 | 46 | public function getId(): int 47 | { 48 | return $this->id; 49 | } 50 | 51 | public function getTransaction(): Transaction 52 | { 53 | return $this->transaction; 54 | } 55 | 56 | public function getProduct(): Product 57 | { 58 | return $this->product; 59 | } 60 | 61 | public function getQuantity(): int 62 | { 63 | return $this->quantity; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Entity/TransactionRepository.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | class TransactionRepository extends ServiceEntityRepository 15 | { 16 | public function __construct(ManagerRegistry $registry) 17 | { 18 | parent::__construct($registry, Transaction::class); 19 | } 20 | 21 | public function createOrUpdate(Transaction $transaction): void 22 | { 23 | /** @var Transaction|null $existingTransaction */ 24 | $existingTransaction = $this->find($transaction->getId()); 25 | if ($existingTransaction === null) { 26 | $this->getEntityManager()->persist($transaction); 27 | 28 | return; 29 | } 30 | 31 | $existingTransaction->update($transaction); 32 | } 33 | 34 | /** 35 | * @param array|Lead $lead 36 | */ 37 | public function findLatest($lead): ?Transaction 38 | { 39 | if ($lead instanceof Lead) { 40 | $id = $lead->getId(); 41 | } elseif (\is_array($lead)) { 42 | $id = $lead['id']; 43 | } else { 44 | throw new \RuntimeException('Unable to retrieve the lead'); 45 | } 46 | 47 | return $this->findOneBy(['lead' => $id], ['date' => 'DESC']); 48 | } 49 | 50 | public function getTransactionsCount(Lead $lead, array $filters = null): int 51 | { 52 | return $this->count(['lead' => $lead]); 53 | } 54 | 55 | public function getTransactions(Lead $lead, array $filters = null, array $orderBy = null, $page = 1, $limit = 25): array 56 | { 57 | $queryBuilder = $this->createQueryBuilder('t'); 58 | 59 | $queryBuilder 60 | ->andWhere('t.lead = :lead') 61 | ->setParameter('lead', $lead) 62 | ; 63 | 64 | return $queryBuilder->getQuery()->getResult(); 65 | } 66 | 67 | public function getAllTransactions($start = 1, $limit = 25): array 68 | { 69 | $queryBuilder = $this->createQueryBuilder('t'); 70 | 71 | $queryBuilder 72 | ->setFirstResult($start) 73 | ->setMaxResults($limit) 74 | ; 75 | 76 | return $queryBuilder->getQuery()->getResult(); 77 | } 78 | 79 | public function getAllTransactionsCount(): int 80 | { 81 | $queryBuilder = $this->createQueryBuilder('t'); 82 | 83 | $queryBuilder 84 | ->select('count(t.id)') 85 | ; 86 | 87 | return (int) $queryBuilder->getQuery()->getSingleScalarResult(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /EventListener/EmailSubscriber.php: -------------------------------------------------------------------------------- 1 | parser = $parser; 22 | $this->translator = $translator; 23 | } 24 | 25 | public static function getSubscribedEvents(): array 26 | { 27 | return [ 28 | EmailEvents::EMAIL_ON_SEND => 'onEmailGenerate', 29 | EmailEvents::EMAIL_ON_DISPLAY => 'onEmailGenerate', 30 | EmailEvents::EMAIL_ON_BUILD => 'onEmailBuild', 31 | ]; 32 | } 33 | 34 | public function onEmailGenerate(EmailSendEvent $event): void 35 | { 36 | $lead = $event->getLead(); 37 | 38 | $event->setContent($this->parser->parse($event->getContent(), $lead)); 39 | $event->setPlainText($this->parser->parse($event->getPlainText(), $lead)); 40 | $event->setSubject($this->parser->parse($event->getSubject(), $lead)); 41 | } 42 | 43 | public function onEmailBuild(EmailBuilderEvent $event): void 44 | { 45 | $tokens = [ 46 | '{transaction:price}' => $this->translator->trans('mautic_ecommerce.email.token.transaction.price'), 47 | '{transaction:nb_products}' => $this->translator->trans('mautic_ecommerce.email.token.transaction.nb_products'), 48 | '{transaction:date}' => $this->translator->trans('mautic_ecommerce.email.token.transaction.date'), 49 | '{product:name}' => $this->translator->trans('mautic_ecommerce.email.token.product.name'), 50 | '{product:quantity}' => $this->translator->trans('mautic_ecommerce.email.token.product.quantity'), 51 | '{product:unit_price}' => $this->translator->trans('mautic_ecommerce.email.token.product.unit_price'), 52 | ]; 53 | 54 | if ($event->tokensRequested(array_keys($tokens))) { 55 | $event->addTokens( 56 | $event->filterTokens($tokens) 57 | ); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /EventListener/LeadListSubscriber.php: -------------------------------------------------------------------------------- 1 | typeOperatorProvider = $typeOperatorProvider; 24 | } 25 | 26 | public static function getSubscribedEvents() 27 | { 28 | return [ 29 | LeadEvents::LIST_FILTERS_CHOICES_ON_GENERATE => 'onGenerateSegmentFiltersAddTransactionFields', 30 | LeadEvents::SEGMENT_DICTIONARY_ON_GENERATE => 'onGenerateSegmentDictionary', 31 | ]; 32 | } 33 | 34 | public function onGenerateSegmentFiltersAddTransactionFields(LeadListFiltersChoicesEvent $event): void 35 | { 36 | $event->addChoice('lead', 'lead_order_date', [ 37 | 'label' => 'Date de dernière commande', 38 | 'object' => 'lead', 39 | 'properties' => ['type' => 'date'], 40 | 'operators' => $this->typeOperatorProvider->getOperatorsIncluding([ 41 | OperatorOptions::EQUAL_TO, 42 | OperatorOptions::NOT_EQUAL_TO, 43 | OperatorOptions::GREATER_THAN, 44 | OperatorOptions::LESS_THAN, 45 | OperatorOptions::GREATER_THAN_OR_EQUAL, 46 | OperatorOptions::LESS_THAN_OR_EQUAL, 47 | ]), 48 | ]); 49 | 50 | $event->addChoice('lead', 'lead_transaction_count', [ 51 | 'label' => 'Nombre de commande', 52 | 'object' => 'lead', 53 | 'properties' => ['type' => 'number'], 54 | 'operators' => $this->typeOperatorProvider->getOperatorsIncluding([ 55 | OperatorOptions::EQUAL_TO, 56 | OperatorOptions::NOT_EQUAL_TO, 57 | OperatorOptions::GREATER_THAN, 58 | OperatorOptions::LESS_THAN, 59 | OperatorOptions::GREATER_THAN_OR_EQUAL, 60 | OperatorOptions::LESS_THAN_OR_EQUAL, 61 | ]), 62 | ]); 63 | 64 | $event->addChoice('lead', 'lead_transaction_sum_price_with_taxes', [ 65 | 'label' => 'CA Cumulé', 66 | 'object' => 'lead', 67 | 'properties' => ['type' => 'money'], 68 | 'operators' => $this->typeOperatorProvider->getOperatorsIncluding([ 69 | OperatorOptions::EQUAL_TO, 70 | OperatorOptions::NOT_EQUAL_TO, 71 | OperatorOptions::GREATER_THAN, 72 | OperatorOptions::LESS_THAN, 73 | OperatorOptions::GREATER_THAN_OR_EQUAL, 74 | OperatorOptions::LESS_THAN_OR_EQUAL, 75 | ]), 76 | ]); 77 | 78 | $event->addChoice('lead', 'lead_transaction_purchase_product', [ 79 | 'label' => 'Produit acheté', 80 | 'object' => 'lead', 81 | 'properties' => [ 82 | 'type' => 'lookup_id', 83 | 'data-action' => 'plugin:Ecommerce:products', 84 | ], 85 | 'operators' => $this->typeOperatorProvider->getOperatorsIncluding([ 86 | OperatorOptions::EQUAL_TO, 87 | OperatorOptions::NOT_EQUAL_TO, 88 | ]), 89 | ]); 90 | } 91 | 92 | public function onGenerateSegmentDictionary(SegmentDictionaryGenerationEvent $event): void 93 | { 94 | $event->addTranslation('lead_order_date', [ 95 | 'type' => ForeignValueFilterQueryBuilder::getServiceId(), 96 | 'foreign_table' => 'ecommerce_transaction', 97 | 'field' => 'date', 98 | ]); 99 | 100 | $event->addTranslation('lead_transaction_count', [ 101 | 'type' => ForeignFuncFilterQueryBuilder::getServiceId(), 102 | 'foreign_table' => 'ecommerce_transaction', 103 | 'foreign_table_field' => 'lead_id', 104 | 'table' => 'leads', 105 | 'table_field' => 'id', 106 | 'func' => 'count', 107 | 'field' => 'id', 108 | ]); 109 | 110 | $event->addTranslation('lead_transaction_sum_price_with_taxes', [ 111 | 'type' => ForeignFuncFilterQueryBuilder::getServiceId(), 112 | 'foreign_table' => 'ecommerce_transaction', 113 | 'foreign_table_field' => 'lead_id', 114 | 'table' => 'leads', 115 | 'table_field' => 'id', 116 | 'func' => 'sum', 117 | 'field' => 'price_with_taxes', 118 | ]); 119 | 120 | $event->addTranslation('lead_transaction_purchase_product', [ 121 | 'type' => PurchaseProductFilterQueryBuilder::getServiceId(), 122 | ]); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /EventListener/LeadUiSubscriber.php: -------------------------------------------------------------------------------- 1 | transactionRepository = $transactionRepository; 20 | } 21 | 22 | /** 23 | * {@inheritDoc} 24 | */ 25 | public static function getSubscribedEvents() 26 | { 27 | return [ 28 | CoreEvents::VIEW_INJECT_CUSTOM_CONTENT => 'onLeadDetailRender', 29 | ]; 30 | } 31 | 32 | public function onLeadDetailRender(CustomContentEvent $event): void 33 | { 34 | // dump(['viewName' => $event->getViewName(), 'context' => $event->getContext()]); 35 | if ($event->getViewName() !== 'MauticLeadBundle:Lead:lead.html.php') { 36 | return; 37 | } 38 | $lead = $event->getVars()['lead']; 39 | 40 | // retrieve transactions from $eveng 41 | 42 | switch ($event->getContext()) { 43 | case 'tabs': 44 | $this->renderContactTabHeader($event, $lead); 45 | break; 46 | case 'tabs.content': 47 | $this->renderContactTabContent($event, $lead); 48 | break; 49 | } 50 | } 51 | 52 | private function renderContactTabHeader(CustomContentEvent $event, Lead $lead): void 53 | { 54 | $count = $this->transactionRepository->getTransactionsCount($lead); 55 | 56 | $event->addTemplate('MauticEcommerceBundle:Contact:tab.html.php', ['count' => $count]); 57 | } 58 | 59 | private function renderContactTabContent(CustomContentEvent $event, Lead $lead): void 60 | { 61 | $transactions = $this->transactionRepository->getTransactions($lead); 62 | 63 | $event->addTemplate('MauticEcommerceBundle:Contact:tabContent.html.php', [ 64 | 'lead' => $lead, 65 | 'items' => $transactions, 66 | 'totalItems' => $this->transactionRepository->getTransactionsCount($lead), 67 | 'page' => 1, 68 | 'limit' => $this->transactionRepository->getTransactionsCount($lead), 69 | ]); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /EventListener/ProductObjectSubscriber.php: -------------------------------------------------------------------------------- 1 | productObjectHelper = $productObjectHelper; 22 | } 23 | 24 | public static function getSubscribedEvents(): array 25 | { 26 | return [ 27 | IntegrationEvents::INTEGRATION_COLLECT_INTERNAL_OBJECTS => ['collectInternalObjects', 0], 28 | IntegrationEvents::INTEGRATION_UPDATE_INTERNAL_OBJECTS => ['updateProducts', 0], 29 | IntegrationEvents::INTEGRATION_CREATE_INTERNAL_OBJECTS => ['createProducts', 0], 30 | ]; 31 | } 32 | 33 | public function collectInternalObjects(InternalObjectEvent $event): void 34 | { 35 | $event->addObject(new Product()); 36 | } 37 | 38 | public function updateProducts(InternalObjectUpdateEvent $event): void 39 | { 40 | if (Product::NAME !== $event->getObject()->getName()) { 41 | return; 42 | } 43 | 44 | $event->setUpdatedObjectMappings( 45 | $this->productObjectHelper->update( 46 | $event->getIdentifiedObjectIds(), 47 | $event->getUpdateObjects() 48 | ) 49 | ); 50 | $event->stopPropagation(); 51 | } 52 | 53 | public function createProducts(InternalObjectCreateEvent $event): void 54 | { 55 | if (Product::NAME !== $event->getObject()->getName()) { 56 | return; 57 | } 58 | 59 | $event->setObjectMappings($this->productObjectHelper->create($event->getCreateObjects())); 60 | $event->stopPropagation(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /EventListener/SyncSubscriber.php: -------------------------------------------------------------------------------- 1 | 'onSyncFieldsLoad', 21 | ]; 22 | } 23 | 24 | public function onSyncFieldsLoad(MauticSyncFieldsLoadEvent $event): void 25 | { 26 | if ($event->getObjectName() === Product::NAME) { 27 | foreach (Product::getFields() as $field => $label) { 28 | $event->addField($field, $label); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Integration/EcommerceAbstractIntegration.php: -------------------------------------------------------------------------------- 1 | fieldRepository = $fieldRepository; 41 | $this->mappingManualFactory = $mappingManualFactory; 42 | $this->syncDataExchange = $syncDataExchange; 43 | $this->config = new Config($this); 44 | } 45 | 46 | public function getSyncConfigObjects(): array 47 | { 48 | return [ 49 | MappingManualFactory::CUSTOMER_OBJECT => 'Customer', 50 | MappingManualFactory::PRODUCT_OBJECT => 'Products', 51 | ]; 52 | } 53 | 54 | public function getSyncMappedObjects(): array 55 | { 56 | return [ 57 | MappingManualFactory::CUSTOMER_OBJECT => Contact::NAME, 58 | MappingManualFactory::PRODUCT_OBJECT => Product::NAME, 59 | ]; 60 | } 61 | 62 | /** 63 | * @return MappedFieldInfoInterface[] 64 | */ 65 | public function getRequiredFieldsForMapping(string $objectName): array 66 | { 67 | return $this->fieldRepository->getRequiredFieldsForMapping($objectName); 68 | } 69 | 70 | /** 71 | * @return MappedFieldInfoInterface[] 72 | */ 73 | public function getOptionalFieldsForMapping(string $objectName): array 74 | { 75 | return $this->fieldRepository->getOptionalFieldsForMapping($objectName); 76 | } 77 | 78 | /** 79 | * @return MappedFieldInfoInterface[] 80 | */ 81 | public function getAllFieldsForMapping(string $objectName): array 82 | { 83 | // Order fields by required alphabetical then optional alphabetical 84 | $sorter = function (MappedFieldInfoInterface $field1, MappedFieldInfoInterface $field2) { 85 | return strnatcasecmp($field1->getLabel(), $field2->getLabel()); 86 | }; 87 | 88 | $requiredFields = $this->fieldRepository->getRequiredFieldsForMapping($objectName); 89 | uasort($requiredFields, $sorter); 90 | 91 | $optionalFields = $this->fieldRepository->getOptionalFieldsForMapping($objectName); 92 | uasort($optionalFields, $sorter); 93 | 94 | return array_merge( 95 | $requiredFields, 96 | $optionalFields 97 | ); 98 | } 99 | 100 | public function getSupportedFeatures(): array 101 | { 102 | return [ 103 | ConfigFormFeaturesInterface::FEATURE_SYNC => 'mautic.integration.feature.sync', 104 | ]; 105 | } 106 | 107 | public function getMappingManual(): MappingManualDAO 108 | { 109 | return $this->mappingManualFactory->getManual(static::NAME); 110 | } 111 | 112 | public function getSyncDataExchange(): SyncDataExchangeInterface 113 | { 114 | return $this->syncDataExchange; 115 | } 116 | 117 | public function getConfig(): Config 118 | { 119 | return $this->config; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Integration/EcommerceIntegrationInterface.php: -------------------------------------------------------------------------------- 1 | $url, 39 | 'token' => $token 40 | ] = $this->getIntegrationConfiguration()->getApiKeys(); 41 | 42 | return new Client($url, $token); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Integration/WooCommerceIntegration.php: -------------------------------------------------------------------------------- 1 | $url, 39 | 'consumerKey' => $consumerKey, 40 | 'consumerSecret' => $consumerSecret, 41 | ] = $this->getIntegrationConfiguration()->getApiKeys(); 42 | 43 | return new Client($url, $consumerKey, $consumerSecret); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | install: 2 | symfony composer update 3 | 4 | lint: lint.php-cs-fixer lint.phpstan 5 | 6 | lint.php-cs-fixer: 7 | symfony php vendor/bin/php-cs-fixer fix 8 | 9 | lint.phpstan: 10 | symfony php vendor/bin/phpstan analyze --memory-limit=-1 11 | 12 | lint.php-cs-fixer@integration: 13 | symfony php vendor/bin/php-cs-fixer fix --ansi --dry-run --diff 14 | 15 | install@integration: 16 | composer install --ansi --verbose --no-interaction --no-progress --prefer-dist --optimize-autoloader --no-scripts --ignore-platform-reqs 17 | 18 | lint.phpstan@integration: 19 | symfony php vendor/bin/phpstan --no-progress --ansi --no-interaction analyse --configuration ./phpstan.neon.dist 20 | -------------------------------------------------------------------------------- /MauticEcommerceBundle.php: -------------------------------------------------------------------------------- 1 | hasTable('ecommerce_transaction') && !$schema->hasTable('ecommerce_product'); 18 | } 19 | 20 | /** 21 | * {@inheritDoc} 22 | */ 23 | protected function up(): void 24 | { 25 | $this->addSql(<<id = $id; 25 | $this->email = $email; 26 | $this->firstName = $firstName; 27 | $this->lastName = $lastName; 28 | $this->createdAt = $createdAt; 29 | $this->updatedAt = $updatedAt; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Model/Order.php: -------------------------------------------------------------------------------- 1 | id = $id; 29 | $this->date = $date; 30 | $this->priceWithoutTaxes = $priceWithoutTaxes; 31 | $this->priceWithTaxes = $priceWithTaxes; 32 | $this->nbProducts = $nbProducts; 33 | $this->customerId = $customerId; 34 | $this->products = $products; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Model/OrderProduct.php: -------------------------------------------------------------------------------- 1 | productId = $productId; 15 | $this->quantity = $quantity; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Model/Product.php: -------------------------------------------------------------------------------- 1 | id = $id; 23 | $this->name = $name; 24 | $this->unitPrice = $unitPrice; 25 | $this->createdAt = $createdAt; 26 | $this->updatedAt = $updatedAt; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Prestashop/Api/Client.php: -------------------------------------------------------------------------------- 1 | withUserInfo($token); 31 | 32 | $this->httpClient = new \GuzzleHttp\Client(['base_uri' => $uri]); 33 | $this->serializer = new Serializer( 34 | [ 35 | new ArrayDenormalizer(), 36 | new DateTimeNormalizer(), 37 | new CustomerNormalizer(), 38 | new OrderNormalizer(), 39 | new ProductNormalizer(), 40 | new OrderProductNormalizer(), 41 | ], 42 | [new JsonEncoder()] 43 | ); 44 | } 45 | 46 | public function getCustomers(int $page, int $limit = 100): array 47 | { 48 | $data = $this->get('customers', $page, $limit); 49 | 50 | return $this->serializer->denormalize( 51 | $data['customers'] ?? [], 52 | Customer::class . '[]', 53 | JsonEncoder::FORMAT, 54 | ['integration' => PrestashopIntegration::NAME] 55 | ); 56 | } 57 | 58 | public function getOrders(int $page, int $limit = 100): array 59 | { 60 | $data = $this->get('orders', $page, $limit); 61 | 62 | return $this->serializer->denormalize( 63 | $data['orders'] ?? [], 64 | Order::class . '[]', 65 | JsonEncoder::FORMAT, 66 | ['integration' => PrestashopIntegration::NAME] 67 | ); 68 | } 69 | 70 | public function getProducts(int $page, int $limit = 100): array 71 | { 72 | $data = $this->get('products', $page, $limit); 73 | 74 | return $this->serializer->denormalize( 75 | $data['products'] ?? [], 76 | Product::class . '[]', 77 | JsonEncoder::FORMAT, 78 | ['integration' => PrestashopIntegration::NAME] 79 | ); 80 | } 81 | 82 | private function get(string $resource, int $page, int $limit): array 83 | { 84 | $offset = ($page - 1) * $limit; 85 | 86 | $response = $this->httpClient->get( 87 | $resource, 88 | [ 89 | 'query' => [ 90 | 'display' => 'full', 91 | 'limit' => $offset . ',' . $limit, 92 | 'output_format' => 'JSON', 93 | ], 94 | ] 95 | ); 96 | 97 | return json_decode($response->getBody()->getContents(), true); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Prestashop/Form/Type/ConfigFormType.php: -------------------------------------------------------------------------------- 1 | add('url', UrlType::class, ['attr' => ['class' => 'form-control']]) 19 | ->add('token', TextType::class, ['attr' => ['class' => 'form-control']]) 20 | ; 21 | } 22 | 23 | public function configureOptions(OptionsResolver $resolver): void 24 | { 25 | $resolver->setDefaults( 26 | [ 27 | 'integration' => null, 28 | ] 29 | ); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Prestashop/Normalizer/CustomerNormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizeDate($data['date_add']), 25 | $this->denormalizeDate($data['date_upd']) 26 | ); 27 | } 28 | 29 | public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool 30 | { 31 | return $type === Customer::class && $context['integration'] === PrestashopIntegration::NAME; 32 | } 33 | 34 | protected function denormalizeDate(string $date): \DateTimeImmutable 35 | { 36 | return $this->denormalizer->denormalize($date, \DateTimeImmutable::class); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Prestashop/Normalizer/OrderNormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizer->denormalize($data['date_add'], \DateTimeImmutable::class), 24 | (int) ((float) $data['total_paid_tax_excl'] * 100), 25 | (int) ((float) $data['total_paid_tax_incl'] * 100), 26 | \count($data['associations']['order_rows']), 27 | $this->denormalizer->denormalize($data['associations']['order_rows'], OrderProduct::class . '[]'), 28 | ); 29 | } 30 | 31 | public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool 32 | { 33 | return $type === Order::class && $context['integration'] === PrestashopIntegration::NAME; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Prestashop/Normalizer/OrderProductNormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizeDate($data['date_add']), 24 | $this->denormalizeDate($data['date_upd']) 25 | ); 26 | } 27 | 28 | public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool 29 | { 30 | return $type === Product::class && $context['integration'] === PrestashopIntegration::NAME; 31 | } 32 | 33 | protected function denormalizeDate(string $date): \DateTimeImmutable 34 | { 35 | return $this->denormalizer->denormalize($date, \DateTimeImmutable::class); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Mautic EcommerceBundle 2 | 3 | ## Installation 4 | 5 | - require it via composer 6 | ``` 7 | composer require 'webanyone/mautic-ecommerce-bundle:*' 8 | ``` 9 | 10 | ## Configuration 11 | 12 | Open the plugin page, and you must saw 2 plugins, prestashop & woocommerce 13 | 14 | ### Prestashop 15 | 16 | Enabled 17 | - url (must end with /api) 18 | - token (readonly for now) 19 | Feature 20 | - check everything 21 | Field mapping 22 | - choose each field (not sure if we need this) 23 | 24 | TODO: How to create a token in prestashop ? 25 | 26 | ### WooCommerce 27 | 28 | Enabled 29 | - url (must end with /wp-json/wc/v3) 30 | - consumer key 31 | - consumer secret 32 | Feature 33 | - check everything 34 | Field mapping 35 | - choose each field (not sure if we need this) 36 | 37 | TODO: How to create a token in woocommerce ? 38 | 39 | ## Sync 40 | 41 | Customer & Product of ecommerce solution are sync using sync engine of Mautic, to retrieve theme add the following cron to your server 42 | 43 | ``` 44 | bin/console mautic:integrations:sync -f -vvv -- WooCommerce 45 | # or 46 | bin/console mautic:integrations:sync -f -vvv -- Prestashop 47 | ``` 48 | 49 | Transaction are sync using a different command which must run after 50 | 51 | ``` 52 | bin/console ecommerce:transaction:import WooCommerce 53 | # or 54 | bin/console ecommerce:transaction:import Prestashop 55 | ``` 56 | 57 | ## Segments 58 | 59 | TODO: list & explain each of the filter choice provided 60 | 61 | ## Emails 62 | 63 | You have access to information about the last transaction made by a lead inside the mails: 64 | 65 | ``` 66 | {last_transaction} 67 |
    68 |
  • {transaction:date}
  • 69 |
  • {transaction:price}
  • 70 |
  • {transaction:nb_products}
  • 71 |
  • 72 | {transaction_products} 73 |
      74 |
    • {product:name}
    • 75 |
    • {product:unit_price}
    • 76 |
    • {product:quantity}
    • 77 |
    78 | {/transaction_products} 79 |
  • 80 |
81 | {/last_transaction} 82 | ``` 83 | 84 | ### The following tags can be used in the {last_transaction} block: 85 | 86 | - `{transaction:date}` 87 | Returns: the date the transaction was made. 88 | Optional param: format {transaction:date format="d-m-Y H:i"} 89 | - `{transaction:price}` 90 | Returns: the total price, including taxes 91 | - `{transaction:nb_products}` 92 | Returns: how many different product is present inside the transaction 93 | 94 | ### The following tags can be used in the {transaction_products} block: 95 | 96 | #### Merge tags 97 | 98 | - `{product:name}` 99 | Returns: the name of the product 100 | - `{product:unit_price}` 101 | Returns: the total price, including taxes 102 | - `{product:quantity}` 103 | Returns: how many item of this product is present inside the transaction 104 | -------------------------------------------------------------------------------- /Segment/Query/Filter/PurchaseProductFilterQueryBuilder.php: -------------------------------------------------------------------------------- 1 | getTableAlias($tablePrefix . 'leads'); 18 | $filterOperator = $filter->getOperator(); 19 | 20 | $subQuery = "SELECT lead_id 21 | FROM {$tablePrefix}ecommerce_transaction ppf_transaction 22 | INNER JOIN {$tablePrefix}ecommerce_transaction_product as ppf_transaction_product 23 | ON ppf_transaction.id = ppf_transaction_product.transaction_id 24 | AND ppf_transaction_product.product_id = :productId"; 25 | 26 | $queryBuilder 27 | ->andWhere("$leadsTableAlias.id IN ($subQuery)") 28 | ->setParameter('productId', $filter->getParameterValue()) 29 | ; 30 | 31 | switch ($filterOperator) { 32 | case 'eq': 33 | $queryBuilder 34 | ->andWhere("$leadsTableAlias.id IN ($subQuery)") 35 | ->setParameter('productId', $filter->getParameterValue()) 36 | ; 37 | break; 38 | case 'neq': 39 | $queryBuilder 40 | ->andWhere("$leadsTableAlias.id NOT IN ($subQuery)") 41 | ->setParameter('productId', $filter->getParameterValue()) 42 | ; 43 | break; 44 | } 45 | 46 | return $queryBuilder; 47 | } 48 | 49 | public static function getServiceId(): string 50 | { 51 | return 'mautic_ecommerce.lead.query_builder.purchase_product'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Sync/Config.php: -------------------------------------------------------------------------------- 1 | integration = $integration; 20 | } 21 | 22 | /** 23 | * @throws InvalidValueException 24 | */ 25 | public function getFieldDirection(string $objectName, string $alias): string 26 | { 27 | if (isset($this->getMappedFieldsDirections($objectName)[$alias])) { 28 | return $this->getMappedFieldsDirections($objectName)[$alias]; 29 | } 30 | 31 | throw new InvalidValueException("There is no field direction for '{$objectName}' field '${alias}'."); 32 | } 33 | 34 | /** 35 | * Returns mapped fields that the user configured for this integration in the format of [field_alias => mautic_field_alias]. 36 | * 37 | * @return string[] 38 | */ 39 | public function getMappedFields(string $objectName): array 40 | { 41 | if (isset($this->mappedFields[$objectName])) { 42 | return $this->mappedFields[$objectName]; 43 | } 44 | 45 | $fieldMappings = $this->getFeatureSettings()['sync']['fieldMappings'][$objectName] ?? []; 46 | 47 | $this->mappedFields[$objectName] = []; 48 | foreach ($fieldMappings as $field => $fieldMapping) { 49 | $this->mappedFields[$objectName][$field] = $fieldMapping['mappedField']; 50 | } 51 | 52 | return $this->mappedFields[$objectName]; 53 | } 54 | 55 | /** 56 | * @return mixed[] 57 | */ 58 | public function getFeatureSettings(): array 59 | { 60 | return $this->integration->getIntegrationConfiguration()->getFeatureSettings() ?: []; 61 | } 62 | 63 | /** 64 | * Returns direction of what field to sync where in the format of [field_alias => direction]. 65 | * 66 | * @return string[] 67 | */ 68 | private function getMappedFieldsDirections(string $objectName): array 69 | { 70 | if (isset($this->fieldDirections[$objectName])) { 71 | return $this->fieldDirections[$objectName]; 72 | } 73 | 74 | $fieldMappings = $this->getFeatureSettings()['sync']['fieldMappings'][$objectName] ?? []; 75 | 76 | $this->fieldDirections[$objectName] = []; 77 | foreach ($fieldMappings as $field => $fieldMapping) { 78 | $this->fieldDirections[$objectName][$field] = $fieldMapping['syncDirection']; 79 | } 80 | 81 | return $this->fieldDirections[$objectName]; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Sync/DataExchange/Internal/Product.php: -------------------------------------------------------------------------------- 1 | 'Name', 29 | 'unitPrice' => 'Unit Price', 30 | 'createdAt' => 'Created At', 31 | 'updatedAt' => 'Updated At', 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Sync/DataExchange/Internal/ProductObjectHelper.php: -------------------------------------------------------------------------------- 1 | productRepository = $productRepository; 24 | $this->propertyAccessor = PropertyAccess::createPropertyAccessor(); 25 | } 26 | 27 | /** 28 | * @param ObjectChangeDAO[] $objects 29 | * 30 | * @return ObjectMapping[] 31 | */ 32 | public function create(array $objects): array 33 | { 34 | $objectMappings = []; 35 | 36 | foreach ($objects as $object) { 37 | $product = new ProductEntity(); 38 | 39 | foreach ($object->getFields() as $field) { 40 | if (!$this->propertyAccessor->isWritable($product, $field->getName())) { 41 | continue; 42 | } 43 | 44 | $normalizedValue = $field->getValue()->getNormalizedValue(); 45 | if ($field->getValue()->getType() === 'datetime') { 46 | $normalizedValue = new \DateTimeImmutable($normalizedValue); 47 | } 48 | 49 | $this->propertyAccessor->setValue($product, $field->getName(), $normalizedValue); 50 | } 51 | 52 | $this->productRepository->saveEntity($product); 53 | $this->productRepository->detachEntity($product); 54 | 55 | $objectMapping = new ObjectMapping(); 56 | $objectMapping->setLastSyncDate($object->getChangeDateTime()) 57 | ->setIntegration($object->getIntegration()) 58 | ->setIntegrationObjectName($object->getMappedObject()) 59 | ->setIntegrationObjectId($object->getMappedObjectId()) 60 | ->setInternalObjectName(Product::NAME) 61 | ->setInternalObjectId($product->getId()); 62 | $objectMappings[] = $objectMapping; 63 | } 64 | 65 | return $objectMappings; 66 | } 67 | 68 | /** 69 | * @param ObjectChangeDAO[] $objects 70 | * 71 | * @return UpdatedObjectMappingDAO[] 72 | */ 73 | public function update(array $ids, array $objects): array 74 | { 75 | $updatedMappedObjects = []; 76 | 77 | /** @var ProductEntity[] $products */ 78 | $products = $this->productRepository->getEntities(['ids' => $ids]); 79 | 80 | foreach ($products as $product) { 81 | $changedObject = $objects[$product->getId()]; 82 | $fields = $changedObject->getFields(); 83 | 84 | foreach ($fields as $field) { 85 | if (!$this->propertyAccessor->isWritable($product, $field->getName())) { 86 | continue; 87 | } 88 | 89 | $normalizedValue = $field->getValue()->getNormalizedValue(); 90 | if ($field->getValue()->getType() === 'datetime') { 91 | $normalizedValue = new \DateTimeImmutable($normalizedValue); 92 | } 93 | 94 | $this->propertyAccessor->setValue($product, $field->getName(), $normalizedValue); 95 | } 96 | 97 | // Integration name and ID are stored in the change's mappedObject/mappedObjectId 98 | $updatedMappedObjects[] = new UpdatedObjectMappingDAO( 99 | $changedObject->getIntegration(), 100 | $changedObject->getMappedObject(), 101 | $changedObject->getMappedObjectId(), 102 | $changedObject->getChangeDateTime() 103 | ); 104 | } 105 | 106 | return $updatedMappedObjects; 107 | } 108 | 109 | public function findObjectsBetweenDates(\DateTimeInterface $from, \DateTimeInterface $to, $start, $limit): array 110 | { 111 | throw new \RuntimeException('Partial Syncing is not supported yet.'); 112 | } 113 | 114 | public function findObjectsByIds(array $ids): array 115 | { 116 | throw new \RuntimeException('Partial Syncing is not supported yet.'); 117 | } 118 | 119 | public function findObjectsByFieldValues(array $fields): array 120 | { 121 | throw new \RuntimeException('Partial Syncing is not supported yet.'); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Sync/DataExchange/ReportBuilder.php: -------------------------------------------------------------------------------- 1 | fieldRepository = $fieldRepository; 32 | 33 | // Value normalizer transforms value types expected by each side of the sync 34 | $this->valueNormalizer = new ValueNormalizer(); 35 | $this->integrationsHelper = $integrationsHelper; 36 | $this->propertyAccessor = PropertyAccess::createPropertyAccessor(); 37 | } 38 | 39 | public function build(int $page, array $requestedObjects, InputOptionsDAO $options): ReportDAO 40 | { 41 | /** @var EcommerceAbstractIntegration $integration */ 42 | $integration = $this->integrationsHelper->getIntegration($options->getIntegration()); 43 | 44 | $config = $integration->getConfig(); 45 | $client = $integration->getClient(); 46 | 47 | $report = new ReportDAO($options->getIntegration()); 48 | 49 | foreach ($requestedObjects as $requestedObject) { 50 | $objectName = $requestedObject->getObject(); 51 | // Fetch a list of changed objects from the integration's API 52 | 53 | switch ($objectName) { 54 | case MappingManualFactory::CUSTOMER_OBJECT: 55 | $modifiedItems = $client->getCustomers($page); 56 | break; 57 | case MappingManualFactory::PRODUCT_OBJECT: 58 | $modifiedItems = $client->getProducts($page); 59 | break; 60 | default: 61 | throw new \RuntimeException(sprintf('Unsupported objectName "%s"', $objectName)); 62 | } 63 | 64 | // Add the modified items to the report 65 | $this->addModifiedItems($report, $config, $objectName, $modifiedItems); 66 | } 67 | 68 | return $report; 69 | } 70 | 71 | /** 72 | * @param Customer[]|Product[] $changeList 73 | */ 74 | private function addModifiedItems(ReportDAO $report, Config $config, string $objectName, array $changeList): void 75 | { 76 | // Get the the field list to know what the field types are 77 | $fields = $this->fieldRepository->getFields($objectName); 78 | $mappedFields = $config->getMappedFields($objectName); 79 | $fieldsToSet = array_intersect(array_keys($mappedFields), array_keys($fields)); 80 | 81 | foreach ($changeList as $item) { 82 | $objectDAO = new ReportObjectDAO( 83 | $objectName, 84 | // Set the ID from the integration 85 | $item->id, 86 | // Set the date/time when the full object was last modified or created 87 | $item->updatedAt 88 | ); 89 | 90 | foreach ($fieldsToSet as $property) { 91 | /** @var Field $field */ 92 | $field = $fields[$property]; 93 | 94 | // The sync is currently from Integration to Mautic so normalize the values for storage in Mautic 95 | $value = $this->propertyAccessor->getValue($item, $property); 96 | 97 | $normalizedValue = $this->valueNormalizer->normalizeForMautic( 98 | $value, 99 | $field->getDataType() 100 | ); 101 | 102 | // If the integration supports field level tracking with timestamps, update FieldDAO::setChangeDateTime as well 103 | // Note that the field name here is the integration's 104 | $objectDAO->addField(new FieldDAO($property, $normalizedValue)); 105 | } 106 | 107 | // Add the modified/new item to the report 108 | $report->addObject($objectDAO); 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /Sync/DataExchange/SyncDataExchange.php: -------------------------------------------------------------------------------- 1 | reportBuilder = $reportBuilder; 22 | } 23 | 24 | public function getSyncReport(RequestDAO $requestDAO): ReportDAO 25 | { 26 | return $this->reportBuilder->build( 27 | $requestDAO->getSyncIteration(), 28 | $requestDAO->getObjects(), 29 | $requestDAO->getInputOptionsDAO() 30 | ); 31 | } 32 | 33 | public function executeSyncOrder(OrderDAO $syncOrderDAO): void 34 | { 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Sync/DataExchange/ValueNormalizer.php: -------------------------------------------------------------------------------- 1 | getType()) { 18 | case NormalizedValueDAO::BOOLEAN_TYPE: 19 | // Integration requires actual boolean 20 | return (bool) $value->getNormalizedValue(); 21 | default: 22 | return $value->getNormalizedValue(); 23 | } 24 | } 25 | 26 | /** 27 | * @param mixed $value 28 | * @param string $type 29 | */ 30 | public function normalizeForMautic($value, $type): NormalizedValueDAO 31 | { 32 | switch ($type) { 33 | case self::BOOLEAN_TYPE: 34 | // Mautic requires 1 or 0 for booleans 35 | return new NormalizedValueDAO(NormalizedValueDAO::BOOLEAN_TYPE, $value, (int) $value); 36 | case self::DATETIME_TYPE: 37 | return new NormalizedValueDAO(NormalizedValueDAO::DATETIME_TYPE, $value, $value->format('Y-m-d H:i:s')); 38 | default: 39 | return new NormalizedValueDAO(NormalizedValueDAO::TEXT_TYPE, $value, (string) $value); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Sync/Mapping/Field/Field.php: -------------------------------------------------------------------------------- 1 | name = $field['name'] ?? ''; 20 | $this->label = $field['label'] ?? ''; 21 | $this->dataType = $field['data_type'] ?? 'text'; 22 | $this->isRequired = (bool) ($field['required'] ?? false); 23 | $this->isWritable = (bool) ($field['writable'] ?? true); 24 | } 25 | 26 | public function getName(): string 27 | { 28 | return $this->name; 29 | } 30 | 31 | public function getLabel(): string 32 | { 33 | return $this->label; 34 | } 35 | 36 | public function getDataType(): string 37 | { 38 | return $this->dataType; 39 | } 40 | 41 | public function isRequired(): bool 42 | { 43 | return $this->isRequired; 44 | } 45 | 46 | public function isWritable(): bool 47 | { 48 | return $this->isWritable; 49 | } 50 | 51 | public function getSupportedSyncDirection(): string 52 | { 53 | return $this->isWritable ? ObjectMappingDAO::SYNC_BIDIRECTIONALLY : ObjectMappingDAO::SYNC_TO_MAUTIC; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Sync/Mapping/Field/FieldRepository.php: -------------------------------------------------------------------------------- 1 | [ 15 | [ 16 | 'name' => 'id', 17 | 'label' => 'ID', 18 | 'data_type' => NormalizedValueDAO::STRING_TYPE, 19 | 'required' => true, 20 | 'writable' => false, 21 | ], 22 | [ 23 | 'name' => 'lastName', 24 | 'label' => 'Last Name', 25 | 'data_type' => NormalizedValueDAO::STRING_TYPE, 26 | 'required' => true, 27 | 'writable' => false, 28 | ], 29 | [ 30 | 'name' => 'firstName', 31 | 'label' => 'First Name', 32 | 'data_type' => NormalizedValueDAO::STRING_TYPE, 33 | 'required' => true, 34 | 'writable' => false, 35 | ], 36 | [ 37 | 'name' => 'email', 38 | 'label' => 'Email', 39 | 'data_type' => NormalizedValueDAO::STRING_TYPE, 40 | 'required' => true, 41 | 'writable' => false, 42 | ], 43 | [ 44 | 'name' => 'createdAt', 45 | 'label' => 'Date add', 46 | 'data_type' => NormalizedValueDAO::DATETIME_TYPE, 47 | 'required' => true, 48 | 'writable' => false, 49 | ], 50 | [ 51 | 'name' => 'updatedAt', 52 | 'label' => 'Date update', 53 | 'data_type' => NormalizedValueDAO::DATETIME_TYPE, 54 | 'required' => true, 55 | 'writable' => false, 56 | ], 57 | ], 58 | MappingManualFactory::PRODUCT_OBJECT => [ 59 | [ 60 | 'name' => 'id', 61 | 'label' => 'ID', 62 | 'data_type' => NormalizedValueDAO::STRING_TYPE, 63 | 'required' => true, 64 | 'writable' => false, 65 | ], 66 | [ 67 | 'name' => 'name', 68 | 'label' => 'Name', 69 | 'data_type' => NormalizedValueDAO::STRING_TYPE, 70 | 'required' => true, 71 | 'writable' => false, 72 | ], 73 | [ 74 | 'name' => 'unitPrice', 75 | 'label' => 'Unit Price', 76 | 'data_type' => NormalizedValueDAO::INT_TYPE, 77 | 'required' => true, 78 | 'writable' => false, 79 | ], 80 | [ 81 | 'name' => 'createdAt', 82 | 'label' => 'Date add', 83 | 'data_type' => NormalizedValueDAO::DATETIME_TYPE, 84 | 'required' => true, 85 | 'writable' => false, 86 | ], 87 | [ 88 | 'name' => 'updatedAt', 89 | 'label' => 'Date update', 90 | 'data_type' => NormalizedValueDAO::DATETIME_TYPE, 91 | 'required' => true, 92 | 'writable' => false, 93 | ], 94 | ], 95 | ]; 96 | 97 | private CacheStorageHelper $cacheProvider; 98 | private array $apiFields = []; 99 | 100 | public function __construct(CacheStorageHelper $cacheProvider) 101 | { 102 | $this->cacheProvider = $cacheProvider; 103 | } 104 | 105 | /** 106 | * Used by the sync engine so that it does not have to fetch the fields live with each object sync. 107 | * 108 | * @return Field[] 109 | */ 110 | public function getFields(string $objectName): array 111 | { 112 | $cacheKey = $this->getCacheKey($objectName); 113 | $fields = $this->cacheProvider->get($cacheKey); 114 | 115 | if (!$fields) { 116 | // Fields are empty or not found so refresh from the API 117 | $fields = $this->getFieldsFromApi($objectName); 118 | } 119 | 120 | return $this->hydrateFieldObjects($fields); 121 | } 122 | 123 | /** 124 | * @return MappedFieldInfo[] 125 | */ 126 | public function getRequiredFieldsForMapping(string $objectName): array 127 | { 128 | $fields = $this->getFieldsFromApi($objectName); 129 | $fieldObjects = $this->hydrateFieldObjects($fields); 130 | 131 | $requiredFields = []; 132 | foreach ($fieldObjects as $field) { 133 | if (!$field->isRequired()) { 134 | continue; 135 | } 136 | 137 | // Fields must have the name as the key 138 | $requiredFields[$field->getName()] = new MappedFieldInfo($field); 139 | } 140 | 141 | return $requiredFields; 142 | } 143 | 144 | /** 145 | * @return MappedFieldInfo[] 146 | */ 147 | public function getOptionalFieldsForMapping(string $objectName): array 148 | { 149 | $fields = $this->getFieldsFromApi($objectName); 150 | $fieldObjects = $this->hydrateFieldObjects($fields); 151 | 152 | $optionalFields = []; 153 | foreach ($fieldObjects as $field) { 154 | if ($field->isRequired()) { 155 | continue; 156 | } 157 | 158 | // Fields must have the name as the key 159 | $optionalFields[$field->getName()] = new MappedFieldInfo($field); 160 | } 161 | 162 | return $optionalFields; 163 | } 164 | 165 | /** 166 | * Used by the config form to fetch the fields fresh from the API. 167 | */ 168 | private function getFieldsFromApi(string $objectName): array 169 | { 170 | if (isset($this->apiFields[$objectName])) { 171 | return $this->apiFields[$objectName]; 172 | } 173 | 174 | // todo retrieve a list of fields for a given objectName 175 | // [{name, label, data_type, required, writable}] 176 | 177 | $fields = self::$fields[$objectName]; 178 | 179 | // Refresh the cache with the fields just fetched 180 | $cacheKey = $this->getCacheKey($objectName); 181 | $this->cacheProvider->set($cacheKey, $fields); 182 | 183 | $this->apiFields[$objectName] = $fields; 184 | 185 | return $this->apiFields[$objectName]; 186 | } 187 | 188 | private function getCacheKey(string $objectName): string 189 | { 190 | return sprintf('helloworld.fields.%s', $objectName); 191 | } 192 | 193 | /** 194 | * @return Field[] 195 | */ 196 | private function hydrateFieldObjects(array $fields): array 197 | { 198 | $fieldObjects = []; 199 | foreach ($fields as $field) { 200 | $fieldObjects[$field['name']] = new Field($field); 201 | } 202 | 203 | return $fieldObjects; 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /Sync/Mapping/Field/MappedFieldInfo.php: -------------------------------------------------------------------------------- 1 | field = $field; 16 | } 17 | 18 | public function getName(): string 19 | { 20 | return $this->field->getName(); 21 | } 22 | 23 | public function getLabel(): string 24 | { 25 | return $this->field->getLabel(); 26 | } 27 | 28 | public function showAsRequired(): bool 29 | { 30 | return $this->field->isRequired(); 31 | } 32 | 33 | public function hasTooltip(): bool 34 | { 35 | return false; 36 | } 37 | 38 | public function getTooltip(): string 39 | { 40 | return ''; 41 | } 42 | 43 | public function isBidirectionalSyncEnabled(): bool 44 | { 45 | return $this->field->isWritable(); 46 | } 47 | 48 | public function isToIntegrationSyncEnabled(): bool 49 | { 50 | return $this->field->isWritable(); 51 | } 52 | 53 | public function isToMauticSyncEnabled(): bool 54 | { 55 | return true; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Sync/Mapping/Manual/MappingManualFactory.php: -------------------------------------------------------------------------------- 1 | fieldRepository = $fieldRepository; 29 | $this->integrationsHelper = $integrationsHelper; 30 | } 31 | 32 | public function getManual(string $integrationName): MappingManualDAO 33 | { 34 | if ($this->manual !== null) { 35 | return $this->manual; 36 | } 37 | 38 | $this->manual = new MappingManualDAO($integrationName); 39 | 40 | $this->configureObjectMapping($integrationName, self::CUSTOMER_OBJECT); 41 | $this->configureObjectMapping($integrationName, self::PRODUCT_OBJECT); 42 | 43 | return $this->manual; 44 | } 45 | 46 | private function configureObjectMapping(string $integrationName, string $objectName): void 47 | { 48 | /** @var EcommerceAbstractIntegration $integration */ 49 | $integration = $this->integrationsHelper->getIntegration($integrationName); 50 | 51 | // Get a list of available fields from the integration 52 | $fields = $this->fieldRepository->getFields($objectName); 53 | 54 | // Get a list of fields mapped by the user 55 | $config = $integration->getConfig(); 56 | $mappedFields = $config->getMappedFields($objectName); 57 | 58 | // Generate an object mapping DAO for the given object. The object must be mapped to a supported Mautic object (i.e. contact or company) 59 | $objectMappingDAO = new ObjectMappingDAO($this->getMauticObjectName($objectName), $objectName); 60 | 61 | foreach ($mappedFields as $fieldAlias => $mauticFieldAlias) { 62 | if (!isset($fields[$fieldAlias])) { 63 | // The mapped field is no longer available 64 | continue; 65 | } 66 | 67 | /** @var Field $field */ 68 | $field = $fields[$fieldAlias]; 69 | 70 | // Configure how fields should be handled by the sync engine as determined by the user's configuration. 71 | $objectMappingDAO->addFieldMapping( 72 | $mauticFieldAlias, 73 | $fieldAlias, 74 | $config->getFieldDirection($objectName, $fieldAlias), 75 | $field->isRequired() 76 | ); 77 | 78 | $this->manual->addObjectMapping($objectMappingDAO); 79 | } 80 | } 81 | 82 | /** 83 | * @throws InvalidValueException 84 | */ 85 | private function getMauticObjectName(string $objectName): string 86 | { 87 | switch ($objectName) { 88 | case self::CUSTOMER_OBJECT: 89 | return Contact::NAME; 90 | case self::PRODUCT_OBJECT: 91 | return Product::NAME; 92 | } 93 | 94 | throw new InvalidValueException("$objectName could not be mapped to a Mautic object"); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Templating/Helper/MoneyHelper.php: -------------------------------------------------------------------------------- 1 | formatCurrency($value / 100, $currency); 17 | } 18 | 19 | public function getName() 20 | { 21 | return 'ecommerce_money'; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Tests/Email/Helper/ParamsHelperTest.php: -------------------------------------------------------------------------------- 1 | ['', []]; 24 | yield 'one param' => ['foo="bar"', ['foo' => 'bar']]; 25 | yield 'more params' => ['foo="bar" bar="baz"', ['foo' => 'bar', 'bar' => 'baz']]; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Tests/Email/ParserTest.php: -------------------------------------------------------------------------------- 1 | prophesize(Lead::class); 24 | 25 | $repository = $this->prophesize(TransactionRepository::class); 26 | $repository->findLatest($lead->reveal())->willReturn($transaction); 27 | 28 | $parser = new Parser($repository->reveal()); 29 | $result = $parser->parse($content, $lead->reveal()); 30 | 31 | self::assertEquals($expectedContent, $result); 32 | } 33 | 34 | public function provideTestParse(): iterable 35 | { 36 | $lead = $this->prophesize(Lead::class); 37 | $transaction = new Transaction($lead->reveal(), 1, new \DateTimeImmutable(), 3200, 3200, 2); 38 | 39 | yield 'empty' => [$transaction, '', '']; 40 | yield 'no transaction found' => [null, '{last_transaction}test{/last_transaction}', '']; 41 | yield 'valid' => [$transaction, '{last_transaction}test{/last_transaction}', 'test']; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Tests/Email/Tag/TransactionProductTagTest.php: -------------------------------------------------------------------------------- 1 | getValue()); 23 | } 24 | 25 | public function provideTestGetValue(): iterable 26 | { 27 | $product = new Product(); 28 | $product->setName('Product name'); 29 | $product->setUnitPrice(1000); 30 | 31 | $transaction = $this->prophesize(Transaction::class); 32 | $transactionProduct = new TransactionProduct($transaction->reveal(), $product, 2); 33 | 34 | yield 'name' => [$transactionProduct, 'name', [], 'Product name']; 35 | yield 'quantity' => [$transactionProduct, 'quantity', [], '2']; 36 | yield 'unit price' => [$transactionProduct, 'unit_price', [], '10']; 37 | yield 'unknown field' => [$transactionProduct, 'unknown', [], 'Unknown (unknown)']; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Tests/Email/Tag/TransactionTagTest.php: -------------------------------------------------------------------------------- 1 | getValue()); 22 | } 23 | 24 | public function provideTestGetValue(): iterable 25 | { 26 | $lead = $this->prophesize(Lead::class); 27 | 28 | $transaction = new Transaction( 29 | $lead->reveal(), 30 | 1, 31 | new \DateTimeImmutable('2022-01-01T20:13:58.000Z'), 32 | 1000, 33 | 1200, 34 | 2 35 | ); 36 | 37 | yield 'price' => [$transaction, 'price', [], '12']; 38 | yield 'nb_products' => [$transaction, 'nb_products', [], '2']; 39 | yield 'date without format' => [$transaction, 'date', [], '01/01/2022 20:13:58']; 40 | yield 'date with format' => [$transaction, 'date', ['format' => 'Y-m-d'], '2022-01-01']; 41 | yield 'unknown field' => [$transaction, 'unknown', [], 'Unknown (unknown)']; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Tests/Email/TransactionParserTest.php: -------------------------------------------------------------------------------- 1 | prophesize(Lead::class); 23 | $transaction = new Transaction($lead->reveal(), 1, new \DateTimeImmutable('2022-06-28'), 3200, 3200, 2); 24 | $parser = new TransactionParser(); 25 | $result = $parser->parse($content, $transaction); 26 | 27 | self::assertEquals($expecterdOutput, $result); 28 | } 29 | 30 | public function provideTestParse(): iterable 31 | { 32 | yield 'empty' => ['', '']; 33 | yield 'no transaction tags' => ['test', 'test']; 34 | yield 'unknow transaction tag' => ['{transaction:test}', 'Unknown (test)']; 35 | yield '1 transaction tag' => ['{transaction:date format="Y-m-d"}', '2022-06-28']; 36 | yield 'multiple transaction tags' => ['{transaction:date format="Y-m-d"} / {transaction:price}', '2022-06-28 / 32']; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Tests/Email/TransactionProductsParserTest.php: -------------------------------------------------------------------------------- 1 | parse($content, $transaction); 26 | 27 | self::assertEquals($expectedContent, $result); 28 | } 29 | 30 | public function provideTestParse(): iterable 31 | { 32 | $productA = new Product(); 33 | $productA->setName('Product A'); 34 | $productA->setUnitPrice(1200); 35 | 36 | \Closure::bind(function () use ($productA) { 37 | $productA->id = 1; 38 | }, $productA, Product::class)(); 39 | 40 | $productB = new Product(); 41 | $productB->setName('Product B'); 42 | $productB->setUnitPrice(1000); 43 | 44 | \Closure::bind(function () use ($productB) { 45 | $productB->id = 2; 46 | }, $productB, Product::class)(); 47 | 48 | $lead = $this->prophesize(Lead::class); 49 | $transaction = new Transaction($lead->reveal(), 1, new \DateTimeImmutable(), 0, 0, 0); 50 | 51 | yield 'empty' => [$transaction, '', '']; 52 | yield 'no products' => [ 53 | $transaction, 54 | <<{transaction_products}
  • {product:name} / {product:unitPrice} / {product:quantity}
  • {/transaction_products} 56 | HTML, 57 | << 59 | HTML, 60 | ]; 61 | 62 | $transaction = new Transaction($lead->reveal(), 1, new \DateTimeImmutable(), 3200, 3200, 2); 63 | $transaction->addProduct($productA, 2); 64 | $transaction->addProduct($productB, 1); 65 | 66 | yield 'valid' => [ 67 | $transaction, 68 | << 70 | {transaction_products} 71 |
  • {product:name} / {product:unit_price} / {product:quantity}
  • 72 | {/transaction_products} 73 | 74 | HTML, 75 | << 77 | 78 |
  • Product A / 12 / 2
  • 79 | 80 |
  • Product B / 10 / 1
  • 81 | 82 | 83 | HTML, 84 | ]; 85 | yield 'no product tags' => [ 86 | $transaction, 87 | << 89 | {transaction_products}
  • A
  • {/transaction_products} 90 | 91 | HTML, 92 | << 94 |
  • A
  • A
  • 95 | 96 | HTML, 97 | ]; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Translations/en_US/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "English - United States", 3 | "locale": "en_US", 4 | "author": "Mautic Team" 5 | } -------------------------------------------------------------------------------- /Translations/en_US/messages.ini: -------------------------------------------------------------------------------- 1 | mautic_ecommerce.email.token.transaction.price="TTC Price of the transaction" 2 | mautic_ecommerce.email.token.transaction.nb_products="Nb Products of the transaction" 3 | mautic_ecommerce.email.token.transaction.date="Transaction Date" 4 | mautic_ecommerce.email.token.product.name="Product Name" 5 | mautic_ecommerce.email.token.product.quantity="Product Quantity" 6 | mautic_ecommerce.email.token.product.unit_price="Product Unit Price" 7 | mautic_ecommerce.menu.transactions=Transactions 8 | mautic_ecommerce.transaction.table.lead=Contact 9 | mautic_ecommerce.transaction.table.status=Status 10 | mautic_ecommerce.transaction.table.date=Date 11 | mautic_ecommerce.transaction.table.nbProducts=Nb Products 12 | mautic_ecommerce.transaction.table.priceWithoutTaxes=Price wo Taxes 13 | mautic_ecommerce.transaction.table.priceWithTaxes=Price with Taxes 14 | mautic_ecommerce.transaction.title=Transactions 15 | -------------------------------------------------------------------------------- /Views/Contact/tab.html.php: -------------------------------------------------------------------------------- 1 |
  • 2 | 3 | 4 | Transactions 5 | 6 |
  • 7 | -------------------------------------------------------------------------------- /Views/Contact/tabContent.html.php: -------------------------------------------------------------------------------- 1 |
    2 | render('MauticEcommerceBundle:Transaction:list.html.php', [ 4 | 'items' => $items, 5 | 'totalItems' => $totalItems, 6 | 'lead' => $lead, 7 | 'tmpl' => 'index', 8 | 'page' => 1, 9 | 'limit' => $limit, 10 | ]); 11 | ?> 12 |
    13 | -------------------------------------------------------------------------------- /Views/Transaction/index.html.php: -------------------------------------------------------------------------------- 1 | extend('MauticCoreBundle:Default:content.html.php'); 4 | $view['slots']->set('mauticContent', 'ecommerceTransaction'); 5 | $view['slots']->set('headerTitle', $view['translator']->trans('mautic_ecommerce.transaction.title')); 6 | 7 | ?> 8 | 9 |
    10 | render( 11 | 'MauticCoreBundle:Helper:list_toolbar.html.php', 12 | [ 13 | 'searchHelp' => 'mautic.core.help.searchcommands', 14 | 'action' => '', 15 | ] 16 | ); ?> 17 |
    18 | output('_content'); ?> 19 |
    20 |
    21 | -------------------------------------------------------------------------------- /Views/Transaction/list.html.php: -------------------------------------------------------------------------------- 1 | extend('MauticEcommerceBundle:Transaction:index.html.php'); 4 | } 5 | ?> 6 | 7 | 8 |
    9 | 10 | 11 | 12 | render( 14 | 'MauticCoreBundle:Helper:tableheader.html.php', 15 | [ 16 | 'sessionVar' => 'ecommerceTransaction', 17 | 'text' => 'mautic_ecommerce.transaction.table.lead', 18 | 'class' => 'col-ecommerce-transaction-lead', 19 | 'orderBy' => 'lead.name', 20 | ] 21 | ); 22 | echo $view->render( 23 | 'MauticCoreBundle:Helper:tableheader.html.php', 24 | [ 25 | 'sessionVar' => 'ecommerceTransaction', 26 | 'text' => 'mautic_ecommerce.transaction.table.status', 27 | 'class' => 'col-ecommerce-transaction-status', 28 | 'orderBy' => 't.status', 29 | ] 30 | ); 31 | echo $view->render( 32 | 'MauticCoreBundle:Helper:tableheader.html.php', 33 | [ 34 | 'sessionVar' => 'ecommerceTransaction', 35 | 'text' => 'mautic_ecommerce.transaction.table.date', 36 | 'class' => 'col-ecommerce-transaction-date', 37 | 'orderBy' => 't.date', 38 | ] 39 | ); 40 | echo $view->render( 41 | 'MauticCoreBundle:Helper:tableheader.html.php', 42 | [ 43 | 'sessionVar' => 'ecommerceTransaction', 44 | 'text' => 'mautic_ecommerce.transaction.table.nbProducts', 45 | 'class' => 'col-ecommerce-transaction-nb-products', 46 | 'orderBy' => 't.status', 47 | ] 48 | ); 49 | echo $view->render( 50 | 'MauticCoreBundle:Helper:tableheader.html.php', 51 | [ 52 | 'sessionVar' => 'ecommerceTransaction', 53 | 'text' => 'mautic_ecommerce.transaction.table.priceWithoutTaxes', 54 | 'class' => 'col-ecommerce-transaction-price-without-taxes', 55 | 'orderBy' => 't.status', 56 | ] 57 | ); 58 | echo $view->render( 59 | 'MauticCoreBundle:Helper:tableheader.html.php', 60 | [ 61 | 'sessionVar' => 'ecommerceTransaction', 62 | 'text' => 'mautic_ecommerce.transaction.table.priceWithTaxes', 63 | 'class' => 'col-ecommerce-transaction-price-with-taxes', 64 | 'orderBy' => 't.status', 65 | ] 66 | ); 67 | ?> 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
    getLead()->getName(); ?>toShort($item->getDate()); ?>getNbProducts(); ?>format($item->getPriceWithoutTaxes()); ?>format($item->getPriceWithTaxes()); ?>
    83 |
    84 | 97 | 98 | render('MauticCoreBundle:Helper:noresults.html.php'); ?> 99 | 100 | -------------------------------------------------------------------------------- /WooCommerce/Api/Client.php: -------------------------------------------------------------------------------- 1 | $consumerKey, 37 | 'consumer_secret' => $consumerSecret, 38 | ]); 39 | 40 | $stack->push($middleware); 41 | 42 | $this->httpClient = new \GuzzleHttp\Client([ 43 | 'base_uri' => $uri, 44 | 'handler' => $stack, 45 | 'auth' => 'oauth', 46 | ]); 47 | 48 | $this->serializer = new Serializer( 49 | [ 50 | new ArrayDenormalizer(), 51 | new DateTimeNormalizer(), 52 | new CustomerNormalizer(), 53 | new OrderNormalizer(), 54 | new ProductNormalizer(), 55 | new OrderProductNormalizer(), 56 | ], 57 | [new JsonEncoder()] 58 | ); 59 | } 60 | 61 | public function getCustomers(int $page, int $limit = 100): array 62 | { 63 | $response = $this->httpClient->get('customers', ['query' => [ 64 | 'page' => $page, 65 | 'per_page' => $limit, 66 | 'orderby' => 'id', 67 | ]]); 68 | 69 | return $this->serializer->deserialize( 70 | $response->getBody()->getContents(), 71 | Customer::class . '[]', 72 | JsonEncoder::FORMAT, 73 | ['integration' => WooCommerceIntegration::NAME] 74 | ); 75 | } 76 | 77 | public function getOrders(int $page, int $limit = 100): array 78 | { 79 | $response = $this->httpClient->get('orders', ['query' => [ 80 | 'page' => $page, 81 | 'per_page' => $limit, 82 | 'orderby' => 'id', 83 | ]]); 84 | 85 | return $this->serializer->deserialize( 86 | $response->getBody()->getContents(), 87 | Order::class . '[]', 88 | JsonEncoder::FORMAT, 89 | ['integration' => WooCommerceIntegration::NAME] 90 | ); 91 | } 92 | 93 | public function getProducts(int $page, int $limit = 100): array 94 | { 95 | $response = $this->httpClient->get('products', ['query' => [ 96 | 'page' => $page, 97 | 'per_page' => $limit, 98 | 'orderby' => 'id', 99 | ]]); 100 | 101 | return $this->serializer->deserialize( 102 | $response->getBody()->getContents(), 103 | Product::class . '[]', 104 | JsonEncoder::FORMAT, 105 | ['integration' => WooCommerceIntegration::NAME] 106 | ); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /WooCommerce/Form/Type/ConfigFormType.php: -------------------------------------------------------------------------------- 1 | add('url', UrlType::class, ['attr' => ['class' => 'form-control']]) 19 | ->add('consumerKey', TextType::class, ['attr' => ['class' => 'form-control']]) 20 | ->add('consumerSecret', TextType::class, ['attr' => ['class' => 'form-control']]) 21 | ; 22 | } 23 | 24 | public function configureOptions(OptionsResolver $resolver): void 25 | { 26 | $resolver->setDefaults( 27 | [ 28 | 'integration' => null, 29 | ] 30 | ); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /WooCommerce/Normalizer/CustomerNormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizeDate($data['date_created_gmt']), 25 | $this->denormalizeDate($data['date_modified_gmt']) 26 | ); 27 | } 28 | 29 | public function supportsDenormalization($data, string $type, string $format = null, array $context = []) 30 | { 31 | return $type === Customer::class && $context['integration'] === WooCommerceIntegration::NAME; 32 | } 33 | 34 | protected function denormalizeDate(string $date): \DateTimeImmutable 35 | { 36 | return $this->denormalizer->denormalize( 37 | $date, 38 | \DateTimeImmutable::class, 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /WooCommerce/Normalizer/OrderNormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizer->denormalize($data['date_created'], \DateTimeImmutable::class), 27 | $total - $taxes, 28 | $total, 29 | \count($data['line_items']), 30 | $this->denormalizer->denormalize($data['line_items'], OrderProduct::class . '[]'), 31 | ); 32 | } 33 | 34 | public function supportsDenormalization($data, string $type, string $format = null, array $context = []): bool 35 | { 36 | return $type === Order::class && $context['integration'] === WooCommerceIntegration::NAME; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /WooCommerce/Normalizer/OrderProductNormalizer.php: -------------------------------------------------------------------------------- 1 | denormalizeDate($data['date_created']), 24 | $this->denormalizeDate($data['date_modified']) 25 | ); 26 | } 27 | 28 | public function supportsDenormalization($data, string $type, string $format = null, array $context = []) 29 | { 30 | return $type === Product::class && $context['integration'] === WooCommerceIntegration::NAME; 31 | } 32 | 33 | protected function denormalizeDate(string $date): \DateTimeImmutable 34 | { 35 | return $this->denormalizer->denormalize($date, \DateTimeImmutable::class); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "webanyone/mautic-ecommerce-bundle", 3 | "description": "MauticEcommerceBundle", 4 | "license": "GPL-3.0", 5 | "type": "mautic-plugin", 6 | "keywords": [ 7 | "mautic", 8 | "plugin", 9 | "integration", 10 | "ecommerce" 11 | ], 12 | "extra": { 13 | "install-directory-name": "MauticEcommerceBundle", 14 | "branch-alias": { 15 | "dev-main": "0.0.x-dev" 16 | } 17 | }, 18 | "autoload-dev": { 19 | "psr-4": { 20 | "MauticPlugin\\MauticEcommerceBundle\\": "" 21 | } 22 | }, 23 | "minimum-stability": "dev", 24 | "require": { 25 | "php": ">=7.4.0 <8.1", 26 | "mautic/core-lib": "^4.0", 27 | "symfony/serializer": ">=4.4", 28 | "guzzlehttp/oauth-subscriber": "^0.6.0" 29 | }, 30 | "repositories": [ 31 | { 32 | "type": "git", 33 | "url": "https://github.com/dennisameling/FOSOAuthServerBundle.git" 34 | } 35 | ], 36 | "require-dev": { 37 | "friendsofphp/php-cs-fixer": "*", 38 | "phpunit/phpunit": "^9.5", 39 | "phpspec/prophecy-phpunit": "^2.0", 40 | "jangregor/phpstan-prophecy": "dev-master", 41 | "phpstan/extension-installer": "^1.2", 42 | "phpstan/phpstan-doctrine": "^1.3", 43 | "phpstan/phpstan": "^1.10" 44 | }, 45 | "config": { 46 | "allow-plugins": { 47 | "symfony/flex": true, 48 | "phpstan/extension-installer": true, 49 | "php-http/discovery": true 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /phpstan-baseline.neon: -------------------------------------------------------------------------------- 1 | parameters: 2 | ignoreErrors: 3 | - 4 | message: "#^Method MauticPlugin\\\\MauticEcommerceBundle\\\\Controller\\\\TransactionController\\:\\:getTransactionRepository\\(\\) should return MauticPlugin\\\\MauticEcommerceBundle\\\\Entity\\\\TransactionRepository but returns object\\.$#" 5 | count: 1 6 | path: Controller/TransactionController.php 7 | 8 | - 9 | message: "#^Method MauticPlugin\\\\MauticEcommerceBundle\\\\Entity\\\\TransactionRepository\\:\\:getAllTransactions\\(\\) has parameter \\$limit with no type specified\\.$#" 10 | count: 1 11 | path: Entity/TransactionRepository.php 12 | 13 | - 14 | message: "#^Method MauticPlugin\\\\MauticEcommerceBundle\\\\Entity\\\\TransactionRepository\\:\\:getAllTransactions\\(\\) has parameter \\$start with no type specified\\.$#" 15 | count: 1 16 | path: Entity/TransactionRepository.php 17 | 18 | - 19 | message: "#^Method MauticPlugin\\\\MauticEcommerceBundle\\\\Entity\\\\TransactionRepository\\:\\:getTransactions\\(\\) has parameter \\$limit with no type specified\\.$#" 20 | count: 1 21 | path: Entity/TransactionRepository.php 22 | 23 | - 24 | message: "#^Method MauticPlugin\\\\MauticEcommerceBundle\\\\Entity\\\\TransactionRepository\\:\\:getTransactions\\(\\) has parameter \\$page with no type specified\\.$#" 25 | count: 1 26 | path: Entity/TransactionRepository.php 27 | 28 | - 29 | message: "#^Parameter \\#1 \\$content of method MauticPlugin\\\\MauticEcommerceBundle\\\\Email\\\\Parser\\:\\:parse\\(\\) expects string, array given\\.$#" 30 | count: 1 31 | path: EventListener/EmailSubscriber.php 32 | 33 | - 34 | message: "#^Cannot cast array\\|bool\\|string to string\\.$#" 35 | count: 1 36 | path: Segment/Query/Filter/PurchaseProductFilterQueryBuilder.php 37 | 38 | - 39 | message: "#^Cannot call method addObjectMapping\\(\\) on Mautic\\\\IntegrationsBundle\\\\Sync\\\\DAO\\\\Mapping\\\\MappingManualDAO\\|null\\.$#" 40 | count: 1 41 | path: Sync/Mapping/Manual/MappingManualFactory.php 42 | 43 | - 44 | message: "#^Method MauticPlugin\\\\MauticEcommerceBundle\\\\Sync\\\\Mapping\\\\Manual\\\\MappingManualFactory\\:\\:getManual\\(\\) should return Mautic\\\\IntegrationsBundle\\\\Sync\\\\DAO\\\\Mapping\\\\MappingManualDAO but returns Mautic\\\\IntegrationsBundle\\\\Sync\\\\DAO\\\\Mapping\\\\MappingManualDAO\\|null\\.$#" 45 | count: 1 46 | path: Sync/Mapping/Manual/MappingManualFactory.php 47 | 48 | - 49 | message: "#^Method MauticPlugin\\\\MauticEcommerceBundle\\\\Templating\\\\Helper\\\\MoneyHelper\\:\\:format\\(\\) should return string but returns string\\|false\\.$#" 50 | count: 1 51 | path: Templating/Helper/MoneyHelper.php 52 | 53 | - 54 | message: "#^Variable \\$count might not be defined\\.$#" 55 | count: 1 56 | path: Views/Contact/tab.html.php 57 | 58 | - 59 | message: "#^Variable \\$items might not be defined\\.$#" 60 | count: 1 61 | path: Views/Contact/tabContent.html.php 62 | 63 | - 64 | message: "#^Variable \\$lead might not be defined\\.$#" 65 | count: 1 66 | path: Views/Contact/tabContent.html.php 67 | 68 | - 69 | message: "#^Variable \\$limit might not be defined\\.$#" 70 | count: 1 71 | path: Views/Contact/tabContent.html.php 72 | 73 | - 74 | message: "#^Variable \\$totalItems might not be defined\\.$#" 75 | count: 1 76 | path: Views/Contact/tabContent.html.php 77 | 78 | - 79 | message: "#^Variable \\$view might not be defined\\.$#" 80 | count: 1 81 | path: Views/Contact/tabContent.html.php 82 | 83 | - 84 | message: "#^Variable \\$view might not be defined\\.$#" 85 | count: 6 86 | path: Views/Transaction/index.html.php 87 | 88 | - 89 | message: "#^Variable \\$items might not be defined\\.$#" 90 | count: 2 91 | path: Views/Transaction/list.html.php 92 | 93 | - 94 | message: "#^Variable \\$limit might not be defined\\.$#" 95 | count: 1 96 | path: Views/Transaction/list.html.php 97 | 98 | - 99 | message: "#^Variable \\$page might not be defined\\.$#" 100 | count: 1 101 | path: Views/Transaction/list.html.php 102 | 103 | - 104 | message: "#^Variable \\$totalItems might not be defined\\.$#" 105 | count: 1 106 | path: Views/Transaction/list.html.php 107 | 108 | - 109 | message: "#^Variable \\$view might not be defined\\.$#" 110 | count: 13 111 | path: Views/Transaction/list.html.php 112 | -------------------------------------------------------------------------------- /phpstan.neon.dist: -------------------------------------------------------------------------------- 1 | includes: 2 | - phpstan-baseline.neon 3 | 4 | parameters: 5 | level: 8 6 | paths: 7 | - . 8 | excludePaths: 9 | - vendor/ 10 | ignoreErrors: 11 | - '#Constant MAUTIC_TABLE_PREFIX not found.#' 12 | checkMissingIterableValueType: false 13 | --------------------------------------------------------------------------------