Skip to content

Commit

Permalink
Opsrc 397/export selected to pdf complete (#93)
Browse files Browse the repository at this point in the history
* Add controller to generate pdf & create button for email
  • Loading branch information
PiotrSzymanski2000 authored Dec 7, 2021
1 parent 6daa1b2 commit 44aa55f
Show file tree
Hide file tree
Showing 43 changed files with 975 additions and 30 deletions.
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',
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

0 comments on commit 44aa55f

Please sign in to comment.