25carat/oro-show-orders-by-shopping-list
Installation
composer require 25carat/oro-show-orders-by-shopping-list
php bin/console oro:platform:update --force
Clear Cache
php bin/console cache:clear
First Use Case
Frontend Integration
templates/orocommerce/account/order/index.html.twig).{% extends 'OroShowOrdersByShoppingList::account/order/index.html.twig' %}
{% block oro_account_order_grid_columns %}
{{ parent() }}
{# Customize column order or visibility #}
{% endblock %}
Data Binding
Oro\Bundle\OrderBundle\Entity\Order entity if you need custom logic:
// src/Entity/Order.php
public function getShoppingList()
{
return $this->getShoppingList(); // Default method provided by the bundle
}
Filtering
# config/oro/datagrids/order.yaml
OroShowOrdersByShoppingList:
columns:
shopping_list:
label: 'Shopping List'
type: 'shopping_list' # Custom type (provided by the bundle)
filters:
shopping_list:
type: 'shopping_list' # Custom filter (provided by the bundle)
API/Backend Usage
use Oro\Bundle\ShowOrdersByShoppingListBundle\Query\OrderQueryBuilderExtension;
$qb = $entityManager->getRepository(Order::class)->createQueryBuilder('o');
$qb->getEntityManager()->getFilters()->disable('non_loaded_metadata_collection');
$extension = new OrderQueryBuilderExtension($qb);
$extension->addShoppingListFilter('list_name');
Shopping List Deletion Blocked
deleteAction in your controller:
// src/Acme/ShoppingListBundle/Controller/ShoppingListController.php
public function deleteAction(Request $request, $id)
{
// Custom logic to allow deletion (e.g., check for linked orders)
return $this->forwardToRoute('oro_shoppinglist_delete', ['id' => $id]);
}
Template Overrides
base.html.twig includes the bundle’s assets:
{{ parent() }}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="{{ asset('bundles/oroshoppinglist/css/order-grid.css') }}">
{% endblock %}
Performance with Large Datasets
shopping_list table in queries.shopping_list_order table if queries are slow:
CREATE INDEX idx_shopping_list_order ON shopping_list_order (shopping_list_id, order_id);
Localization Issues
# config/oro/translations/messages.en.yml
OroShowOrdersByShoppingList:
ShoppingList: 'Shopping List'
Filter by Shopping List: 'Filter by Shopping List'
Check Grid Configuration
$gridName = 'oro_account_order';
$gridConfig = $this->container->get('oro_datagrid.datagrid.registry')->getDatagrid($gridName)->getConfiguration();
dump($gridConfig);
Query Logging
// config/packages/dev/doctrine.yaml
doctrine:
dbal:
logging: true
profiling: true
Event Listeners
oro_shopping_list.post_delete). Listen for them to debug:
// src/EventListener/ShoppingListListener.php
public function onPostDelete(ShoppingListEvent $event)
{
if (!$event->getShoppingList()->getOrders()->isEmpty()) {
throw new \RuntimeException('Cannot delete shopping list with orders.');
}
}
Customize Column Data
Oro\Bundle\ShowOrdersByShoppingListBundle\Provider\OrderShoppingListProvider to modify how shopping lists are fetched for orders:
// src/Provider/CustomOrderShoppingListProvider.php
public function getShoppingList(Order $order)
{
// Custom logic (e.g., fallback to a default list)
return $order->getShoppingList() ?: $this->findDefaultList();
}
Add Batch Actions
# config/oro/datagrids/order.yaml
OroShowOrdersByShoppingList:
actions:
reorder:
type: 'reorder'
label: 'Reorder from Shopping List'
acl: 'oro_order_reorder'
API Endpoint
Oro\Bundle\OrderBundle\Api\OrderApi:
// src/Api/OrderApiExtension.php
public function getAdditionalData(Order $order, array $context = [])
{
return [
'shopping_list' => $order->getShoppingList() ? $order->getShoppingList()->getName() : null,
];
}
How can I help you explore Laravel packages today?