Skip to content

Commit

Permalink
feat(matching): introduce product matching engine
Browse files Browse the repository at this point in the history
Uses part of the https://schema.org vocabulary.
Make use of the api platform schema generator to bootstrap entities.

> resolves #448
  • Loading branch information
lutangar authored and JalilArfaoui committed Sep 28, 2021
1 parent 03b4f84 commit 26777a3
Show file tree
Hide file tree
Showing 16 changed files with 695 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
"friendsofphp/php-cs-fixer": "^2.16",
"rector/rector": "^0.8.15",
"brainmaestro/composer-git-hooks": "^2.8",
"phpstan/phpstan": "^0.12.83"
"phpstan/phpstan": "^0.12.83",
"api-platform/schema-generator": "^2.2"
},
"conflict": {
"symfony/symfony": "*"
Expand Down
229 changes: 228 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions config/schema_generator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
id:
generate: true

namespaces:
entity: "App\\Entity"


# The list of types and properties we want to use
types:
Thing:
embeddable: false
properties:
name: ~
alternateName: ~
description: ~
Product:
parent: "Thing"
embeddable: false
properties:
# Force the type of the property to text
category:
range: "Text"
cardinality: "(0..1)"
offers:
range: "Offer"
embedded: true
columnPrefix: "offer_"
cardinality: "(0..1)"
Offer:
# Disable the generation of the class hierarchy for this type
parent: false
embeddable: true
properties:
# Force the type of the addressCountry property to text
availableAtOrFrom:
range: "Text"
cardinality: "(0..1)"
price:
range: "Number"
cardinality: "(0..1)"
16 changes: 16 additions & 0 deletions docs/schema_generator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Schema generator

Some entities were bootstrapped using the api-platform schema-generator:
https://api-platform.com/docs/schema-generator/

The generator uses the vocabulary formalized on [schema.org](https://schema.org).

## Configuration

[config/schema_generator.yaml](config/schema_generator.yaml)

## Generation

```shell
docker-compose exec php vendor/bin/schema generate src/ config/schema_generator.yaml
```
35 changes: 35 additions & 0 deletions migrations/Version20210922155023.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Application\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* On custom index and foreign key names:
* https://stackoverflow.com/questions/7623958/naming-a-relation-in-doctrine-2-orm.
*/
final class Version20210922155023 extends AbstractMigration
{
public function up(Schema $schema): void
{
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('CREATE TABLE product (id INT AUTO_INCREMENT NOT NULL, name LONGTEXT DEFAULT NULL, alternate_name LONGTEXT DEFAULT NULL, description LONGTEXT DEFAULT NULL, category LONGTEXT DEFAULT NULL, offer_available_at_or_from LONGTEXT DEFAULT NULL, offer_price DOUBLE PRECISION DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE matching_context ADD product_id INT DEFAULT NULL');
$this->addSql('ALTER TABLE matching_context ADD CONSTRAINT FK_matching_context_product_id FOREIGN KEY (product_id) REFERENCES product (id)');
$this->addSql('CREATE UNIQUE INDEX UNIQ_matching_context_product_id ON matching_context (product_id)');
}

public function down(Schema $schema): void
{
$this->abortIf('mysql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE matching_context DROP FOREIGN KEY FK_matching_context_product_id');
$this->addSql('DROP TABLE product');
$this->addSql('DROP INDEX UNIQ_matching_context_product_id ON matching_context');
$this->addSql('ALTER TABLE matching_context DROP product_id');
}
}
13 changes: 13 additions & 0 deletions public/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
border-radius: var(--border-radius);
}

.form-group .form-group .form-group > legend + .form-widget {
padding-left: 10px;
margin-bottom: 20px;
background-color: var(--fieldset-bg);
border: var(--border-width) var(--border-style) var(--gray-400);
border-radius: var(--border-radius);
}

.form-group legend.col-form-label {
font-weight: bold;
font-size: medium;
}

body.edit textarea#notice_message,
body.edit textarea#notice_note,
body.new textarea#notice_message,
Expand Down
Loading

0 comments on commit 26777a3

Please sign in to comment.