Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opsrc 397/export selected to pdf complete #93

Merged
merged 27 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e87e097
Add controller to generate pdf & create button for email
PiotrSzymanski2000 Oct 25, 2021
1245fbd
Filter selected products & send data to pdf & display data in pdf
PiotrSzymanski2000 Oct 26, 2021
335b5c1
add resolver to image path & create model for selected products & cre…
PiotrSzymanski2000 Oct 27, 2021
0bd9ee1
refactor ExportWishlistToPdfAction $ add validation in resolver $ add…
PiotrSzymanski2000 Oct 29, 2021
6e76905
refactor code & add tests for resolver and model
PiotrSzymanski2000 Nov 2, 2021
fd61a5b
add tests for ExportWishlistToPdfAction & tests for ExporterWishlistT…
PiotrSzymanski2000 Nov 3, 2021
5685c17
fix phpspec tests
PiotrSzymanski2000 Nov 4, 2021
e8a0399
fix phpspec tests for ListWishlistProductsAction & refactor code & ad…
PiotrSzymanski2000 Nov 5, 2021
bd8bba1
fix github actions
PiotrSzymanski2000 Nov 5, 2021
246bd6e
correct the code with formatting standards
PiotrSzymanski2000 Nov 5, 2021
bb18759
fix behat tests
PiotrSzymanski2000 Nov 5, 2021
d7067c8
run ecs to format the code
PiotrSzymanski2000 Nov 5, 2021
695fccb
rafactor code style & refactor behat test
PiotrSzymanski2000 Nov 10, 2021
8ba64f1
Refactor code & code style
PiotrSzymanski2000 Nov 10, 2021
05c36c8
fix conflict with collective actions
PiotrSzymanski2000 Nov 22, 2021
9092141
fix github actions
PiotrSzymanski2000 Nov 22, 2021
a900400
refactor code & fix phpspec tests
PiotrSzymanski2000 Nov 23, 2021
1d332f1
refactor code
PiotrSzymanski2000 Nov 29, 2021
80a4dbf
refactor code & fix phpspec tests
PiotrSzymanski2000 Nov 29, 2021
6a5bee3
improve code
PiotrSzymanski2000 Nov 30, 2021
5e1f299
fix after cr
PiotrSzymanski2000 Dec 1, 2021
363a5be
rename model file
PiotrSzymanski2000 Dec 1, 2021
abd97bd
fix github actions
PiotrSzymanski2000 Dec 1, 2021
2ff94b1
fix after cr & refactor resolver to image path
PiotrSzymanski2000 Dec 6, 2021
6a77729
extract creating model logic to other service
PiotrSzymanski2000 Dec 6, 2021
45cfe7f
add BitBag comment
PiotrSzymanski2000 Dec 6, 2021
9a3485b
fix after cr
PiotrSzymanski2000 Dec 7, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
"symfony/intl": "^4.4 || ^5.2",
"symfony/web-profiler-bundle": "^4.4 || ^5.2",
"symfony/web-server-bundle": "^4.4|^5.2",
"symfony/webpack-encore-bundle": "^1.12",
"symfony/dependency-injection": "<4.4.19 || >=5.0.0 <5.2.2"
"symfony/dependency-injection": "<4.4.19 || >=5.0.0 <5.2.2",
"dompdf/dompdf": "1.0.2",
"symfony/webpack-encore-bundle": "^1.12"
},
"conflict": {
"doctrine/dbal": "^3.0",
Expand Down
2 changes: 0 additions & 2 deletions features/adding_product_to_wishlist.feature
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,3 @@ Feature: Adding a product to wishlist
And I log out
And I log in again
Then I should have one item in my wishlist


16 changes: 16 additions & 0 deletions features/exporting_product_from_wishlist_to_pdf.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@wishlist
Feature: Exporting a product from wishlist to pdf
In order to save products and buy later
As a Visitor
I want to be able to exporting products to pdf

Background:
Given the store operates on a single channel in "United States"

@ui
Scenario: Exporting selected products from wishlist
Given the store has a product "Jack Daniels Gentleman" priced at "$10.00"
And I have this product in my wishlist
When I go to the wishlist page
Then I check "Jack Daniels Gentleman"
And I export to pdf selected products from wishlist and file is downloaded
53 changes: 53 additions & 0 deletions spec/Model/Factory/VariantPdfModelFactorySpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusWishlistPlugin\Model\Factory;

use BitBag\SyliusWishlistPlugin\Model\Factory\VariantPdfModelFactory;
use BitBag\SyliusWishlistPlugin\Model\Factory\VariantPdfModelFactoryInterface;
use BitBag\SyliusWishlistPlugin\Model\VariantPdfModel;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ProductVariant;

final class VariantPdfModelFactorySpec extends ObjectBehavior
{
function it_is_initializable(): void
{
$this->shouldHaveType(VariantPdfModelFactory::class);
}

function it_implements_variant_pdf_model_factory_interface(): void
{
$this->shouldHaveType(VariantPdfModelFactoryInterface::class);
}

function it_returns_product_pdf_model(): void
{
$productVariant = new ProductVariant();
$productPdfModel = $this->createWithVariantAndImagePath(
$productVariant,
'http://127.0.0.1:8000/media/image/b4/c2/fc6b3202ee567e0fb05f293b709c.jpg',
10,
'variant test'
);

$productPdfModel->getVariant()->shouldReturn($productVariant);
$productPdfModel->getImagePath()->shouldReturn('http://127.0.0.1:8000/media/image/b4/c2/fc6b3202ee567e0fb05f293b709c.jpg');
$productPdfModel->getQuantity()->shouldReturn(10);
$productPdfModel->getActualVariant()->shouldReturn('variant test');

$this->createWithVariantAndImagePath(
$productVariant,
'http://127.0.0.1:8000/media/image/b4/c2/fc6b3202ee567e0fb05f293b709c.jpg',
PiotrSzymanski2000 marked this conversation as resolved.
Show resolved Hide resolved
10,
'variant test'
)->shouldBeAnInstanceOf(VariantPdfModel::class);
}
}
42 changes: 42 additions & 0 deletions spec/Model/VariantPdfModelSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusWishlistPlugin\Model;

use BitBag\SyliusWishlistPlugin\Model\VariantPdfModel;
use BitBag\SyliusWishlistPlugin\Model\VariantPdfModelInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ProductVariantInterface;

final class VariantPdfModelSpec extends ObjectBehavior
{
function it_is_initializable(): void
{
$this->shouldHaveType(VariantPdfModel::class);
}

function it_implements_variant_pdf_model_interface(): void
{
$this->shouldHaveType(VariantPdfModelInterface::class);
}

function it_returns_property_of_variant_pdf_model(ProductVariantInterface $productVariant): void
{
$this->setActualVariant('variant test');
$this->setVariant($productVariant);
$this->setImagePath('/image/123/image.jpg');
$this->setQuantity(10);

$this->getActualVariant()->shouldReturn('variant test');
$this->getVariant()->shouldReturn($productVariant);
$this->getImagePath()->shouldReturn('/image/123/image.jpg');
$this->getQuantity()->shouldReturn(10);
}
}
62 changes: 62 additions & 0 deletions spec/Resolver/VariantImageToDataUriResolverSpec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace spec\BitBag\SyliusWishlistPlugin\Resolver;

use BitBag\SyliusWishlistPlugin\Resolver\GenerateDataUriForImageResolverInterface;
use BitBag\SyliusWishlistPlugin\Resolver\VariantImageToDataUriResolver;
use Doctrine\Common\Collections\Collection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ProductImage;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;

final class VariantImageToDataUriResolverSpec extends ObjectBehavior
{
private const TEST_BASE_URL = 'http://test:8000';

public function let(GenerateDataUriForImageResolverInterface $dataUriForImageResolver): void
{
$this->beConstructedWith(
$dataUriForImageResolver
);
}

public function it_is_initializable(): void
{
$this->shouldHaveType(VariantImageToDataUriResolver::class);
}

public function it_resolve_empty_image_path(
ProductVariantInterface $variant,
ProductInterface $product,
Collection $productImages
): void {
$variant->getProduct()->willReturn($product);
$product->getImages()->willReturn($productImages);
$productImages->first()->willReturn(false);

$this->resolve($variant, self::TEST_BASE_URL)->shouldReturn('');
}

public function it_resolve_image_path(
ProductVariantInterface $variant,
ProductInterface $product,
Collection $productImages,
ProductImage $productImage,
GenerateDataUriForImageResolverInterface $dataUriForImageResolver
): void {
$variant->getProduct()->willReturn($product);
$product->getImages()->willReturn($productImages);
$productImages->first()->willReturn($productImage);
$dataUriForImageResolver->resolve($productImage)->willReturn(self::TEST_BASE_URL);
$this->resolve($variant, self::TEST_BASE_URL)->shouldReturn(self::TEST_BASE_URL);
}
}
2 changes: 1 addition & 1 deletion src/Command/Wishlist/AddProductsToWishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

final class AddProductsToWishlist
{
/** @var Collection<AddWishlistProduct> */
/** @var Collection<WishlistItem> */
private Collection $wishlistProducts;

public function __construct(Collection $wishlistProducts)
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Wishlist/AddSelectedProductsToCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

final class AddSelectedProductsToCart
{
/** @var Collection<AddWishlistProduct> */
/** @var Collection<WishlistItem> */
private Collection $wishlistProducts;

public function __construct(Collection $wishlistProducts)
Expand Down
31 changes: 31 additions & 0 deletions src/Command/Wishlist/ExportSelectedProductsFromWishlistToPdf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace BitBag\SyliusWishlistPlugin\Command\Wishlist;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\Component\HttpFoundation\Request;

final class ExportSelectedProductsFromWishlistToPdf implements ExportSelectedProductsFromWishlistToPdfInterface
{
/** @var Collection<WishlistItem> */
private Collection $wishlistProducts;

public function __construct(Collection $wishlistProducts)
{
$this->wishlistProducts = $wishlistProducts;
}

public function getWishlistProducts(): ?Collection
{
return $this->wishlistProducts;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace BitBag\SyliusWishlistPlugin\Command\Wishlist;

use Doctrine\Common\Collections\Collection;

interface ExportSelectedProductsFromWishlistToPdfInterface
{
public function getWishlistProducts(): ?Collection;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

final class RemoveSelectedProductsFromWishlist
{
/** @var Collection<AddWishlistProduct> */
/** @var Collection<WishlistItem> */
private Collection $wishlistProducts;

public function __construct(Collection $wishlistProducts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface;
use Sylius\Bundle\OrderBundle\Controller\AddToCartCommandInterface;

class AddWishlistProduct
class WishlistItem implements WishlistItemInterface
{
private ?WishlistProductInterface $wishlistProduct;

Expand Down
23 changes: 23 additions & 0 deletions src/Command/Wishlist/WishlistItemInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace BitBag\SyliusWishlistPlugin\Command\Wishlist;

use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface;
use Sylius\Bundle\OrderBundle\Controller\AddToCartCommandInterface;

interface WishlistItemInterface
{
public function getWishlistProduct(): ?WishlistProductInterface;

public function setWishlistProduct(?WishlistProductInterface $wishlistProduct): void;

public function isSelected(): ?bool;

public function setSelected(?bool $selected): void;

public function getCartItem(): ?AddToCartCommandInterface;

public function setCartItem(?AddToCartCommandInterface $cartItem): void;
}
8 changes: 4 additions & 4 deletions src/CommandHandler/Wishlist/AddProductsToWishlistHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist;

use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddProductsToWishlist;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddWishlistProduct;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItem;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Component\Order\Model\OrderItemInterface;
Expand Down Expand Up @@ -49,15 +49,15 @@ public function __invoke(AddProductsToWishlist $addProductsToWishlistCommand): v

private function addProductsToWishlist(Collection $wishlistProducts): void
{
/** @var AddWishlistProduct $wishlistProduct */
/** @var WishlistItem $wishlistProduct */
foreach ($wishlistProducts as $wishlistProduct) {
if ($this->productCanBeProcessed($wishlistProduct)) {
$this->addProductToWishlist($wishlistProduct);
}
}
}

private function productCanBeProcessed(AddWishlistProduct $wishlistProduct): bool
private function productCanBeProcessed(WishlistItem $wishlistProduct): bool
{
$cartItem = $wishlistProduct->getCartItem()->getCartItem();

Expand Down Expand Up @@ -85,7 +85,7 @@ private function productHasPositiveQuantity(OrderItemInterface $product): bool
return false;
}

private function addProductToWishlist(AddWishlistProduct $wishlistProduct): void
private function addProductToWishlist(WishlistItem $wishlistProduct): void
{
$cart = $wishlistProduct->getCartItem()->getCart();
$cartItem = $wishlistProduct->getCartItem()->getCartItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace BitBag\SyliusWishlistPlugin\CommandHandler\Wishlist;

use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddSelectedProductsToCart;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\AddWishlistProduct;
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItem;
use Doctrine\Common\Collections\Collection;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
use Sylius\Component\Order\Modifier\OrderItemQuantityModifierInterface;
Expand Down Expand Up @@ -57,7 +57,7 @@ public function __invoke(AddSelectedProductsToCart $addSelectedProductsToCartCom

private function addSelectedProductsToCart(Collection $wishlistProducts): void
{
/** @var AddWishlistProduct $wishlistProduct */
/** @var WishlistItem $wishlistProduct */
foreach ($wishlistProducts as $wishlistProduct) {
if (!$wishlistProduct->isSelected()) {
continue;
Expand All @@ -71,7 +71,7 @@ private function addSelectedProductsToCart(Collection $wishlistProducts): void
}
}

private function isInStock(AddWishlistProduct $wishlistProduct): bool
private function isInStock(WishlistItem $wishlistProduct): bool
{
$cartItem = $wishlistProduct->getCartItem()->getCartItem();

Expand All @@ -84,7 +84,7 @@ private function isInStock(AddWishlistProduct $wishlistProduct): bool
return false;
}

private function addProductToWishlist(AddWishlistProduct $wishlistProduct): void
private function addProductToWishlist(WishlistItem $wishlistProduct): void
{
$cart = $wishlistProduct->getCartItem()->getCart();
$cartItem = $wishlistProduct->getCartItem()->getCartItem();
Expand Down
Loading