Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ default:
FriendsOfBehat\ContextServiceExtension:
imports:
- vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml
- tests/Behat/Resources/services.xml
- tests/Behat/Resources/services.yml

FriendsOfBehat\SymfonyExtension:
kernel:
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
"phpunit/phpunit": "^6.5",
"se/selenium-server-standalone": "^2.52",
"sylius-labs/coding-standard": "^2.0",
"symplify/easy-coding-standard": "^4.6"
"symplify/easy-coding-standard": "^4.6",
"behat/symfony2-extension": "^2.1"
},
"prefer-stable": true,
"autoload": {
"psr-4": {
"Locastic\\SyliusStoreLocatorPlugin\\": "src/",
"Tests\\Acme\\SyliusExamplePlugin\\": "tests/"
"Tests\\Locastic\\SyliusStoreLocatorPlugin\\": "tests/"
}
},
"autoload-dev": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@store
Feature: Seeing store locator index page
As a Customer
I want to be able to see index page with all store locations listed

Background:
Given the store operates on a single channel in "United States"
Given the store has "Dragon Store" store location
Given the store has "Bunny Store" store location

@ui
Scenario: Seeing the store locator page
Given I am at the store locator index page
Then I should see the store map
And I should see the "Dragon Store" store location
And I should see the "Bunny Store" store location
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@store
Feature: Seeing store locator show page
As a Customer
I want to be able to see store location page

Background:
Given the store operates on a single channel in "United States"
Given the store has "Dragon Store" store location
Given the store has "Bunny Store" store location
Given the store has "Basic Bunny Store" store location with only required info

@ui
Scenario: Seeing the single store locator page
Given I am at the store locator index page
And I should see the "Dragon Store" store location
And I should see the "Bunny Store" store location
And I should see the "Basic Bunny Store" store location
And I go to "Bunny Store" store location page
Then I should see the store map
And I should see "Bunny Store" store information
And I should see store images

@ui
Scenario: Seeing the single store locator page with only required info
Given I am at the store locator index page
And I should see the "Basic Bunny Store" store location
And I go to "Basic Bunny Store" store location page
Then I should see the store map
And I should see "Basic Bunny Store" store title
And I should not see "Basic Bunny Store" store information
And I should not see store images
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@store
Feature: Selecting shipping method with pickup at store
In order to pick up order at store
As a Customer
I want to be able to choose a shipping method with pickup at store option

Background:
Given the store operates on a single channel in "United States"
Given the store has a product "Targaryen T-Shirt" priced at "$19.99"
Given the store has "Dragon Store" store location
Given the store has "other shipping method" shipping method with "$10.00" fee
Given the store has "pickup at store" shipping method with enabled store pickup and "$10.00" fee

@ui
Scenario: Selecting store pickup shipping method
Given I have product "Targaryen T-Shirt" in the cart
And I am at the checkout addressing step
When I specify the email as "jon.snow@example.com"
And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And I complete the addressing step
Then I should be redirected to the shipping step
And I select "pickup at store" shipping method
Then I should see "Dragon Store" store location
When I select "Dragon Store" store location
And I complete the shipping step

@ui
Scenario: Selecting store pickup shipping method without store selection
Given I have product "Targaryen T-Shirt" in the cart
And I am at the checkout addressing step
When I specify the email as "jon.snow@example.com"
And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And I complete the addressing step
Then I should be redirected to the shipping step
And I select "pickup at store" shipping method
And I complete the shipping step
Then I should see a validation error

@ui
Scenario: I should be able to select other shipping method and not choose store
Given I have product "Targaryen T-Shirt" in the cart
And I am at the checkout addressing step
When I specify the email as "jon.snow@example.com"
And I specify the shipping address as "Ankh Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And I complete the addressing step
Then I should be redirected to the shipping step
When I select "other shipping method" shipping method
And I complete the shipping step
4 changes: 2 additions & 2 deletions phpspec.yml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
suites:
main:
namespace: Acme\SyliusExamplePlugin
psr4_prefix: Acme\SyliusExamplePlugin
namespace: Locastic\SyliusStoreLocatorPlugin
psr4_prefix: Locastic\SyliusStoreLocatorPlugin
2 changes: 1 addition & 1 deletion src/Entity/IsPickupAtStoreInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ interface IsPickupAtStoreInterface
{
public function isPickupAtStore(): ?bool;

public function setPickupAtStore(bool $pickupAtLocation): void;
public function setPickupAtStore(bool $pickupAtStore): void;
}
81 changes: 81 additions & 0 deletions src/Fixture/StoreFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Locastic\SyliusStoreLocatorPlugin\Fixture;

use Locastic\SyliusStoreLocatorPlugin\Entity\Store;
use Locastic\SyliusStoreLocatorPlugin\Entity\StoreImage;
use Locastic\SyliusStoreLocatorPlugin\Entity\StoreImageInterface;
use Locastic\SyliusStoreLocatorPlugin\Entity\StoreTranslation;
use Sylius\Component\Core\Uploader\ImageUploaderInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;

class StoreFactory
{
/** @var ImageUploaderInterface */
private $imageUploader;

/**
* StoreFactory constructor.
* @param ImageUploaderInterface $imageUploader
*/
public function __construct(ImageUploaderInterface $imageUploader)
{
$this->imageUploader = $imageUploader;
}

/**
* {@inheritdoc}
*/
public function create(array $options = [])
{
$store = new Store();
$store->setCode($options['code']);

foreach ($options['translations'] as $locale => $translation) {
$pageTranslation = new StoreTranslation();
$pageTranslation->setLocale($locale);

$pageTranslation->setName($translation['name']);
$pageTranslation->setSlug($translation['slug']);
$pageTranslation->setContent($translation['content']);
$pageTranslation->setOpeningHours($translation['opening_hours']);
$pageTranslation->setMetaTitle($translation['meta_title']);
$pageTranslation->setMetaDescription($translation['meta_description']);
$pageTranslation->setMetaKeywords($translation['meta_keywords']);

$store->addTranslation($pageTranslation);
}

$store->setLatitude($options['latitude']);
$store->setLongitude($options['longitude']);
$store->setAddress($options['address']);
$store->setContactEmail($options['contact_email']);
$store->setContactPhone($options['contact_phone']);
$store->setPickupAtStoreAvailable($options['pickup_at_store_available']);

foreach ($options['images'] as $image) {
if (!array_key_exists('path', $image)) {
$imagePath = array_shift($image);
$imageType = array_pop($image);
} else {
$imagePath = $image['path'];
$imageType = $image['type'] ?? null;
}

$uploadedImage = new UploadedFile($imagePath, basename($imagePath));

/** @var StoreImageInterface $storeImage */
$storeImage = new StoreImage();

$storeImage->setPath($imagePath);
$storeImage->setFile($uploadedImage);
$storeImage->setType($imageType);

$this->imageUploader->upload($storeImage);

$store->addImage($storeImage);
}

return $store;
}
}
41 changes: 41 additions & 0 deletions src/Form/EventListener/ShipmentFormEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Locastic\SyliusStoreLocatorPlugin\Form\EventListener;

use Locastic\SyliusStoreLocatorPlugin\Entity\Shipment;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;

class ShipmentFormEventListener implements EventSubscriberInterface
{
private $message;

public function __construct(string $message)
{
$this->message = $message;
}

public static function getSubscribedEvents()
{
return [
FormEvents::POST_SUBMIT => 'onPostSubmit',
];
}


public function onPostSubmit(FormEvent $event)
{
$shipment = $event->getData();
$form = $event->getForm();

if (!$shipment instanceof Shipment || !$form->isValid()) {
return;
}

if ($shipment->getMethod()->isPickupAtStore() && $shipment->getStore() === null) {
$form->addError(new FormError($this->message));
}
}
}
17 changes: 14 additions & 3 deletions src/Form/Extension/Checkout/ShipmentTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Locastic\SyliusStoreLocatorPlugin\Form\Extension\Checkout;

use Locastic\SyliusStoreLocatorPlugin\Entity\Store;
use Locastic\SyliusStoreLocatorPlugin\Form\EventListener\ShipmentFormEventListener;
use Sylius\Bundle\CoreBundle\Form\Type\Checkout\ShipmentType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractTypeExtension;
Expand All @@ -13,6 +14,13 @@

final class ShipmentTypeExtension extends AbstractTypeExtension
{
private $translator;

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

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add(
Expand All @@ -25,15 +33,18 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->setParameter('pickupAtStoreAvailable', true);
},
'mapped' => true,
'class' => Store::class,
'required' => false,
'class' => Store::class,
'choice_label' => 'name',
]
);

$message = $this->translator->trans('locastic_sylius_store_locator_plugin.shipment_method.store_not_null',[],'validators');
$builder->addEventSubscriber(new ShipmentFormEventListener($message));
}

public function getExtendedType(): string
public static function getExtendedTypes(): iterable
{
return ShipmentType::class;
return [ShipmentType::class];
}
}
8 changes: 4 additions & 4 deletions src/Form/Extension/ShippingMethodTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add(
'pickupAtLocation',
'pickupAtStore',
CheckboxType::class,
[
'label' => 'locastic_sylius_store_locator_plugin.ui.pickup_at_location',
'label' => 'locastic_sylius_store_locator_plugin.ui.pickup_at_store',
'required' => false,
]
);
}

public function getExtendedType()
public static function getExtendedTypes(): iterable
{
return ShippingMethodType::class;
return [ShippingMethodType::class];
}
}
2 changes: 2 additions & 0 deletions src/Resources/config/config_pickup_at_store.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ imports:
services:
locastic_sylius_store_locator_plugin.form.extension.type.shipment:
class: Locastic\SyliusStoreLocatorPlugin\Form\Extension\Checkout\ShipmentTypeExtension
arguments:
- '@translator'
tags:
- { name: form.type_extension, extended_type: Sylius\Bundle\CoreBundle\Form\Type\Checkout\ShipmentType }

Expand Down
6 changes: 6 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ services:
tags:
- { name: sylius_fixtures.fixture }

locastic_sylius_store_locator_plugin.example_factory.store:
class: Locastic\SyliusStoreLocatorPlugin\Fixture\StoreFactory
arguments:
- '@sylius.image_uploader'
public: true


# listeners
locastic_sylius_store_locator_plugin.listener.images_upload:
Expand Down
4 changes: 0 additions & 4 deletions src/Resources/config/validation/Shipment.yml

This file was deleted.

7 changes: 7 additions & 0 deletions src/Resources/public/js/locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,11 @@
map.setAddress();
});

//This is temporary fix for app.js addition of hidden class.
setTimeout(function () {

$('#locastic_sylius_store_locator_plugin_store_enabled').removeClass('hidden');
$('#locastic_sylius_store_locator_plugin_store_pickupAtStoreAvailable').removeClass('hidden');
}, 500);

}(window.jQuery));
2 changes: 1 addition & 1 deletion src/Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ locastic_sylius_store_locator_plugin:
opening_hours: Opening hours
see_more: See More
pickup_at_store_available: Pickup At Store Available
pickup_at_location: Pickup At Location
pickup_at_store: Pickup At Location
images: Images of store
2 changes: 1 addition & 1 deletion src/Resources/translations/messages.hr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ locastic_sylius_store_locator_plugin:
opening_hours: Radno vrijeme
see_more: Pogledaj više
pickup_at_store_available: Dostupno preuzimanje u trgovini
pickup_at_location: Preuzimanje u trgovini
pickup_at_store: Preuzimanje u trgovini
images: Slike trgovine
Loading