Recommend this page to a friend! |
Classes of Tomas Saghy | PHP Cart Page | README.md | Download |
|
![]() PHP CartPHP library providing basic shopping cart functionality. InstallationInstall the latest version using Or add to your composer.json file as a requirement:
UsageConstructor takes three configuration parameters: * context data that are passed to each added cart item (you can pass i.e. customer id to resolve custom price) * true when listing gross prices, false for net prices (see nice explanation) * number of decimals for rounding All of them can be set separately.
Manipulating cart itemsItems can be accessed by their cart id (provided by getCartId method).
Batch cart items manipulationCart can be cleared using clear() method. Items can be set using setItems() method. Please note that setItems will call clear. All items have to implement CartItemInterface. Getting itemsItems can be fetched using getItems or by type using getItemsByType. Getting totalsCart works with Decimal class (see litipk/php-bignumbers). You can access subtotal (without VAT), taxes (array of amounts for all rates) and total (subtotal + taxes).
Totals can be also count by type:
Getting weight (since 1.4)As of 1.4 item implementing WeightedCartItemInterface can be added to cart, so cart can count total weight. Weight can be counted by type using same format as for counting totals.
TestsYou can run the unit tests with the following command:
|