getSandbox(); $params['group_by'] = 'GROUP BY a.id_order'; } $params['fields']['reference']['filter_key'] = 'a!reference'; $params['fields'] = array_merge($params['fields'], [ 'inpost_shipment_date' => [ 'title' => $this->module->l('InPost date', self::TRANSLATION_SOURCE), 'align' => 'text-right', 'type' => 'datetime', 'filter_key' => 'inpost!date_add', ], ]); } public function hookDisplayAdminOrdersListBefore() { return $this->renderPrintShipmentLabelModal() . $this->renderDispatchOrderModal(); } public function hookDisplayAdminOrdersListAfter() { $this->context->smarty->assign([ 'moduleDisplayName' => $this->module->displayName, 'bulkActions' => $this->getBulkActions(), ]); return $this->module->display($this->module->name, 'views/templates/hook/admin-orders-list-after.tpl'); } public function hookDisplayAdminGridTableBefore($params) { if ($params['legacy_controller'] === 'AdminOrders') { return '
' . $this->renderPrintShipmentLabelModal() . $this->renderDispatchOrderModal(); } return ''; } public function hookActionOrderGridDefinitionModifier($params) { /** @var GridDefinitionInterface $definition */ $definition = $params['definition']; $definition->getColumns() ->addAfter( 'date_add', (new DateTimeColumn('inpost_shipment_date')) ->setName($this->module->l('InPost shipment creation date', self::TRANSLATION_SOURCE)) ->setOptions([ 'field' => 'inpost_shipment_date', 'empty_data' => '--', ]) ); $definition->getFilters() ->add( (new Filter('inpost_shipment_date', DateRangeType::class)) ->setTypeOptions([ 'attr' => [ 'placeholder' => $this->module->l('Search date', self::TRANSLATION_SOURCE), ], 'required' => false, ]) ->setAssociatedColumn('inpost_shipment_date') ); $bulkActions = $definition->getBulkActions(); foreach ($this->getBulkActions() as $key => $bulkAction) { $bulkActions->add( (new ButtonBulkAction($key)) ->setName($bulkAction['label']) ->setOptions([ 'class' => $bulkAction['class'], 'attributes' => [ 'data-action' => $bulkAction['action'], ], ]) ); } } public function hookActionOrderGridQueryBuilderModifier($params) { /** @var QueryBuilder[] $queryBuilders */ $queryBuilders = [ 'search' => $params['search_query_builder'], 'count' => $params['count_query_builder'], ]; /** @var OrderFilters $searchCriteria */ $searchCriteria = $params['search_criteria']; $filters = $searchCriteria->getFilters(); foreach ($queryBuilders as $queryBuilder) { if (isset($filters['inpost_shipment_date']['from'])) { $queryBuilder ->andWhere('inpost.date_add >= :inpost_date_from') ->setParameter('inpost_date_from', $filters['inpost_shipment_date']['from']); } if (isset($filters['inpost_shipment_date']['to'])) { $queryBuilder ->andWhere('inpost.date_add <= :inpost_date_to') ->setParameter('inpost_date_to', $filters['inpost_shipment_date']['to']); } } if (!isset($filters['inpost_shipment_date']['from']) && !isset($filters['inpost_shipment_date']['to'])) { unset($queryBuilders['count']); } foreach ($queryBuilders as $queryBuilder) { $queryBuilder ->addSelect(sprintf( 'IFNULL(MAX(inpost.date_add), "%s") as inpost_shipment_date', DateTime::NULL_VALUE )) ->leftJoin( 'o', _DB_PREFIX_ . 'inpost_shipment', 'inpost', 'inpost.id_order = o.id_order AND inpost.sandbox = ' . $this->getSandbox() ) ->groupBy('o.id_order'); } } protected function getBulkActions() { /** @var LinkAdapter $link */ $link = $this->module->getService('inpost.shipping.adapter.link'); return [ 'inpost_create_shipments' => [ 'label' => $this->module->l('Create InPost shipments', self::TRANSLATION_SOURCE), 'action' => $link->getAdminLink(Tabs::SHIPMENTS_CONTROLLER_NAME, true, [], [ 'action' => 'bulkCreateShipment', 'ajax' => true, ]), 'class' => 'js-inpost-bulk-create-shipments', 'icon' => 'truck', ], 'inpost_create_print_shipments' => [ 'label' => $this->module->l('Create InPost shipments and print labels', self::TRANSLATION_SOURCE), 'action' => $link->getAdminLink(Tabs::SHIPMENTS_CONTROLLER_NAME, true, [], [ 'action' => 'bulkPrintLabels', 'ajax' => true, ]), 'class' => 'js-inpost-bulk-create-print-shipments', 'icon' => 'print', ], 'inpost_create_dispatch_orders' => [ 'label' => $this->module->l('Create InPost dispatch orders', self::TRANSLATION_SOURCE), 'action' => $link->getAdminLink(Tabs::SHIPMENTS_CONTROLLER_NAME, true, [], [ 'action' => 'bulkCreateDispatchOrders', 'ajax' => true, ]), 'class' => 'js-inpost-bulk-create-dispatch-orders', 'icon' => 'truck', ], 'inpost_print_dispatch_orders' => [ 'label' => $this->module->l('Print InPost dispatch orders', self::TRANSLATION_SOURCE), 'action' => $link->getAdminLink(Tabs::SHIPMENTS_CONTROLLER_NAME, true, [], [ 'action' => 'bulkPrintDispatchOrders', 'ajax' => true, ]), 'class' => 'js-inpost-bulk-print-dispatch-orders', 'icon' => 'print', ], 'inpost_refresh_shipment_status' => [ 'label' => $this->module->l('Update InPost shipments\' statuses', self::TRANSLATION_SOURCE), 'action' => $link->getAdminLink(Tabs::SHIPMENTS_CONTROLLER_NAME, true, [], [ 'action' => 'bulkRefreshStatuses', 'ajax' => true, ]), 'class' => 'js-inpost-bulk-refresh-shipment-status', 'icon' => 'refresh', ], ]; } protected function getSandbox() { /** @var ShipXConfiguration $configuration */ $configuration = $this->module->getService('inpost.shipping.configuration.shipx'); return $configuration->isSandboxModeEnabled() ? 1 : 0; } }