Skip to content

Commit

Permalink
Merge pull request #16 from Jelmer-Ketelaar/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
KawianW authored Nov 8, 2021
2 parents 35992a6 + ae3e8c8 commit f32b32c
Show file tree
Hide file tree
Showing 27 changed files with 928 additions and 457 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ APP_SECRET=86f8e46e16865da05c3cbe1137e8aa22
# IMPORTANT: You MUST configure your server version, either here or in config/packages/doctrine.yaml
#
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
DATABASE_URL="mysql://root:@127.0.0.1:3306/symfony"
DATABASE_URL="mysql://root:root@127.0.0.1:3306/symfony"
#DATABASE_URL="postgresql://db_user:[email protected]:3306/db_name?serverVersion=13&charset=utf8"
###< doctrine/doctrine-bundle ###

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1. composer install
2. bin/console doctrine:migrations:migrate
3. php -d memory_limit=-1 bin/console app:fill:products
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"doctrine/doctrine-migrations-bundle": "^3.1",
"doctrine/orm": "^2.10",
"doctrine/sql-formatter": "^1.1",
"guzzlehttp/guzzle": "^6.5",
"grandcruwijnen/sdk": "^0.1.26",
"guzzlehttp/guzzle": "^6.5",
"nelmio/cors-bundle": "^2.1",
"phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "^6.1",
Expand Down
256 changes: 128 additions & 128 deletions composer.lock

Large diffs are not rendered by default.

19 changes: 18 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Files in the packages/ subdirectory configure your dependencies.

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:

services:
Expand All @@ -20,6 +20,23 @@ services:
- '../src/Entity/'
- '../src/Kernel.php'
- '../src/Tests/'
- '../src/Migrations/'

# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller/'
tags: ['controller.service_arguments']

# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
Grandcruwijnen\:
autowire: true
resource: '../vendor/grandcruwijnen/sdk/src/Grandcruwijnen/*'

Grandcruwijnen\SDK\API:
arguments:
$username: '%env(MAGENTO2_USERNAME)%'
$password: '%env(MAGENTO2_PASSWORD)%'
$baseUri: 'https://beta.grandcruwijnen.dev/'
$userAgent: 'Grandcruwijnen.nl Funnel'
Binary file added public/image/sommelierIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/image/wijnoverzicht.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions public/javascript/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function goBack() {
window.history.back();
}
81 changes: 77 additions & 4 deletions public/style/style.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
body {
font-family: 'Montserrat', sans-serif;
height: 100%;
width: 100%;
background-color: #e9dcd1;
}

.example-wrapper {
margin: 1em auto;
max-width: 800px;
width: 95%;
font: 18px/1.5 sans-serif;
}

.example-wrapper code {
background: #F5F5F5;
padding: 2px 6px;
}

.p {
line-height: 1.5;
}
Expand All @@ -13,13 +24,25 @@ body {
display: inline-grid;
border: #1111 1px solid;
box-shadow: 0 0 5px -1px rgb(0 0 0 / 30%), 0 0 15px -1px rgb(0 0 0 / 25%), 0 0 20px -1px rgb(0 0 0 / 15%);
margin: 4vw 0 0 4vw;
margin: 4vw 0 0 4.5vw;
height: 25vh;
width: 20vh;
border-radius: 10%;
background-color: #e9dcd1;
}

.grid-sub {
display: inline-grid;
text-align: center;
border: #1111 1px solid;
box-shadow: 0 0 5px -1px rgb(0 0 0 / 30%), 0 0 15px -1px rgb(0 0 0 / 25%), 0 0 20px -1px rgb(0 0 0 / 15%);
margin: 4vw 0 0 4.5vw;
height: 60px;
width: 20vh;
border-radius: 10px;
background-color: #e9dcd1;
}

.grid:active {
box-shadow: 0 0 5px -1px rgb(0 0 0 / 30%), 0 0 15px -1px rgb(0 0 0 / 25%), 0 0 20px -1px rgb(0 0 0 / 15%);
transform: translateY(10px) translateX(10px);
Expand All @@ -40,10 +63,60 @@ body {
.text {
margin-left: 2vw;
}

h1 {
font-size: 4rem;
}

.container {
margin-top: 5000000vh !important;
.logo_landing_page {
margin: 30px 30px 30px 5vw;
}

.logo {
margin: 30px 30px 30px -10vw;

}

.content {
height: 100vh !important;
}

.mealImage {
/*margin: -10px;*/
width: 19.6vw;
margin-left: -15px;
border-radius: 20px 20px 0 0;
min-height: 20vw
}

#row {
display: flex;
width: 100%;
flex-wrap: wrap;
justify-content: center;
}

button {
outline: none !important;
}

#column {
text-align: center;
border-radius: 20px;
margin: 10px;
width: 20%;
height: 54vh;
box-shadow: rgba(0, 0, 0, 0.24) 0 3px 8px;
}

.wineImage {
max-width: 40vw;
max-height: 60vh;
position: relative;
padding-top: 5vh
}

.imageWine {
max-width: 200px;
max-height: 200px;
}
95 changes: 95 additions & 0 deletions src/Command/ProductsCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace App\Command;


use App\Entity\Product;
use App\Repository\ProductRepository;
use DateTime;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Grandcruwijnen\SDK\Products;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class ProductsCommand extends Command {
protected static $defaultName = 'app:fill:products';
protected static $defaultDescription = 'Fills products database';

private Products $products;
private EntityManagerInterface $manager;
private ProductRepository $productRepository;

/**
* ProductsCommand constructor.
* @param Products $products
* @param EntityManagerInterface $manager
* @param ProductRepository $productRepository
*/
public function __construct(Products $products, EntityManagerInterface $manager, ProductRepository $productRepository)
{
parent::__construct();

$this->products = $products;
$this->manager = $manager;
$this->productRepository = $productRepository;
}

protected function configure(): void
{
$this->setDescription(self::$defaultDescription);
}

/**
* @throws Exception
* @throws GuzzleException
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$items = $this->products->getProducts()['items'];
foreach ($items as $magentoProduct)
{
//var_dump($magentoProduct['custom_attributes']); die();
if ($magentoProduct['status'] !== 1)
{
continue;
}
if ( ! isset($magentoProduct['media_gallery_entries'][0]))
{
continue;
}
$product = $this->productRepository->findOneBy(['sku' => $magentoProduct['sku']]);
$updatedAt = new DateTime($magentoProduct['updated_at']);
// $io->comment($magentoProduct['sku']);
if ($product === null)
{
$product = new Product();
$product
->setSku($magentoProduct['sku'])
->setUpdatedAt($updatedAt)
->setName($magentoProduct['name'])
->setDescription($magentoProduct['custom_attributes'][1]['value'])
->setPrice($magentoProduct["price"])
->setStock($magentoProduct['extension_attributes']['stock_item']['qty'])
->setImage($magentoProduct['media_gallery_entries'][0]['file']);
} else if ($updatedAt > $product->getUpdatedAt())
{
$product
->setValid(false)
->setCheckedSinceUpdate(false);
}

$this->manager->persist($product);
}

$this->manager->flush();

$io->success('Product database updated');

return Command::SUCCESS;
}
}
35 changes: 23 additions & 12 deletions src/Controller/MealController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace App\Controller;


use App\Dto\ProductMatch;
use App\Repository\ProductRepository;
use App\Service\MealMatcherService;
use Grandcruwijnen\SDK\API;
use Grandcruwijnen\SDK\Products;
use GuzzleHttp\Exception\GuzzleException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -15,10 +14,13 @@
class MealController extends AbstractController
{

/**
* @throws GuzzleException
*/
#[Route('/', name: 'landing_page')]
public function getIndex(MealMatcherService $mealMatcherService): Response
{
return $this->render('landing page/index.html.twig', ['choices' => $mealMatcherService->getIndexPage()]);
return $this->render('landing/index.html.twig', ['choices' => $mealMatcherService->getIndexPage()]);
}

/**
Expand All @@ -33,7 +35,7 @@ public function getMealCategories(MealMatcherService $mealMatcherService): Respo
/**
* @throws GuzzleException
*/
#[Route('/{parentId}', name: 'meal_categories_for_parent')]
#[Route('/category/{parentId}', name: 'meal_categories_for_parent')]
public function getCategoriesForParent(int $parentId, MealMatcherService $mealMatcherService): Response
{
return $this->render('categories/index.html.twig', ['meals' => $mealMatcherService->getCategoriesForParent($parentId)]);
Expand All @@ -51,17 +53,26 @@ public function getMealsForCategory(int $categoryId, MealMatcherService $mealMat
/**
* @throws GuzzleException
*/
#[Route('/matches/{mealId}', name: 'wines_for_meals')]
public function getWinesForMeals($mealId, MealMatcherService $mealMatcherService)
#[Route('matches/{mealId}', name: 'wines_for_meals')]
public function getWinesForMeals(ProductRepository $products, $mealId, MealMatcherService $mealMatcherService): Response
{
$matches = [];
// dd($mealMatcherService->getWinesForMeal($mealId));
foreach ($mealMatcherService->getWinesForMeal($mealId) as $wine) {
$product = $products->findOneBy(['sku' => $wine->wine->sku]);
// $product = $products->findOneBy(['sku' => $wine->wine->sku]);
if ($product !== null) {
$score = $wine->score;
$productMatch = new ProductMatch($product, $score);
$matches[] = $productMatch;
// $score'' = $product;

$api = new API("[email protected]", "7Wn2okY7!A@mX-DZMmw7tanFaQ*sTGef87o!Gn4_mE6ctiqmLk2hH6LX_deN_K8P7U6LRs7H2BT.cGWvh", "https://beta.grandcruwijnen.dev");
$products = new Products($api);
$sku = '01001';
$products = $products->getProduct($sku);
//TODO: Scores toevoegen aan de wijn
}
}

return $this->render('wines/index.html.twig', [
'products' => $products, 'matches' => $mealMatcherService->getWinesForMeal($mealId)
'matches' => $matches
]);
}
}
14 changes: 14 additions & 0 deletions src/Dto/ProductMatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Dto;

class ProductMatch {
public $product;
public $score;
public function __construct ($product, $score) {
$this->product = $product;
$this->score = $score;
}
}

?>
Loading

0 comments on commit f32b32c

Please sign in to comment.