├── .gitignore
├── README.md
├── Resources
├── translations
│ ├── messages.en.yml
│ ├── messages.cs.yml
│ ├── messages.da.yml
│ ├── messages.el.yml
│ ├── messages.es.yml
│ ├── messages.fa.yml
│ ├── messages.fr.yml
│ ├── messages.hr.yml
│ ├── messages.it.yml
│ ├── messages.lt.yml
│ ├── messages.no.yml
│ ├── messages.pl.yml
│ ├── messages.sk.yml
│ ├── messages.sl.yml
│ ├── messages.sq.yml
│ ├── messages.sv.yml
│ ├── messages.th.yml
│ ├── messages.tr.yml
│ ├── messages.zh_CN.yml
│ ├── messages.be.yml
│ ├── messages.ca.yml
│ ├── messages.de.yml
│ ├── messages.de_CH.yml
│ ├── messages.hu.yml
│ ├── messages.id.yml
│ ├── messages.nl.yml
│ ├── messages.pt.yml
│ ├── messages.pt_BR.yml
│ ├── messages.ro.yml
│ ├── messages.ru.yml
│ ├── messages.uk.yml
│ ├── flashes.zh_CN.yml
│ ├── flashes.ja.yml
│ ├── flashes.ar.yml
│ ├── flashes.fi.yml
│ ├── flashes.be.yml
│ ├── flashes.ru.yml
│ ├── flashes.sq.yml
│ ├── flashes.fa.yml
│ ├── flashes.cs.yml
│ ├── flashes.uk.yml
│ ├── flashes.lt.yml
│ ├── flashes.sr.yml
│ ├── flashes.sr_CS.yml
│ ├── flashes.sv.yml
│ ├── flashes.ro.yml
│ ├── flashes.en.yml
│ ├── flashes.hu.yml
│ ├── flashes.sk.yml
│ ├── flashes.no.yml
│ ├── flashes.bg.yml
│ ├── flashes.pl.yml
│ ├── flashes.pt.yml
│ ├── flashes.pt_BR.yml
│ ├── flashes.th.yml
│ ├── flashes.vi.yml
│ ├── flashes.hr.yml
│ ├── flashes.el.yml
│ ├── flashes.sl.yml
│ ├── flashes.tr.yml
│ ├── flashes.de_CH.yml
│ ├── flashes.es.yml
│ ├── flashes.id.yml
│ ├── flashes.da.yml
│ ├── flashes.af.yml
│ ├── flashes.de.yml
│ ├── flashes.fr.yml
│ ├── flashes.ca.yml
│ ├── flashes.it.yml
│ └── flashes.nl.yml
├── config
│ ├── routing.yml
│ ├── driver
│ │ └── doctrine
│ │ │ └── orm.xml
│ ├── doctrine
│ │ └── model
│ │ │ ├── CartItem.orm.xml
│ │ │ └── Cart.orm.xml
│ ├── twig.xml
│ ├── templating.xml
│ ├── validation.xml
│ └── services.xml
└── meta
│ └── LICENSE
├── phpspec.yml.dist
├── spec
├── Twig
│ └── CartExtensionSpec.php
├── Purger
│ └── ExpiredCartsPurgerSpec.php
├── Command
│ └── PurgeCartsCommandSpec.php
├── Form
│ └── Type
│ │ ├── CartTypeSpec.php
│ │ └── CartItemTypeSpec.php
├── Context
│ └── SessionBasedCartContextSpec.php
└── Templating
│ └── Helper
│ └── CartHelperSpec.php
├── Form
└── Type
│ ├── CartType.php
│ └── CartItemType.php
├── Command
└── PurgeCartsCommand.php
├── DependencyInjection
├── Compiler
│ └── RegisterCartContextsPass.php
├── SyliusCartExtension.php
└── Configuration.php
├── SyliusCartBundle.php
├── composer.json
├── Purger
└── ExpiredCartsPurger.php
├── Doctrine
└── ORM
│ └── CartRepository.php
├── CHANGELOG.md
├── Context
└── SessionBasedCartContext.php
├── Controller
├── Controller.php
├── CartController.php
└── CartItemController.php
├── Twig
└── CartExtension.php
├── Templating
└── Helper
│ └── CartHelper.php
├── EventListener
└── SessionCartSubscriber.php
└── Tests
└── DependencyInjection
└── Compiler
└── RegisterCartContextsPassTest.php
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor/
2 | bin/
3 |
4 | composer.phar
5 | composer.lock
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | DEPRACATED
2 | ==========
3 |
4 | Use SyliusOrderBundle instead.
5 |
--------------------------------------------------------------------------------
/Resources/translations/messages.en.yml:
--------------------------------------------------------------------------------
1 | sylius:
2 | form:
3 | cart_item:
4 | quantity: Quantity
5 |
--------------------------------------------------------------------------------
/phpspec.yml.dist:
--------------------------------------------------------------------------------
1 | suites:
2 | main:
3 | namespace: Sylius\Bundle\CartBundle
4 | psr4_prefix: Sylius\Bundle\CartBundle
5 | src_path: .
6 |
--------------------------------------------------------------------------------
/Resources/translations/messages.cs.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Počet
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.da.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Mængde
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.el.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Ποσότητα
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.es.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Cantidad
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.fa.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: تعداد
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.fr.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Quantité
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.hr.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Količina
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.it.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Quantità
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.lt.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Kiekis
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.no.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Antall
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.pl.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Ilość
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.sk.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Množstvo
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.sl.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Količina
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.sq.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Sasia
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.sv.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Antal
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.th.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: จำนวน
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.tr.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Adet
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.zh_CN.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: 数量
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.be.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Колькасць
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.ca.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Quantitat
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.de.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Stückzahl
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.de_CH.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Stückzahl
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.hu.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Mennyiség
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.id.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Kuantitas
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.nl.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Hoeveelheid
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.pt.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Quantidade
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.pt_BR.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Quantidade
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.ro.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Cantitate
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.ru.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Количество
8 |
--------------------------------------------------------------------------------
/Resources/translations/messages.uk.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | form:
6 | cart_item:
7 | quantity: Кількість
8 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.zh_CN.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: 已成功更新购物车。
7 | cart_clear_completed: 购物车已清空。
8 | item_add_completed: 商品已添加到购物车。
9 | item_remove_completed: 已从购物车中移除该商品。
10 | item_add_error: 商品添加到购物车时发生错误 。
11 | item_remove_error: 从购物车中删除商品时出错。
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.ja.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: カートに保存しました。
7 | cart_clear_completed: カートを空にしました。
8 | item_add_completed: 商品をカートに追加しました。
9 | item_remove_completed: 商品をカートから削除しました。
10 | item_add_error: 商品をカートに追加できませんでした。
11 | item_remove_error: 商品をカートから削除できませんでした。
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.ar.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: تم بنجاح تحديث العربة.
7 | cart_clear_completed: تم مسح العربة بنجاح.
8 | item_add_completed: تم إضافة العنصر إلى عربة التسوق.
9 | item_remove_completed: وقد تم إزالة العنصر من سلة.
10 | item_add_error: حدث خطأ أثناء إضافة العنصر إلى عربة التسوق.
11 | item_remove_error: حدث خطأ أثناء إزالة العنصر من سلة.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.fi.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Ostoskori on päivitetty.
7 | cart_clear_completed: Ostoskori on tyhjennetty.
8 | item_add_completed: Tuote on lisätty ostoskoriin.
9 | item_remove_completed: Tuote poistettiin ostoskorista.
10 | item_add_error: Virhe lisättäessä tuotetta ostoskoriin.
11 | item_remove_error: Virhe poistettaessa tuotetta.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.be.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Кошык быў абноўлены.
7 | cart_clear_completed: Кошык ачышчаны.
8 | item_add_completed: Пакупка дададзена у кошык.
9 | item_remove_completed: Тавар выдалены з кошыка.
10 | item_add_error: Памылка здарылася падчас дадання тавару да кошыка.
11 | item_remove_error: Памылка здарылася падчас выдаленна тавару з кошыка.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.ru.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Корзина успешно обновлена.
7 | cart_clear_completed: Корзина успешно очищена.
8 | item_add_completed: Позиция добавлена в корзину.
9 | item_remove_completed: Позиция удалена из корзины.
10 | item_add_error: При добавлении позиции в корзину возникла ошибка.
11 | item_remove_error: При удалении из корзины возникла ошибка.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.sq.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Karta u përditësua me sukses.
7 | cart_clear_completed: Karta u fshi me sukses.
8 | item_add_completed: Artikulli u shtua në kartë.
9 | item_remove_completed: Artikulli u fshi nga karta.
10 | item_add_error: Gabim gjatë shtimit të artikullit në kartë.
11 | item_remove_error: Gabim gjatë fshirjes së artikullit nga karta.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.fa.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: سبد خرید با موفقیت به روز شد.
7 | cart_clear_completed: سبد خرید با موفقیت خالی شد.
8 | item_add_completed: کالا با موفقیت به سبد خرید اضافه شد.
9 | item_remove_completed: محصول از سبد خرید حذف شد.
10 | item_add_error: هنگام افزودن کالا به سبد خرید اشکالی رخ داد.
11 | item_remove_error: هنگام حذف کالا از سبد خرید اشکالی رخ داد.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.cs.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Košík byl úspěšně aktualizován.
7 | cart_clear_completed: Košík byl úspěšně vyprázdněn.
8 | item_add_completed: Položka byla přidána do košíku.
9 | item_remove_completed: Položka byla odebrána z košíku.
10 | item_add_error: Nastala chyba při přidávání položky do košíku.
11 | item_remove_error: Nastala chyba při odebírání položky z košíku.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.uk.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Кошик було успішно оновлено.
7 | cart_clear_completed: Кошик було успішно очищено.
8 | item_add_completed: Елемент був доданий в кошик.
9 | item_remove_completed: Елемент видалено з кошика.
10 | item_add_error: Сталася помилка під час додавання елемента в кошик.
11 | item_remove_error: Сталася помилка під час видалення елемента з кошику.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.lt.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Krepšelis buvo sėkmingai atnaujintas.
7 | cart_clear_completed: Krepšelis buvo sėkmingai išvalytas.
8 | item_add_completed: Prekė įdėta į krepšelį.
9 | item_remove_completed: Prekė pašalinta iš krepšelio.
10 | item_add_error: Įvyko klaida bandant įdėti prekę į krepšelį.
11 | item_remove_error: Įvyko klaida bandant pašalinti prekę iš krepšelio.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.sr.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Корпа је успешно ажурирана.
7 | cart_clear_completed: Корпа је успешно испражњена.
8 | item_add_completed: Артикал је додат у корпу.
9 | item_remove_completed: Артикал је уклоњен из корпе.
10 | item_add_error: Дошло је до грешке приликом додавања артикла у корпу.
11 | item_remove_error: Дошло је до грешке приликом уклањања артикла из корпе.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.sr_CS.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Korpa je uspešno ažurirana.
7 | cart_clear_completed: Korpa je uspešno ispražnjena.
8 | item_add_completed: Stavka je dodata u korpu.
9 | item_remove_completed: Stavka je izbačena iz korpe.
10 | item_add_error: Dogodila se greška dok se stavka dodavala u korpu.
11 | item_remove_error: Dogodila se greška dok se stavka uklanjala iz korpe.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.sv.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Korgen har uppdaterats.
7 | cart_clear_completed: Korgen har tömts.
8 | item_add_completed: Artikeln har lagts i korgen.
9 | item_remove_completed: Artikeln har tagits bort från korgen.
10 | item_add_error: Ett fel uppstod när artikeln skulle läggas i korgen.
11 | item_remove_error: Ett fel uppstod när artikeln skulle tas bort från korgen.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.ro.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Coșul a fost actualizat cu succes.
7 | cart_clear_completed: Coșul a fost golit cu succes.
8 | item_add_completed: Produsul a fost adăugat în coș.
9 | item_remove_completed: Produsul a fost scos din coș.
10 | item_add_error: A apărut o eroare la adăugarea produsului in coş.
11 | item_remove_error: A apărut o eroare la ștergerea produsului din coș.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.en.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: The cart has been successfully updated.
7 | cart_clear_completed: The cart has been successfully cleared.
8 | item_add_completed: Item has been added to cart.
9 | item_remove_completed: Item has been removed from cart.
10 | item_add_error: Error occurred while adding item to cart.
11 | item_remove_error: Error occurred while removing item from cart.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.hu.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: A kosár tartalmának módosítása megtörtént.
7 | cart_clear_completed: A kosár kiürítése megtörtént.
8 | item_add_completed: A kiválasztott elem a kosárba került.
9 | item_remove_completed: Az termék törölve lett a kosárból.
10 | item_add_error: Hiba történt a kosárba helyezés közben.
11 | item_remove_error: Hiba az elem kosárból való eltávolítása közben.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.sk.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Košík bol úspešne aktualizovaný.
7 | cart_clear_completed: Obsah košíka bol úspešne vymazaný.
8 | item_add_completed: Položka bola pridaná do košíka.
9 | item_remove_completed: Položka bola odstránená z košíka.
10 | item_add_error: Nastala chyba pri pridávaní položky do košíka.
11 | item_remove_error: Nastala chyba pri odstraňovaní položky do košíka.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.no.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Handlevognen ble oppdatert.
7 | cart_clear_completed: Handlevognen ble tømt.
8 | item_add_completed: Varen ble lagt i handlevognen.
9 | item_remove_completed: Varen ble fjernet fra handlevognen.
10 | item_add_error: Det oppstod en feil da varen skulle legges i handlevognen.
11 | item_remove_error: Det oppstod en feil da varen skulle fjernes fra handlevognen.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.bg.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Количката е актуализирана успешно.
7 | cart_clear_completed: Количката е почистена успешно.
8 | item_add_completed: Артикулът е добавен в кошницата.
9 | item_remove_completed: Артикулът е премахнат от кошницата.
10 | item_add_error: Възникна грешка при добавяне на елемент в кошницата.
11 | item_remove_error: Възникна грешка при премахването на елемент от количката.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.pl.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Koszyk został pomyślnie uaktualniony.
7 | cart_clear_completed: Koszyk został pomyślnie wyczyszczony.
8 | item_add_completed: Produkt został dodany do koszyka.
9 | item_remove_completed: Produkt został usunięty z koszyka.
10 | item_add_error: Wystąpił błąd podczas dodawania produktu do koszyka.
11 | item_remove_error: Wystąpił błąd podczas usuwania produktu z koszyka.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.pt.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: O carrinho foi atualizado com sucesso.
7 | cart_clear_completed: O carrinho foi limpo com sucesso.
8 | item_add_completed: O produto foi adicionado ao carrinho.
9 | item_remove_completed: O produto foi removido do carrinho.
10 | item_add_error: Ocorreu um erro ao adicionar o produto ao carrinho.
11 | item_remove_error: Ocorreu um erro ao remover o produto ao carrinho.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.pt_BR.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: O carrinho foi atualizado com sucesso.
7 | cart_clear_completed: O carrinho foi esvaziado com sucesso.
8 | item_add_completed: O item foi adicionado ao carrinho.
9 | item_remove_completed: O item foi removido do carrinho.
10 | item_add_error: Ocorreu um erro ao adicionar o item no carrinho.
11 | item_remove_error: Ocorreu um erro ao remover um item do carrinho.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.th.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: อัปเดตตะกร้าสินค้าเสร็จเรียบร้อยแล้ว
7 | cart_clear_completed: เคลียร์ตะกร้าสินค้าเสร็จเรียบร้อยแล้ว
8 | item_add_completed: เพิ่มรายการลงในตระกร้าสินค้าเรียบร้อยแล้ว
9 | item_remove_completed: รายการสินค้าถูกลบออกจากตะกร้าสินค้าแล้ว
10 | item_add_error: เกิดความผิดพลาดในขณะเพิ่มรายการสินค้าลงตะกร้า
11 | item_remove_error: เกิดความผิดพลาดขึ้นในขณะลบสินค้าออกจากตะกร้า
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.vi.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Giỏ hàng đã được cập nhật thành công.
7 | cart_clear_completed: Giỏ hàng đã được xóa thành công.
8 | item_add_completed: Sản phẩm đã được thêm vào giỏ hàng.
9 | item_remove_completed: Sản phẩm đã được xoá khỏi giỏ hàng.
10 | item_add_error: Xuất hiện lỗi trong khi thêm sản phẩm vào giỏ hàng.
11 | item_remove_error: Xuất hiện lỗi trong khi loại bỏ sản phẩm khỏi giỏ hàng.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.hr.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Košarica je uspješno ažurirana.
7 | cart_clear_completed: Košarica je uspješno uklonjena.
8 | item_add_completed: Artikal je uspješno dodan u košaricu.
9 | item_remove_completed: Artikal je uspješno izbrisan iz košarice.
10 | item_add_error: Došlo je do pogreške kod dodavanja artikla u košaricu.
11 | item_remove_error: Došlo je do pogreške prilikom brisanja artikla iz košarice.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.el.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Το καλάθι ενημερώθηκε με επιτυχία.
7 | cart_clear_completed: Το καλάθι άδειασε με επιτυχία.
8 | item_add_completed: Το στοιχείο προστέθηκε στο καλάθι.
9 | item_remove_completed: Το στοιχείο αφαιρέθηκε από το καλάθι.
10 | item_add_error: Παρουσιάστηκε σφάλμα κατά την προσθήκη στοιχείου στο καλάθι.
11 | item_remove_error: Παρουσιάστηκε σφάλμα κατά την αφαίρεση στοιχείου από το καλάθι.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.sl.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Košarica je bila uspešno posodobljena.
7 | cart_clear_completed: Košarica je bila uspešno izpraznjena.
8 | item_add_completed: Izdelek je dodan v košarico.
9 | item_remove_completed: Izdelek je bil odstranjen iz košarice.
10 | item_add_error: Med dodajanjem izdelka v košarico je prišlo do napake.
11 | item_remove_error: Med odstranjevanjem izdelka iz košarice je prišlo do napake.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.tr.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Alışveriş sepetiniz başarıyla güncellendi.
7 | cart_clear_completed: Alışveriş sepetiniz başarıyla boşaltıldı.
8 | item_add_completed: Ürün alışveriş spetinize eklendi.
9 | item_remove_completed: Ürün alışveriş sepetinizden çıkartıldı.
10 | item_add_error: Ürün alışveriş sepetinize eklenirken bir hata oluştu.
11 | item_remove_error: Ürün alışveriş sepetinizden çıkartılırken bir hata oluştu.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.de_CH.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Der Warenkorb wurde erfolgreich aktualisiert.
7 | cart_clear_completed: Der Warenkorb wurde geleert.
8 | item_add_completed: Das Produkt wurde zum Warenkorb hinzugefügt.
9 | item_remove_completed: Das Produkt wurde vom Warenkorb entfernt.
10 | item_add_error: Beim hinzufügen des Artikels ist ein Fehler aufgetreten.
11 | item_remove_error: Beim entfernen des Artikels ist ein Fehler aufgetreten.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.es.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: El carrito se ha actualizado correctamente.
7 | cart_clear_completed: El carrito se ha vaciado correctamente.
8 | item_add_completed: El item se ha añadido al carrito.
9 | item_remove_completed: El item se ha borrado del carrito.
10 | item_add_error: Ha ocurrido un error mientras se añadía el item al carrito.
11 | item_remove_error: Ha ocurrido un error mientras se borraba el item del carrito.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.id.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Keranjang Belanja telah berhasil diperbarui.
7 | cart_clear_completed: Keranjang Belanja telah berhasil dihapus.
8 | item_add_completed: Item telah ditambahkan ke keranjang belanja.
9 | item_remove_completed: Item dihapus dari keranjang belanja.
10 | item_add_error: Terjadi kesalahan saat menambahkan item ke keranjang.
11 | item_remove_error: Terjadi kesalahan saat menghapus item dari keranjang.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.da.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Indkøbskurven er blevet opdateret.
7 | cart_clear_completed: Indkøbskurven er blevet tømt.
8 | item_add_completed: Varen er blevet tilføjet til indkøbskurven.
9 | item_remove_completed: Varen er blevet fjernet fra indkøbskurven.
10 | item_add_error: Der opstod en fejl under tilføjelse af varen til indkøbskurven.
11 | item_remove_error: Der opstod en fejl i forsøget på at fjerne en vare fra indkøbskurven.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.af.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Die mandjie is suksesvol bygewerk.
7 | cart_clear_completed: Die mandjie is suksesvol leeg gemaak.
8 | item_add_completed: Item is toegevoeg aan die mandjie.
9 | item_remove_completed: Item is verwijder uit die mandjie.
10 | item_add_error: "'n Probleem het opgetree tydens die toevoeg van die item aan die mandjie."
11 | item_remove_error: "'n Probleem het opgetree tydens die verwyder van die item uit die mandjie."
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.de.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Der Warenkorb wurde erfolgreich gespeichert.
7 | cart_clear_completed: Der Warenkorb wurde erfolgreich geleert.
8 | item_add_completed: Artikel wurde dem Warenkorb hinzugefügt.
9 | item_remove_completed: Artikel wurde aus dem Warenkorb entfernt.
10 | item_add_error: Während des Hinzufügens des Artikels ist ein Fehler aufgetreten.
11 | item_remove_error: Während des Entfernens des Artikels ist ein Fehler aufgetreten.
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.fr.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Le panier a été mis à jour avec succès.
7 | cart_clear_completed: Le panier a été vidé avec succès.
8 | item_add_completed: "L'article a bien été ajouté au panier."
9 | item_remove_completed: "L'article a bien été supprimé du panier."
10 | item_add_error: "Une erreur s'est produite lors de l'ajout de l'article au panier."
11 | item_remove_error: "Une erreur s'est produite lors de la suppression de l'article du panier."
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.ca.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: "La cistella de la compra s'ha actualitzat correctament."
7 | cart_clear_completed: "La cistella de la compra s'ha esborrat amb èxit."
8 | item_add_completed: "El producte s'ha afegit a la cistella."
9 | item_remove_completed: "El producte s'ha esborrat de la cistella."
10 | item_add_error: "S'ha produït un error al afegir el producte a la cistella."
11 | item_remove_error: "S'ha produït un error en treure el producte de la cistella."
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.it.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Il carrello è stato correttamente aggiornato.
7 | cart_clear_completed: Il carrello è stato cancellato con successo.
8 | item_add_completed: "L'articolo è stato aggiunto al carrello."
9 | item_remove_completed: "L'articolo è stato rimosso dal carrello."
10 | item_add_error: "Si è verificato un errore durante l'aggiunta di un elemento al carrello."
11 | item_remove_error: "Si è verificato un errore durante la rimozione dell'articolo dal carrello."
12 |
--------------------------------------------------------------------------------
/Resources/translations/flashes.nl.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius:
5 | cart:
6 | cart_save_completed: Het winkelwagentje is bijgewerkt.
7 | cart_clear_completed: Het winkelwagentje is leeggemaakt.
8 | item_add_completed: Product is toegevoegd aan het winkelwagentje.
9 | item_remove_completed: Product is verwijderd uit het winkelwagentje.
10 | item_add_error: Er is een fout opgetreden bij het toevoegen van een product aan het winkelwagentje.
11 | item_remove_error: Er is een fout opgetreden bij het verwijderen van een product uit het winkelwagentje.
12 |
--------------------------------------------------------------------------------
/Resources/config/routing.yml:
--------------------------------------------------------------------------------
1 | # This file is part of the Sylius package.
2 | # (c) Paweł Jędrzejewski
3 |
4 | sylius_cart_summary:
5 | path: /
6 | defaults: { _controller: sylius.controller.cart:summaryAction }
7 |
8 | sylius_cart_save:
9 | path: /save
10 | defaults: { _controller: sylius.controller.cart:saveAction }
11 |
12 | sylius_cart_clear:
13 | path: /clear
14 | defaults: { _controller: sylius.controller.cart:clearAction }
15 |
16 | sylius_cart_item_add:
17 | path: /add
18 | defaults: { _controller: sylius.controller.cart_item:addAction }
19 |
20 | sylius_cart_item_remove:
21 | path: /{id}/remove
22 | defaults: { _controller: sylius.controller.cart_item:removeAction }
23 |
--------------------------------------------------------------------------------
/Resources/config/driver/doctrine/orm.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
18 |
19 |
20 | Sylius\Bundle\CartBundle\Doctrine\ORM\CartRepository
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Resources/config/doctrine/model/CartItem.orm.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Resources/config/doctrine/model/Cart.orm.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/spec/Twig/CartExtensionSpec.php:
--------------------------------------------------------------------------------
1 |
19 | */
20 | final class CartExtensionSpec extends ObjectBehavior
21 | {
22 | function let(CartHelper $helper)
23 | {
24 | $this->beConstructedWith($helper);
25 | }
26 |
27 | function it_is_initializable()
28 | {
29 | $this->shouldHaveType('Sylius\Bundle\CartBundle\Twig\CartExtension');
30 | }
31 |
32 | function it_is_a_twig_extension()
33 | {
34 | $this->shouldHaveType('Twig_Extension');
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/Resources/config/twig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
18 |
19 |
20 | Sylius\Bundle\CartBundle\Twig\CartExtension
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Resources/meta/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011-2016 Paweł Jędrzejewski
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is furnished
8 | to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
20 |
--------------------------------------------------------------------------------
/Form/Type/CartType.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | class CartType extends AbstractResourceType
24 | {
25 | /**
26 | * {@inheritdoc}
27 | */
28 | public function buildForm(FormBuilderInterface $builder, array $options)
29 | {
30 | $builder
31 | ->add('items', 'collection', [
32 | 'type' => 'sylius_cart_item',
33 | ])
34 | ->add('notes')
35 | ;
36 | }
37 |
38 | /**
39 | * {@inheritdoc}
40 | */
41 | public function getName()
42 | {
43 | return 'sylius_cart';
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/Command/PurgeCartsCommand.php:
--------------------------------------------------------------------------------
1 |
22 | */
23 | class PurgeCartsCommand extends ContainerAwareCommand
24 | {
25 | protected function configure()
26 | {
27 | $this
28 | ->setName('sylius:cart:purge')
29 | ->setDescription('Purge expired carts')
30 | ;
31 | }
32 |
33 | protected function execute(InputInterface $input, OutputInterface $output)
34 | {
35 | $output->writeln('Purging expired carts...');
36 |
37 | $cartsPurger = $this->getContainer()->get('sylius.cart.purger');
38 | $cartsPurger->purge();
39 |
40 | $output->writeln('Expired carts purged.');
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/spec/Purger/ExpiredCartsPurgerSpec.php:
--------------------------------------------------------------------------------
1 | beConstructedWith($manager, $repository);
24 | }
25 |
26 | function it_is_initializable()
27 | {
28 | $this->shouldHaveType('Sylius\Bundle\CartBundle\Purger\ExpiredCartsPurger');
29 | }
30 |
31 | function it_purge_cart($manager, $repository, CartInterface $cart)
32 | {
33 | $repository->findExpiredCarts()->shouldBeCalled()->willReturn([$cart]);
34 | $manager->remove($cart)->shouldBeCalled();
35 | $manager->flush()->shouldBeCalled();
36 |
37 | $this->purge();
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Resources/config/templating.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
18 |
19 |
20 | Sylius\Bundle\CartBundle\Templating\Helper\CartHelper
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/DependencyInjection/Compiler/RegisterCartContextsPass.php:
--------------------------------------------------------------------------------
1 |
20 | */
21 | final class RegisterCartContextsPass implements CompilerPassInterface
22 | {
23 | /**
24 | * {@inheritdoc}
25 | */
26 | public function process(ContainerBuilder $container)
27 | {
28 | if (!$container->has('sylius.context.cart')) {
29 | return;
30 | }
31 |
32 | $cartContext = $container->findDefinition('sylius.context.cart');
33 |
34 | foreach ($container->findTaggedServiceIds('sylius.cart_context') as $id => $attributes) {
35 | $priority = isset($attributes[0]['priority']) ? (int) $attributes[0]['priority'] : 0;
36 |
37 | $cartContext->addMethodCall('addContext', [new Reference($id), $priority]);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/Resources/config/validation.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/SyliusCartBundle.php:
--------------------------------------------------------------------------------
1 |
21 | */
22 | class SyliusCartBundle extends AbstractResourceBundle
23 | {
24 | /**
25 | * {@inheritdoc}
26 | */
27 | public function getSupportedDrivers()
28 | {
29 | return [
30 | SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
31 | ];
32 | }
33 |
34 | /**
35 | * {@inheritdoc}
36 | */
37 | public function build(ContainerBuilder $container)
38 | {
39 | parent::build($container);
40 |
41 | $container->addCompilerPass(new RegisterCartContextsPass());
42 | }
43 |
44 | /**
45 | * {@inheritdoc}
46 | */
47 | protected function getBundlePrefix()
48 | {
49 | return 'sylius_order';
50 | }
51 |
52 | /**
53 | * {@inheritdoc}
54 | */
55 | protected function getModelNamespace()
56 | {
57 | return 'Sylius\Component\Cart\Model';
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sylius/cart-bundle",
3 | "type": "symfony-bundle",
4 | "description": "Cart engine for your next Symfony2 application.",
5 | "keywords": ["shop", "ecommerce", "cart", "carts", "sylius"],
6 | "homepage": "http://sylius.org",
7 | "license": "MIT",
8 | "authors": [
9 | {
10 | "name": "Paweł Jędrzejewski",
11 | "homepage": "http://pjedrzejewski.com"
12 | },
13 | {
14 | "name": "Sylius project",
15 | "homepage": "http://sylius.org"
16 | },
17 | {
18 | "name": "Community contributions",
19 | "homepage": "http://github.com/Sylius/Sylius/contributors"
20 | }
21 | ],
22 | "require": {
23 | "php": "^5.6|^7.0",
24 |
25 | "sylius/cart": "^1.0",
26 | "sylius/order-bundle": "^1.0",
27 | "symfony/framework-bundle": "^2.8"
28 | },
29 | "require-dev": {
30 | "phpspec/phpspec": "^3.0",
31 | "symfony/form": "^2.8",
32 | "symfony/validator": "^2.8",
33 | "doctrine/orm": "^2.4.8,<2.5",
34 | "twig/twig": "^1.0"
35 | },
36 | "config": {
37 | "bin-dir": "bin"
38 | },
39 | "autoload": {
40 | "psr-4": { "Sylius\\Bundle\\CartBundle\\": "" }
41 | },
42 | "autoload-dev": {
43 | "psr-4": { "Sylius\\Bundle\\CartBundle\\spec\\": "spec/" }
44 | },
45 | "minimum-stability": "dev",
46 | "prefer-stable": true,
47 | "repositories": [
48 | {
49 | "type": "path",
50 | "url": "../../*/*"
51 | }
52 | ],
53 | "extra": {
54 | "branch-alias": {
55 | "dev-master": "1.0-dev"
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/Purger/ExpiredCartsPurger.php:
--------------------------------------------------------------------------------
1 |
23 | */
24 | class ExpiredCartsPurger implements PurgerInterface
25 | {
26 | /**
27 | * Cart manager.
28 | *
29 | * @var ObjectManager
30 | */
31 | protected $manager;
32 |
33 | /**
34 | * Cart repository.
35 | *
36 | * @var CartRepositoryInterface
37 | */
38 | protected $repository;
39 |
40 | public function __construct(ObjectManager $manager, CartRepositoryInterface $repository)
41 | {
42 | $this->manager = $manager;
43 | $this->repository = $repository;
44 | }
45 |
46 | /**
47 | * {@inheritdoc}
48 | */
49 | public function purge()
50 | {
51 | $cartsToPurge = $this->repository->findExpiredCarts();
52 |
53 | foreach ($cartsToPurge as $cart) {
54 | $this->purgeCart($cart);
55 | }
56 |
57 | $this->manager->flush();
58 | }
59 |
60 | /**
61 | * Purge a cart
62 | *
63 | * @param CartInterface $cart
64 | */
65 | protected function purgeCart(CartInterface $cart)
66 | {
67 | $this->manager->remove($cart);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/spec/Command/PurgeCartsCommandSpec.php:
--------------------------------------------------------------------------------
1 | shouldHaveType('Sylius\Bundle\CartBundle\Command\PurgeCartsCommand');
26 | }
27 |
28 | public function it_is_a_command()
29 | {
30 | $this->shouldHaveType(ContainerAwareCommand::class);
31 | }
32 |
33 | public function it_has_a_name()
34 | {
35 | $this->getName()->shouldReturn('sylius:cart:purge');
36 | }
37 |
38 | public function it_imports_the_vet(
39 | ContainerInterface $container,
40 | InputInterface $input,
41 | OutputInterface $output,
42 | PurgerInterface $purger
43 | ) {
44 | $output->writeln('Purging expired carts...')->shouldBeCalled();
45 |
46 | $container->get('sylius.cart.purger')->shouldBeCalled()->willReturn($purger);
47 | $purger->purge()->shouldBeCalled();
48 |
49 | $output->writeln('Expired carts purged.')->shouldBeCalled();
50 |
51 | $this->setContainer($container);
52 | $this->run($input, $output);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/Form/Type/CartItemType.php:
--------------------------------------------------------------------------------
1 |
20 | */
21 | class CartItemType extends AbstractResourceType
22 | {
23 | /**
24 | * @var DataMapperInterface
25 | */
26 | protected $orderItemQuantityDataMapper;
27 |
28 | /**
29 | * @param string $dataClass
30 | * @param array $validationGroups
31 | * @param DataMapperInterface $orderItemQuantityDataMapper
32 | */
33 | public function __construct($dataClass, array $validationGroups = [], DataMapperInterface $orderItemQuantityDataMapper)
34 | {
35 | parent::__construct($dataClass, $validationGroups);
36 |
37 | $this->orderItemQuantityDataMapper = $orderItemQuantityDataMapper;
38 | }
39 |
40 | /**
41 | * {@inheritdoc}
42 | */
43 | public function buildForm(FormBuilderInterface $builder, array $options)
44 | {
45 | $builder
46 | ->add('quantity', 'integer', [
47 | 'attr' => ['min' => 1],
48 | 'label' => 'sylius.form.cart_item.quantity',
49 | ])
50 | ->setDataMapper($this->orderItemQuantityDataMapper);
51 | }
52 |
53 | /**
54 | * {@inheritdoc}
55 | */
56 | public function getName()
57 | {
58 | return 'sylius_cart_item';
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/spec/Form/Type/CartTypeSpec.php:
--------------------------------------------------------------------------------
1 |
21 | */
22 | final class CartTypeSpec extends ObjectBehavior
23 | {
24 | function let()
25 | {
26 | $this->beConstructedWith('Cart', ['sylius']);
27 | }
28 |
29 | function it_is_initializable()
30 | {
31 | $this->shouldHaveType('Sylius\Bundle\CartBundle\Form\Type\CartType');
32 | }
33 |
34 | function it_is_a_form_type()
35 | {
36 | $this->shouldImplement(FormTypeInterface::class);
37 | }
38 |
39 | function it_builds_form_with_items_collection(FormBuilder $builder)
40 | {
41 | $builder
42 | ->add('items', 'collection', ['type' => 'sylius_cart_item'])
43 | ->willReturn($builder)
44 | ;
45 |
46 | $builder
47 | ->add('notes')
48 | ->willReturn($builder)
49 | ;
50 |
51 | $this->buildForm($builder, []);
52 | }
53 |
54 | function it_defines_assigned_data_class(OptionsResolver $resolver)
55 | {
56 | $resolver
57 | ->setDefaults([
58 | 'data_class' => 'Cart',
59 | 'validation_groups' => ['sylius'],
60 | ])
61 | ->shouldBeCalled()
62 | ;
63 |
64 | $this->configureOptions($resolver);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Doctrine/ORM/CartRepository.php:
--------------------------------------------------------------------------------
1 |
20 | * @author Alexandre Bacco
21 | */
22 | class CartRepository extends OrderRepository implements CartRepositoryInterface
23 | {
24 | /**
25 | * {@inheritdoc}
26 | */
27 | public function findCartById($id)
28 | {
29 | return $this->createQueryBuilder('o')
30 | ->where('o.id = :id')
31 | ->andWhere('o.state = :state')
32 | ->setParameter('state', OrderInterface::STATE_CART)
33 | ->setParameter('id', $id)
34 | ->getQuery()
35 | ->getOneOrNullResult()
36 | ;
37 | }
38 |
39 | /**
40 | * {@inheritdoc}
41 | */
42 | public function findExpiredCarts()
43 | {
44 | $queryBuilder = $this->createQueryBuilder('o')
45 | ->leftJoin('o.items', 'item')
46 | ->addSelect('item')
47 | ;
48 |
49 | $queryBuilder
50 | ->andWhere($queryBuilder->expr()->lt('o.expiresAt', ':now'))
51 | ->andWhere($queryBuilder->expr()->eq('o.state', ':state'))
52 | ->setParameter('now', new \DateTime())
53 | ->setParameter('state', OrderInterface::STATE_CART)
54 | ;
55 |
56 | return $queryBuilder->getQuery()->getResult();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | CHANGELOG
2 | =========
3 |
4 | ### v0.10.0
5 |
6 | * Twig extension was renamed from `SyliusCartExtension` into `CartExtension`,
7 | also the service name was changed from `sylius.cart_twig` to `sylius.twig.extension.cart`.
8 |
9 | ### v0.9.0
10 |
11 | * Release before components.
12 | * Fixed double cart refresh.
13 |
14 | ### v0.8.0
15 |
16 | * Convert translation files to YAML.
17 |
18 | ### v0.7.0
19 |
20 | * Introduce cart provider events.
21 |
22 | ### v0.6.0
23 |
24 | * Release before components introduction. (delayed)
25 |
26 | ### v0.5.0
27 |
28 | * Symfony 2.3 compatible version.
29 | * Removed `Entity` classes.
30 | * Based on SyliusSalesBundle order model.
31 |
32 | ### v0.4.0
33 |
34 | * Last Symfony 2.2 compatible version.
35 |
36 | ### v0.3.0
37 |
38 | * Remove `CartOperator` & `CartOperatorInterface`.
39 | * Introduce `SyliusCartEvents` & event listeners.
40 | * Removed the ``sylius_cart`` prefix from services and models, used ``sylius`` instead.
41 | * All money values are represented as integers.
42 |
43 | ### v0.2.0
44 |
45 | * Introduce default cart entity.
46 | * Use Doctrine RTEL to map interfaces instead of real entities.
47 | * Rename `CartController::showAction` to `CartController::summaryAction`.
48 | * Renamed `SyliusCartBundle:Cart:show.html` template to ``SyliusCartBundle:Cart:summary.html`.
49 | * Add base controller.
50 |
51 | ### v0.1.0
52 |
53 | * First development release.
54 | * Introduced ItemResolvingException.
55 | * More complete set of [phpspec2](http://phpspec.net) examples.
56 | * Changed configuration schema.
57 | * Bundle now uses [SyliusResourceBundle](http://github.com/Sylius/SyliusResourceBundle) for model persistence.
58 | * Models now depend on Doctrine collections.
59 | * New controller.
60 | * Renamed **Item** to **CartItem**.
61 | * Renamed **ItemType** to **CartItemType**.
62 | * Introduce specs with [phpspec2](http://phpspec.net).
63 | * Renamed **CartFormType** to **CartType** to be consistent.
64 |
--------------------------------------------------------------------------------
/spec/Form/Type/CartItemTypeSpec.php:
--------------------------------------------------------------------------------
1 |
23 | */
24 | final class CartItemTypeSpec extends ObjectBehavior
25 | {
26 | function let(DataMapperInterface $orderItemQuantityDataMapper)
27 | {
28 | $this->beConstructedWith('CartItem', ['sylius'], $orderItemQuantityDataMapper);
29 | }
30 |
31 | function it_is_initializable()
32 | {
33 | $this->shouldHaveType('Sylius\Bundle\CartBundle\Form\Type\CartItemType');
34 | }
35 |
36 | function it_is_a_form_type()
37 | {
38 | $this->shouldImplement(FormTypeInterface::class);
39 | }
40 |
41 | function it_builds_form_with_quantity_field($orderItemQuantityDataMapper, FormBuilder $builder)
42 | {
43 | $builder
44 | ->add('quantity', 'integer', Argument::any())
45 | ->shouldBeCalled()
46 | ->willReturn($builder)
47 | ;
48 |
49 | $builder
50 | ->setDataMapper($orderItemQuantityDataMapper)
51 | ->shouldBeCalled()
52 | ->willReturn($builder)
53 | ;
54 |
55 | $this->buildForm($builder, []);
56 | }
57 |
58 | function it_defines_assigned_data_class(OptionsResolver $resolver)
59 | {
60 | $resolver
61 | ->setDefaults([
62 | 'data_class' => 'CartItem',
63 | 'validation_groups' => ['sylius'],
64 | ])
65 | ->shouldBeCalled()
66 | ;
67 |
68 | $this->configureOptions($resolver);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Context/SessionBasedCartContext.php:
--------------------------------------------------------------------------------
1 |
21 | */
22 | final class SessionBasedCartContext implements CartContextInterface
23 | {
24 | /**
25 | * @var SessionInterface
26 | */
27 | private $session;
28 |
29 | /**
30 | * @var string
31 | */
32 | private $sessionKeyName;
33 |
34 | /**
35 | * @var CartRepositoryInterface
36 | */
37 | private $cartRepository;
38 |
39 | /**
40 | * @param SessionInterface $session
41 | * @param string $sessionKeyName
42 | * @param CartRepositoryInterface $cartRepository
43 | */
44 | public function __construct(SessionInterface $session, $sessionKeyName, CartRepositoryInterface $cartRepository)
45 | {
46 | $this->session = $session;
47 | $this->sessionKeyName = $sessionKeyName;
48 | $this->cartRepository = $cartRepository;
49 | }
50 |
51 | /**
52 | * {@inheritdoc}
53 | */
54 | public function getCart()
55 | {
56 | if (!$this->session->has($this->sessionKeyName)) {
57 | throw new CartNotFoundException('Sylius was not able to find the cart in session');
58 | }
59 |
60 | $cart = $this->cartRepository->findCartById($this->session->get($this->sessionKeyName));
61 |
62 | if (null === $cart) {
63 | $this->session->remove($this->sessionKeyName);
64 |
65 | throw new CartNotFoundException('Sylius was not able to find the cart in session');
66 | }
67 |
68 | return $cart;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/Controller/Controller.php:
--------------------------------------------------------------------------------
1 |
23 | */
24 | abstract class Controller extends ResourceController
25 | {
26 | /**
27 | * @param RequestConfiguration $configuration
28 | *
29 | * @return RedirectResponse
30 | */
31 | protected function redirectToCartSummary(RequestConfiguration $configuration)
32 | {
33 | if (null === $configuration->getParameters()->get('redirect')) {
34 | return $this->redirectHandler->redirectToRoute($configuration, $this->getCartSummaryRoute());
35 | }
36 |
37 | return $this->redirectHandler->redirectToRoute($configuration, $configuration->getParameters()->get('redirect'));
38 | }
39 |
40 | /**
41 | * @return string
42 | */
43 | protected function getCartSummaryRoute()
44 | {
45 | return 'sylius_cart_summary';
46 | }
47 |
48 | /**
49 | * @return CartInterface
50 | */
51 | protected function getCurrentCart()
52 | {
53 | return $this->getContext()->getCart();
54 | }
55 |
56 | /**
57 | * @return CartContextInterface
58 | */
59 | protected function getContext()
60 | {
61 | return $this->container->get('sylius.context.cart');
62 | }
63 |
64 | /**
65 | * @return EventDispatcherInterface
66 | */
67 | protected function getEventDispatcher()
68 | {
69 | return $this->container->get('event_dispatcher');
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Twig/CartExtension.php:
--------------------------------------------------------------------------------
1 |
20 | */
21 | class CartExtension extends \Twig_Extension
22 | {
23 | /**
24 | * @var CartHelper
25 | */
26 | private $helper;
27 |
28 | /**
29 | * @param CartHelper $helper
30 | */
31 | public function __construct(CartHelper $helper)
32 | {
33 | $this->helper = $helper;
34 | }
35 |
36 | /**
37 | * {@inheritdoc}
38 | */
39 | public function getFunctions()
40 | {
41 | return [
42 | new \Twig_SimpleFunction('sylius_cart_exists', [$this, 'hasCart']),
43 | new \Twig_SimpleFunction('sylius_cart_get', [$this, 'getCurrentCart']),
44 | new \Twig_SimpleFunction('sylius_cart_form', [$this, 'getItemFormView']),
45 | ];
46 | }
47 |
48 | /**
49 | * Returns current cart.
50 | *
51 | * @return null|CartInterface
52 | */
53 | public function getCurrentCart()
54 | {
55 | return $this->helper->getCurrentCart();
56 | }
57 |
58 | /**
59 | * Check if a cart exists.
60 | *
61 | * @return bool
62 | */
63 | public function hasCart()
64 | {
65 | return $this->helper->hasCart();
66 | }
67 |
68 | /**
69 | * Returns cart item form view.
70 | *
71 | * @param array $options
72 | *
73 | * @return FormView
74 | */
75 | public function getItemFormView(array $options = [])
76 | {
77 | return $this->helper->getItemFormView($options);
78 | }
79 |
80 | /**
81 | * {@inheritdoc}
82 | */
83 | public function getName()
84 | {
85 | return 'sylius_cart';
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/Resources/config/services.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
18 |
19 |
20 | Sylius\Bundle\CartBundle\EventListener\SessionCartSubscriber
21 |
22 | Sylius\Bundle\CartBundle\Purger\ExpiredCartsPurger
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 | _sylius.cart
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | _sylius.cart
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/spec/Context/SessionBasedCartContextSpec.php:
--------------------------------------------------------------------------------
1 |
23 | */
24 | final class SessionBasedCartContextSpec extends ObjectBehavior
25 | {
26 | function let(SessionInterface $session, CartRepositoryInterface $cartRepository)
27 | {
28 | $this->beConstructedWith($session, 'session_key_name', $cartRepository);
29 | }
30 |
31 | function it_is_initializable()
32 | {
33 | $this->shouldHaveType('Sylius\Bundle\CartBundle\Context\SessionBasedCartContext');
34 | }
35 |
36 | function it_implements_cart_context_interface()
37 | {
38 | $this->shouldImplement(CartContextInterface::class);
39 | }
40 |
41 | function it_returns_cart_based_on_id_stored_in_session(
42 | SessionInterface $session,
43 | CartRepositoryInterface $cartRepository,
44 | CartInterface $cart
45 | ) {
46 | $session->has('session_key_name')->willReturn(true);
47 | $session->get('session_key_name')->willReturn(12345);
48 | $cartRepository->findCartById(12345)->willReturn($cart);
49 |
50 | $this->getCart()->shouldReturn($cart);
51 | }
52 |
53 | function it_throws_cart_not_found_exception_if_session_key_does_not_exist(SessionInterface $session)
54 | {
55 | $session->has('session_key_name')->willReturn(false);
56 |
57 | $this->shouldThrow(CartNotFoundException::class)->during('getCart');
58 | }
59 |
60 | function it_throws_cart_not_found_exception_and_removes_id_from_session_when_cart_is_not_found(
61 | SessionInterface $session,
62 | CartRepositoryInterface $cartRepository
63 | ) {
64 | $session->has('session_key_name')->willReturn(true);
65 | $session->get('session_key_name')->willReturn(12345);
66 | $cartRepository->findCartById(12345)->willReturn(null);
67 |
68 | $session->remove('session_key_name')->shouldBeCalled();
69 |
70 | $this->shouldThrow(CartNotFoundException::class)->during('getCart');
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/Templating/Helper/CartHelper.php:
--------------------------------------------------------------------------------
1 | cartContext = $cartContext;
53 | $this->cartItemFactory = $cartItemFactory;
54 | $this->formFactory = $formFactory;
55 | $this->orderItemQuantityModifier = $orderItemQuantityModifier;
56 | }
57 |
58 | /**
59 | * @return CartInterface|null
60 | */
61 | public function getCurrentCart()
62 | {
63 | return $this->cartContext->getCart();
64 | }
65 |
66 | /**
67 | * @param array $options
68 | *
69 | * @return FormView
70 | */
71 | public function getItemFormView(array $options = [])
72 | {
73 | $cartItem = $this->cartItemFactory->createNew();
74 | $this->orderItemQuantityModifier->modify($cartItem, 1);
75 |
76 | $form = $this->formFactory->create('sylius_cart_item', $cartItem, $options);
77 |
78 | return $form->createView();
79 | }
80 |
81 | /**
82 | * {@inheritdoc}
83 | */
84 | public function getName()
85 | {
86 | return 'sylius_cart';
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/EventListener/SessionCartSubscriber.php:
--------------------------------------------------------------------------------
1 |
23 | */
24 | final class SessionCartSubscriber implements EventSubscriberInterface
25 | {
26 | /**
27 | * @var CartContextInterface
28 | */
29 | private $cartContext;
30 |
31 | /**
32 | * @var string
33 | */
34 | private $sessionKeyName;
35 |
36 | /**
37 | * @param CartContextInterface $cartContext
38 | * @param string $sessionKeyName
39 | */
40 | public function __construct(CartContextInterface $cartContext, $sessionKeyName)
41 | {
42 | $this->cartContext = $cartContext;
43 | $this->sessionKeyName = $sessionKeyName;
44 | }
45 |
46 | /**
47 | * {@inheritdoc}
48 | */
49 | public static function getSubscribedEvents()
50 | {
51 | return [
52 | KernelEvents::RESPONSE => ['onKernelResponse'],
53 | ];
54 | }
55 |
56 | /**
57 | * @param FilterResponseEvent $event
58 | */
59 | public function onKernelResponse(FilterResponseEvent $event)
60 | {
61 | if (!$event->isMasterRequest()) {
62 | return;
63 | }
64 |
65 | /** @var Request $request */
66 | $request = $event->getRequest();
67 | // Hacky hack. Until there is a better solution.
68 | if (!$this->isHtmlRequest($request)) {
69 | return;
70 | }
71 |
72 | try {
73 | $cart = $this->cartContext->getCart();
74 | } catch (CartNotFoundException $exception) {
75 | return;
76 | }
77 |
78 | if (null !== $cart && null !== $cart->getId() && null !== $cart->getChannel()) {
79 | $session = $request->getSession();
80 |
81 | $session->set(
82 | sprintf('%s.%s', $this->sessionKeyName, $cart->getChannel()->getCode()),
83 | $cart->getId()
84 | );
85 | }
86 | }
87 |
88 | /**
89 | * @param Request $request
90 | *
91 | * @return bool
92 | */
93 | private function isHtmlRequest(Request $request)
94 | {
95 | return 'html' === $request->getRequestFormat();
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/Tests/DependencyInjection/Compiler/RegisterCartContextsPassTest.php:
--------------------------------------------------------------------------------
1 |
23 | */
24 | class RegisterCartContextsPassTest extends AbstractCompilerPassTestCase
25 | {
26 | /**
27 | * @test
28 | */
29 | public function it_registers_defined_cart_contexts()
30 | {
31 | $this->setDefinition('sylius.context.cart', new Definition());
32 |
33 | $cartContextDefinition = new Definition();
34 | $cartContextDefinition->addTag('sylius.cart_context');
35 | $this->setDefinition('sylius.context.cart_new', $cartContextDefinition);
36 |
37 | $this->compile();
38 |
39 | $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
40 | 'sylius.context.cart',
41 | 'addContext',
42 | [
43 | new Reference('sylius.context.cart_new'),
44 | 0
45 | ]
46 | );
47 | }
48 |
49 | /**
50 | * @test
51 | */
52 | public function it_does_not_register_cart_contexts_if_there_is_no_cart_contexts()
53 | {
54 | $this->setDefinition('sylius.context.cart', new Definition());
55 |
56 | $this->compile();
57 |
58 | $this->assertContainerBuilderDoesNotHaveServiceDefinitionWithMethodCall(
59 | 'sylius.context.cart',
60 | 'addContext'
61 | );
62 | }
63 |
64 | /**
65 | * {@inheritdoc}
66 | */
67 | public function registerCompilerPass(ContainerBuilder $container)
68 | {
69 | $container->addCompilerPass(new RegisterCartContextsPass());
70 | }
71 |
72 | /**
73 | * @param string $serviceId
74 | * @param string $method
75 | */
76 | private function assertContainerBuilderDoesNotHaveServiceDefinitionWithMethodCall($serviceId, $method)
77 | {
78 | $definition = $this->container->findDefinition($serviceId);
79 |
80 | self::assertThat(
81 | $definition,
82 | new \PHPUnit_Framework_Constraint_Not(new DefinitionHasMethodCallConstraint($method))
83 | );
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/DependencyInjection/SyliusCartExtension.php:
--------------------------------------------------------------------------------
1 |
25 | * @author Saša Stamenković
26 | * @author Jérémy Leherpeur
27 | */
28 | class SyliusCartExtension extends AbstractResourceExtension implements PrependExtensionInterface
29 | {
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public function load(array $config, ContainerBuilder $container)
34 | {
35 | $config = $this->processConfiguration($this->getConfiguration($config, $container), $config);
36 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
37 |
38 | $loader->load(sprintf('driver/%s.xml', $config['driver']));
39 |
40 | $this->registerResources('sylius', $config['driver'], $config['resources'], $container);
41 |
42 | $configFiles = [
43 | 'services.xml',
44 | 'templating.xml',
45 | 'twig.xml',
46 | ];
47 |
48 | foreach ($configFiles as $configFile) {
49 | $loader->load($configFile);
50 | }
51 |
52 | $definition = $container->getDefinition('sylius.form.type.cart_item');
53 | $definition->addArgument(new Reference('sylius.form.data_mapper.order_item_quantity'));
54 | }
55 |
56 | /**
57 | * {@inheritdoc}
58 | */
59 | public function prepend(ContainerBuilder $container)
60 | {
61 | if (!$container->hasExtension('sylius_order')) {
62 | throw new \RuntimeException('Please install and configure SyliusOrderBundle in order to use SyliusCartBundle.');
63 | }
64 |
65 | $container->prependExtensionConfig('sylius_order', [
66 | 'resources' => [
67 | 'order' => [
68 | 'classes' => [
69 | 'model' => Cart::class,
70 | ],
71 | ],
72 | 'order_item' => [
73 | 'classes' => [
74 | 'model' => CartItem::class,
75 | ],
76 | ],
77 | ], ]
78 | );
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/spec/Templating/Helper/CartHelperSpec.php:
--------------------------------------------------------------------------------
1 | beConstructedWith($cartContext, $itemFactory, $formFactory, $orderItemQuantityModifier);
34 | }
35 |
36 | function it_is_initializable()
37 | {
38 | $this->shouldHaveType('Sylius\Bundle\CartBundle\Templating\Helper\CartHelper');
39 | }
40 |
41 | function it_is_a_twig_extension()
42 | {
43 | $this->shouldHaveType(Helper::class);
44 | }
45 |
46 | function its_getCurrentCart_returns_current_cart_via_provider($cartContext, CartInterface $cart)
47 | {
48 | $cartContext->getCart()->willReturn($cart);
49 |
50 | $this->getCurrentCart()->shouldReturn($cart);
51 | }
52 |
53 | function its_getItemFormView_returns_a_form_view_of_cart_item_form(
54 | $formFactory,
55 | $itemFactory,
56 | $orderItemQuantityModifier,
57 | CartItemInterface $item,
58 | FormInterface $form,
59 | FormView $formView
60 | ) {
61 | $itemFactory->createNew()->shouldBeCalled()->willReturn($item);
62 | $orderItemQuantityModifier->modify($item, 1)->shouldBeCalled();
63 |
64 | $formFactory->create('sylius_cart_item', $item, [])->shouldBeCalled()->willReturn($form);
65 | $form->createView()->willReturn($formView);
66 |
67 | $this->getItemFormView()->shouldReturn($formView);
68 | }
69 |
70 | function its_getItemFormView_uses_given_options_when_creating_form(
71 | $itemFactory,
72 | $formFactory,
73 | $orderItemQuantityModifier,
74 | FormInterface $form,
75 | FormView $formView,
76 | CartItemInterface $item
77 | ) {
78 | $itemFactory->createNew()->shouldBeCalled()->willReturn($item);
79 | $orderItemQuantityModifier->modify($item, 1)->shouldBeCalled();
80 |
81 | $formFactory->create('sylius_cart_item', $item, ['foo' => 'bar'])->shouldBeCalled()->willReturn($form);
82 | $form->createView()->willReturn($formView);
83 |
84 | $this->getItemFormView(['foo' => 'bar'])->shouldReturn($formView);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/Controller/CartController.php:
--------------------------------------------------------------------------------
1 |
24 | * @author Grzegorz Sadowski
25 | */
26 | class CartController extends Controller
27 | {
28 | /**
29 | * @param Request $request
30 | *
31 | * @return Response
32 | */
33 | public function summaryAction(Request $request)
34 | {
35 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
36 |
37 | $cart = $this->getCurrentCart();
38 | $form = $this->resourceFormFactory->create($configuration, $cart);
39 |
40 | $view = View::create()
41 | ->setTemplate($configuration->getTemplate('summary.html'))
42 | ->setData([
43 | 'cart' => $cart,
44 | 'form' => $form->createView(),
45 | ])
46 | ;
47 |
48 | return $this->viewHandler->handle($configuration, $view);
49 | }
50 |
51 | /**
52 | * @param Request $request
53 | *
54 | * @return Response
55 | */
56 | public function saveAction(Request $request)
57 | {
58 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
59 |
60 | $this->isGrantedOr403($configuration, ResourceActions::UPDATE);
61 | $resource = $this->getCurrentCart();
62 |
63 | $form = $this->resourceFormFactory->create($configuration, $resource);
64 |
65 | if (in_array($request->getMethod(), ['POST', 'PUT', 'PATCH']) && $form->submit($request, !$request->isMethod('PATCH'))->isValid()) {
66 | $resource = $form->getData();
67 |
68 | $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::UPDATE, $configuration, $resource);
69 |
70 | if ($event->isStopped() && !$configuration->isHtmlRequest()) {
71 | throw new HttpException($event->getErrorCode(), $event->getMessage());
72 | }
73 | if ($event->isStopped()) {
74 | $this->flashHelper->addFlashFromEvent($configuration, $event);
75 |
76 | return $this->redirectHandler->redirectToResource($configuration, $resource);
77 | }
78 |
79 | if ($configuration->hasStateMachine()) {
80 | $this->stateMachine->apply($configuration, $resource);
81 | }
82 |
83 | $this->eventDispatcher->dispatchPostEvent(ResourceActions::UPDATE, $configuration, $resource);
84 |
85 | if (!$configuration->isHtmlRequest()) {
86 | return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
87 | }
88 |
89 | $this->getEventDispatcher()->dispatch(SyliusCartEvents::CART_CHANGE, new GenericEvent($resource));
90 | $this->manager->flush();
91 |
92 | $this->flashHelper->addSuccessFlash($configuration, ResourceActions::UPDATE, $resource);
93 |
94 | return $this->redirectHandler->redirectToResource($configuration, $resource);
95 | }
96 |
97 | if (!$configuration->isHtmlRequest()) {
98 | return $this->viewHandler->handle($configuration, View::create($form, Response::HTTP_BAD_REQUEST));
99 | }
100 |
101 | $view = View::create()
102 | ->setData([
103 | 'configuration' => $configuration,
104 | $this->metadata->getName() => $resource,
105 | 'form' => $form->createView(),
106 | ])
107 | ->setTemplate($configuration->getTemplate(ResourceActions::UPDATE . '.html'))
108 | ;
109 |
110 | return $this->viewHandler->handle($configuration, $view);
111 | }
112 |
113 | /**
114 | * @param Request $request
115 | *
116 | * @return Response
117 | */
118 | public function clearAction(Request $request)
119 | {
120 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
121 |
122 | $this->isGrantedOr403($configuration, ResourceActions::DELETE);
123 | $resource = $this->getCurrentCart();
124 |
125 | $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource);
126 |
127 | if ($event->isStopped() && !$configuration->isHtmlRequest()) {
128 | throw new HttpException($event->getErrorCode(), $event->getMessage());
129 | }
130 | if ($event->isStopped()) {
131 | $this->flashHelper->addFlashFromEvent($configuration, $event);
132 |
133 | return $this->redirectHandler->redirectToIndex($configuration, $resource);
134 | }
135 |
136 | $this->repository->remove($resource);
137 | $this->eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource);
138 |
139 | if (!$configuration->isHtmlRequest()) {
140 | return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
141 | }
142 |
143 | $this->flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource);
144 |
145 | return $this->redirectHandler->redirectToIndex($configuration, $resource);
146 | }
147 | }
148 |
--------------------------------------------------------------------------------
/Controller/CartItemController.php:
--------------------------------------------------------------------------------
1 |
28 | * @author Grzegorz Sadowski
29 | */
30 | class CartItemController extends Controller
31 | {
32 | /**
33 | * @param Request $request
34 | *
35 | * @return Response
36 | */
37 | public function addAction(Request $request)
38 | {
39 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
40 |
41 | $this->isGrantedOr403($configuration, ResourceActions::CREATE);
42 | $newResource = $this->newResourceFactory->create($configuration, $this->factory);
43 |
44 | $this->getItemQuantityModifier()->modify($newResource, 1);
45 |
46 | $form = $this->resourceFormFactory->create($configuration, $newResource);
47 |
48 | if ($request->isMethod('POST') && $form->submit($request)->isValid()) {
49 | $newResource = $form->getData();
50 |
51 | $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource);
52 |
53 | if ($event->isStopped() && !$configuration->isHtmlRequest()) {
54 | throw new HttpException($event->getErrorCode(), $event->getMessage());
55 | }
56 | if ($event->isStopped()) {
57 | $this->flashHelper->addFlashFromEvent($configuration, $event);
58 |
59 | return $this->redirectHandler->redirectToIndex($configuration, $newResource);
60 | }
61 |
62 | $cart = $this->getCurrentCart();
63 | $this->getCartModifier()->addToCart($cart, $newResource);
64 |
65 | $cartManager = $this->getCartManager();
66 | $cartManager->persist($cart);
67 | $cartManager->flush();
68 |
69 | $this->eventDispatcher->dispatchPostEvent(ResourceActions::CREATE, $configuration, $newResource);
70 |
71 | if (!$configuration->isHtmlRequest()) {
72 | return $this->viewHandler->handle($configuration, View::create($newResource, Response::HTTP_CREATED));
73 | }
74 | $this->flashHelper->addSuccessFlash($configuration, ResourceActions::CREATE, $newResource);
75 |
76 | return $this->redirectHandler->redirectToResource($configuration, $newResource);
77 | }
78 |
79 | if (!$configuration->isHtmlRequest()) {
80 | return $this->viewHandler->handle($configuration, View::create($form, Response::HTTP_BAD_REQUEST));
81 | }
82 |
83 | $view = View::create()
84 | ->setData([
85 | 'configuration' => $configuration,
86 | $this->metadata->getName() => $newResource,
87 | 'form' => $form->createView(),
88 | ])
89 | ->setTemplate($configuration->getTemplate(CartActions::ADD . '.html'))
90 | ;
91 |
92 | return $this->viewHandler->handle($configuration, $view);
93 | }
94 |
95 | /**
96 | * @param Request $request
97 | *
98 | * @return Response
99 | */
100 | public function removeAction(Request $request)
101 | {
102 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request);
103 |
104 | $this->isGrantedOr403($configuration, ResourceActions::DELETE);
105 | $resource = $this->findOr404($configuration);
106 |
107 | $event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::DELETE, $configuration, $resource);
108 |
109 | if ($event->isStopped() && !$configuration->isHtmlRequest()) {
110 | throw new HttpException($event->getErrorCode(), $event->getMessage());
111 | }
112 | if ($event->isStopped()) {
113 | $this->flashHelper->addFlashFromEvent($configuration, $event);
114 |
115 | return $this->redirectHandler->redirectToIndex($configuration, $resource);
116 | }
117 |
118 | $cart = $this->getCurrentCart();
119 |
120 | $this->getCartModifier()->removeFromCart($cart, $resource);
121 |
122 | $this->repository->remove($resource);
123 |
124 | $cartManager = $this->getCartManager();
125 | $cartManager->persist($cart);
126 | $cartManager->flush();
127 |
128 | $this->eventDispatcher->dispatchPostEvent(ResourceActions::DELETE, $configuration, $resource);
129 |
130 | if (!$configuration->isHtmlRequest()) {
131 | return $this->viewHandler->handle($configuration, View::create(null, Response::HTTP_NO_CONTENT));
132 | }
133 |
134 | $this->flashHelper->addSuccessFlash($configuration, ResourceActions::DELETE, $resource);
135 |
136 | return $this->redirectHandler->redirectToIndex($configuration, $resource);
137 | }
138 |
139 | /**
140 | * @return OrderItemQuantityModifierInterface
141 | */
142 | private function getItemQuantityModifier()
143 | {
144 | return $this->get('sylius.order_item_quantity_modifier');
145 | }
146 |
147 | /**
148 | * @return CartModifierInterface
149 | */
150 | private function getCartModifier()
151 | {
152 | return $this->get('sylius.cart.cart_modifier');
153 | }
154 |
155 | /**
156 | * @return EntityManagerInterface
157 | */
158 | private function getCartManager()
159 | {
160 | return $this->get('sylius.manager.cart');
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/DependencyInjection/Configuration.php:
--------------------------------------------------------------------------------
1 |
35 | * @author Saša Stamenković
36 | */
37 | class Configuration implements ConfigurationInterface
38 | {
39 | /**
40 | * {@inheritdoc}
41 | */
42 | public function getConfigTreeBuilder()
43 | {
44 | $treeBuilder = new TreeBuilder();
45 | $rootNode = $treeBuilder->root('sylius_cart');
46 |
47 | $rootNode
48 | ->addDefaultsIfNotSet()
49 | ->children()
50 | ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->cannotBeEmpty()->end()
51 | ->end()
52 | ;
53 |
54 | $this->addResourcesSection($rootNode);
55 |
56 | return $treeBuilder;
57 | }
58 |
59 | /**
60 | * @param ArrayNodeDefinition $node
61 | */
62 | private function addResourcesSection(ArrayNodeDefinition $node)
63 | {
64 | $node
65 | ->children()
66 | ->arrayNode('resources')
67 | ->isRequired()
68 | ->addDefaultsIfNotSet()
69 | ->children()
70 | ->arrayNode('cart')
71 | ->addDefaultsIfNotSet()
72 | ->children()
73 | ->variableNode('options')->end()
74 | ->arrayNode('classes')
75 | ->addDefaultsIfNotSet()
76 | ->children()
77 | ->scalarNode('model')->defaultValue(Cart::class)->cannotBeEmpty()->end()
78 | ->scalarNode('interface')->defaultValue(CartInterface::class)->cannotBeEmpty()->end()
79 | ->scalarNode('controller')->defaultValue(CartController::class)->cannotBeEmpty()->end()
80 | ->scalarNode('repository')->cannotBeEmpty()->end()
81 | ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
82 | ->arrayNode('form')
83 | ->addDefaultsIfNotSet()
84 | ->children()
85 | ->scalarNode('default')->defaultValue(CartType::class)->cannotBeEmpty()->end()
86 | ->end()
87 | ->end()
88 | ->end()
89 | ->end()
90 | ->arrayNode('validation_groups')
91 | ->addDefaultsIfNotSet()
92 | ->children()
93 | ->arrayNode('default')
94 | ->prototype('scalar')->end()
95 | ->defaultValue(['sylius'])
96 | ->end()
97 | ->end()
98 | ->end()
99 | ->end()
100 | ->end()
101 | ->arrayNode('cart_item')
102 | ->addDefaultsIfNotSet()
103 | ->children()
104 | ->variableNode('options')->end()
105 | ->arrayNode('classes')
106 | ->addDefaultsIfNotSet()
107 | ->children()
108 | ->scalarNode('model')->defaultValue(CartItem::class)->cannotBeEmpty()->end()
109 | ->scalarNode('interface')->defaultValue(CartItemInterface::class)->cannotBeEmpty()->end()
110 | ->scalarNode('controller')->defaultValue(CartItemController::class)->cannotBeEmpty()->end()
111 | ->scalarNode('repository')->cannotBeEmpty()->end()
112 | ->scalarNode('factory')->defaultValue(Factory::class)->cannotBeEmpty()->end()
113 | ->arrayNode('form')
114 | ->addDefaultsIfNotSet()
115 | ->children()
116 | ->scalarNode('default')->defaultValue(CartItemType::class)->cannotBeEmpty()->end()
117 | ->end()
118 | ->end()
119 | ->end()
120 | ->end()
121 | ->arrayNode('validation_groups')
122 | ->addDefaultsIfNotSet()
123 | ->children()
124 | ->arrayNode('default')
125 | ->prototype('scalar')->end()
126 | ->defaultValue(['sylius'])
127 | ->end()
128 | ->end()
129 | ->end()
130 | ->end()
131 | ->end()
132 | ->end()
133 | ->end()
134 | ->end()
135 | ;
136 | }
137 | }
138 |
--------------------------------------------------------------------------------