-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from Jelmer-Ketelaar/dev
Dev
- Loading branch information
Showing
27 changed files
with
928 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ### | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function goBack() { | ||
window.history.back(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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()]); | ||
} | ||
|
||
/** | ||
|
@@ -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)]); | ||
|
@@ -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 | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.