Installation:
composer require alpixel/shopbundle
Ensure your project uses Symfony 2.8 (as per composer.json).
Enable the Bundle:
Add to app/AppKernel.php:
new Alpixel\Bundle\ShopBundle\AlpixelShopBundle(),
new Happyr\GoogleAnalyticsBundle\HappyrGoogleAnalyticsBundle(), // Required if using GA
new Http\HttplugBundle\HttplugBundle(), // Required if using GA
Basic Configuration (config.yml):
alpixel_shop:
customer_class: AppBundle\Entity\Customer # Extend Alpixel's base Customer entity
stock:
strategy: soft # Default: 'soft' (allows over-selling)
use_google_analytics: false # Set to true if using GA
First Use Case:
Create a custom Customer entity extending Alpixel\Bundle\ShopBundle\Entity\Customer:
// src/AppBundle/Entity/Customer.php
namespace AppBundle\Entity;
use Alpixel\Bundle\ShopBundle\Entity\Customer as BaseCustomer;
class Customer extends BaseCustomer { /* Add custom fields */ }
Product Management:
Alpixel\Bundle\ShopBundle\Entity\Product or extend via product_inheritance:
alpixel_shop:
product_inheritance:
- { key: 'custom_product', class: AppBundle\Entity\CustomProduct }
soft, tolerant, strict) control order validation:
// Soft: Allow orders regardless of stock
$order->validate(); // Always passes
Cart Functionality:
$cart = $this->get('alpixel_shop.cart_manager')->createCart();
$cart->addProduct($product, 2);
$cartManager->saveCart($cart); // Persist to reuse later
$userCart = $this->get('alpixel_shop.cart_manager')->getCartByUser($user);
Order Processing:
$order->addShipment($address, $carrier);
$order->setStatus('shipped');
Google Analytics Integration:
config.yml and use events:
$this->get('ga.tracker')->sendEvent('ecommerce', 'purchase', $order->getId());
stof/doctrine-extensions for behaviors like timestamps.alpixel_shop.order.created or alpixel_shop.cart.saved for custom logic.Http\HttplugBundle for external services (e.g., payment gateways).Stock Strategy Misconfiguration:
strict mode blocks orders with insufficient stock. Test thoroughly in staging.soft mode risks over-selling; monitor stock levels post-order.Entity Inheritance:
Customer/Product entities are properly mapped in Doctrine:
# AppBundle/Resources/config/doctrine/Customer.orm.yml
AppBundle\Entity\Customer:
type: entity
extends: Alpixel\Bundle\ShopBundle\Entity\Customer
Google Analytics Dependency:
use_google_analytics: true, ensure HappyrGoogleAnalyticsBundle and HttplugBundle are installed and configured.Deprecated Symfony Version:
Cart Persistence Issues:
CartManager is autowired and the cart table exists in your database.prePersist/preUpdate issues.Stock Updates:
stock.update: false, stock quantities won’t auto-decrement. Manually update via:
$product->decrementStock($quantity);
$em->flush();
Custom Order Statuses:
Alpixel\Bundle\ShopBundle\Entity\Order and add transitions:
// src/AppBundle/Entity/Order.php
public function setStatus($status)
{
if ($status === 'custom_status') {
$this->fireEvent('custom_status_transition');
}
parent::setStatus($status);
}
Payment Gateways:
// src/AppBundle/Service/PaymentGateway.php
class PaymentGateway
{
public function process(Order $order) {
// Use HttplugBundle to call external API
}
}
Custom Validation:
OrderValidator to add rules:
// src/AppBundle/Validator/OrderValidator.php
class OrderValidator extends \Alpixel\Bundle\ShopBundle\Validator\OrderValidator
{
public function validate(Order $order) {
parent::validate($order);
// Add custom checks
}
}
How can I help you explore Laravel packages today?