diff --git a/CHANGELOG.md b/CHANGELOG.md index 91117c3..72f4683 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased +- Smarty is gone, as in Thelia 3: the Smarty plugin `credit_note_format_address`, the Smarty back-office and PDF templates, the Smarty fallback of the back-office hooks. The loops no Twig template calls are removed too: `credit-note-comment`, `credit-note-status`, `credit-note-type`, `order-credit-note` and `credit-note-version` (its table has not existed since 2.3.4). The loops `credit-note`, `credit-note-address` and `credit-note-detail` stay: the credit note document of the PDF template reads them. - The languages a credit note is printed in are a setting of the module (`document_locales`, locales separated by commas): a customer whose language is in the list gets the document in that language, the others the default language of the shop. Empty, as before: English and French. A shop whose PDF template is translated in German adds `de_DE`. The field refuses anything that is not a list of locales such as `fr_FR`. - Credit notes numbered like the invoices (`invoice_ref_with_thelia_order`) draw their number from `InvoiceRefSequence::next()` (InvoiceRef 3.1 or later): the counter is read under a lock shared with the orders, and a number an order already carries is skipped. The previous read and increment, without a lock, could hand the same number to an invoice and a credit note. - The ceiling of an order is a setting of the module (`order_ceiling`, on by default, added to an existing installation by the update): a shop that grants credit notes beyond the total of the order turns it off. diff --git a/Config/config.xml b/Config/config.xml index 1db7007..01cd8d6 100755 --- a/Config/config.xml +++ b/Config/config.xml @@ -4,13 +4,8 @@ - - - - - diff --git a/Config/module.xml b/Config/module.xml index 1fe0e32..e7cfc59 100755 --- a/Config/module.xml +++ b/Config/module.xml @@ -17,7 +17,7 @@ en_US fr_FR - 4.1.0 + 4.2.0 Gilles Bourgeat gbourgeat@openstudio.fr diff --git a/Controller/CreditNoteController.php b/Controller/CreditNoteController.php index 2fced53..cffec20 100755 --- a/Controller/CreditNoteController.php +++ b/Controller/CreditNoteController.php @@ -621,13 +621,7 @@ protected function performCustomer(Form $formValidate, CreditNote $creditNote) /** @var int $customerId */ $customerId = $formValidate->get('customer_id')->getData(); - // check if order - if (!empty($orderId) && null !== $order = OrderQuery::create()->findPk($orderId)) { - $creditNote - ->setOrder($order) - ->setCurrency($order->getCurrency()) - ->setCustomer($order->getCustomer()); - } elseif (!empty($customerId) && null !== $customer = CustomerQuery::create()->findPk($customerId)) { + if (!empty($customerId) && null !== $customer = CustomerQuery::create()->findPk($customerId)) { $creditNote->setCustomer($customer); } diff --git a/Hook/Back/ConfigHook.php b/Hook/Back/ConfigHook.php index d326dcd..64d0a6c 100644 --- a/Hook/Back/ConfigHook.php +++ b/Hook/Back/ConfigHook.php @@ -18,8 +18,6 @@ class ConfigHook extends BaseHook { - use TemplateFallbackTrait; - public function __construct( private readonly TheliaFormFactory $formFactory, ?EventDispatcherInterface $dispatcher = null, diff --git a/Hook/Back/CustomerEditHook.php b/Hook/Back/CustomerEditHook.php index 4c7de0b..8327f8e 100755 --- a/Hook/Back/CustomerEditHook.php +++ b/Hook/Back/CustomerEditHook.php @@ -19,8 +19,6 @@ */ class CustomerEditHook extends BaseHook { - use TemplateFallbackTrait; - public function __construct( private readonly CreditNoteHookPresenter $presenter, ?EventDispatcherInterface $dispatcher = null, diff --git a/Hook/Back/MainHook.php b/Hook/Back/MainHook.php index 37ec928..33eb44a 100755 --- a/Hook/Back/MainHook.php +++ b/Hook/Back/MainHook.php @@ -19,8 +19,6 @@ */ class MainHook extends BaseHook { - use TemplateFallbackTrait; - public function __construct( private readonly CreditNoteHookPresenter $presenter, ?EventDispatcherInterface $dispatcher = null, diff --git a/Hook/Back/OrderEditHook.php b/Hook/Back/OrderEditHook.php index f7c5a02..61d8c01 100755 --- a/Hook/Back/OrderEditHook.php +++ b/Hook/Back/OrderEditHook.php @@ -22,8 +22,6 @@ */ class OrderEditHook extends BaseHook { - use TemplateFallbackTrait; - public function __construct( private readonly CreditNoteHookPresenter $presenter, ?EventDispatcherInterface $dispatcher = null, diff --git a/Hook/Back/TemplateFallbackTrait.php b/Hook/Back/TemplateFallbackTrait.php deleted file mode 100644 index 38a9f47..0000000 --- a/Hook/Back/TemplateFallbackTrait.php +++ /dev/null @@ -1,77 +0,0 @@ -resolveCompatibleTemplateName($templateName), $parameters); - } - - private function resolveCompatibleTemplateName(string $templateName): string - { - if (!str_ends_with($templateName, '.html.twig')) { - return $templateName; - } - - $parser = $this->getParser(); - - if (!$parser instanceof ParserInterface) { - return $templateName; - } - - $resolver = $this->getAssetsResolver(); - $moduleCode = $this->module?->getCode() ?? ''; - - // Recent Twig back-office: the .html.twig template resolves, keep it. - if (null !== $resolver->resolveAssetSourcePath($moduleCode, '', $templateName, $parser)) { - return $templateName; - } - - // Legacy Smarty back-office: try the .html template, with and without the - // leading module-code prefix (Smarty templates live flat under default/). - $withoutTwig = substr($templateName, 0, -\strlen('.twig')); - $candidates = [$withoutTwig]; - - $prefix = $moduleCode.'/'; - - if ('' !== $moduleCode && str_starts_with($withoutTwig, $prefix)) { - $candidates[] = substr($withoutTwig, \strlen($prefix)); - } - - foreach ($candidates as $candidate) { - if (null !== $resolver->resolveAssetSourcePath($moduleCode, '', $candidate, $parser)) { - return $candidate; - } - } - - return $templateName; - } -} diff --git a/Loop/CreditNoteComment.php b/Loop/CreditNoteComment.php deleted file mode 100755 index be7f2fb..0000000 --- a/Loop/CreditNoteComment.php +++ /dev/null @@ -1,127 +0,0 @@ - - * - * @method string[] getCode() - * @method int[] getId() - * @method int[] getCreditNoteId() - * @method string[] getOrder() - */ -class CreditNoteComment extends BaseI18nLoop implements PropelSearchLoopInterface -{ - protected $timestampable = true; - - protected function getArgDefinitions(): \Thelia\Core\Template\Loop\Argument\ArgumentCollection - { - return new ArgumentCollection( - Argument::createIntListTypeArgument("id"), - Argument::createIntListTypeArgument("credit_note_id"), - Argument::createEnumListTypeArgument( - "order", - [ - "id", "id-reverse", - "create-date", "create-date-reverse" - ], - "create-date" - ) - ); - } - - /** - * this method returns a Propel ModelCriteria - * - * @return \Propel\Runtime\ActiveQuery\ModelCriteria - */ - public function buildModelCriteria(): ModelCriteria - { - $query = new CreditNoteCommentQuery(); - - if (null !== $id = $this->getId()) { - $query->filterById($id); - } - - if (null !== $creditNoteId = $this->getCreditNoteId()) { - $query->filterByCreditNoteId($creditNoteId); - } - - $query->useAdminQuery() - ->endUse(); - - $query->withColumn(AdminTableMap::COL_LOGIN, 'ADMIN_LOGIN'); - $query->withColumn(AdminTableMap::COL_FIRSTNAME, 'ADMIN_FIRST_NAME'); - $query->withColumn(AdminTableMap::COL_LASTNAME, 'ADMIN_LAST_NAME'); - - $this->buildModelCriteriaOrder($query); - - return $query; - } - - /** - * @param CreditNoteCommentQuery $query - */ - protected function buildModelCriteriaOrder($query) - { - foreach ($this->getOrder() as $order) { - switch ($order) { - case "id": - $query->orderById(); - break; - case "id-reverse": - $query->orderById(Criteria::DESC); - break; - case 'create-date': - $query->orderByCreatedAt(Criteria::ASC); - break; - case 'create-date-reverse': - $query->orderByCreatedAt(Criteria::DESC); - break; - } - } - } - - /** - * @param LoopResult $loopResult - * - * @return LoopResult - */ - public function parseResults(LoopResult $loopResult): LoopResult - { - /** @var \CreditNote\Model\CreditNoteComment $entry */ - foreach ($loopResult->getResultDataCollection() as $entry) { - $row = new LoopResultRow($entry); - $row - ->set("ID", $entry->getId()) - ->set("CREDIT_NOTE_ID", $entry->getCreditNoteId()) - ->set("ADMIN_ID", $entry->getAdminId()) - ->set("ADMIN_LOGIN", $entry->getVirtualColumn('ADMIN_LOGIN')) - ->set("ADMIN_FIRST_NAME", $entry->getVirtualColumn('ADMIN_FIRST_NAME')) - ->set("ADMIN_LAST_NAME", $entry->getVirtualColumn('ADMIN_LAST_NAME')) - ->set("COMMENT", $entry->getComment()) - ; - $this->addOutputFields($row, $entry); - $loopResult->addRow($row); - } - - return $loopResult; - } -} diff --git a/Loop/CreditNoteStatus.php b/Loop/CreditNoteStatus.php deleted file mode 100755 index e17c112..0000000 --- a/Loop/CreditNoteStatus.php +++ /dev/null @@ -1,169 +0,0 @@ - - * - * @method string[] getCode() - * @method int[] getId() - * @method int[] getPosition() - * @method int[] getCurrentStatusId() - * @method string[] getOrder() - * @method string|bool getInvoiced() - * @method string|bool getUsed() - */ -class CreditNoteStatus extends BaseI18nLoop implements PropelSearchLoopInterface -{ - protected $timestampable = true; - - protected function getArgDefinitions(): \Thelia\Core\Template\Loop\Argument\ArgumentCollection - { - return new ArgumentCollection( - Argument::createAnyListTypeArgument('code'), - Argument::createIntListTypeArgument("id"), - Argument::createIntListTypeArgument("position"), - Argument::createBooleanOrBothTypeArgument("invoiced", BooleanOrBothType::ANY), - Argument::createBooleanOrBothTypeArgument("used", BooleanOrBothType::ANY), - Argument::createIntListTypeArgument("current_status_id"), - Argument::createEnumListTypeArgument( - "order", - [ - "id", "id-reverse", - "create-date", "create-date-reverse", - "code", "code-reverse", - "position", "position-reverse" - ], - "position" - ) - ); - } - - /** - * this method returns a Propel ModelCriteria - * - * @return \Propel\Runtime\ActiveQuery\ModelCriteria - */ - public function buildModelCriteria(): ModelCriteria - { - $query = new CreditNoteStatusQuery(); - - if (null !== $id = $this->getId()) { - $query->filterById($id); - } - - if (null !== $code = $this->getCode()) { - $query->filterByCode($code); - } - - if (null !== $position = $this->getPosition()) { - $query->filterByPosition($position); - } - - if (BooleanOrBothType::ANY !== $used = $this->getUsed()) { - $query->filterByUsed($used); - } - - if (BooleanOrBothType::ANY !== $invoiced = $this->getInvoiced()) { - $query->filterByInvoiced($invoiced); - } - - if (null !== $currentStatusId = $this->getCurrentStatusId()) { - $flowIds = CreditNoteStatusFlowQuery::create() - ->filterByFromStatusId($currentStatusId) - ->find()->toArray('toStatusId'); - - $flowIds = array_keys($flowIds); - - $query->filterById(array_merge($flowIds, $currentStatusId)); - } - - $this->configureI18nProcessing($query, ['TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM']); - - $this->buildModelCriteriaOrder($query); - - $query->groupById(); - - return $query; - } - - /** - * @param CreditNoteStatusQuery $query - */ - protected function buildModelCriteriaOrder($query) - { - foreach ($this->getOrder() as $order) { - switch ($order) { - case "id": - $query->orderById(); - break; - case "id-reverse": - $query->orderById(Criteria::DESC); - break; - case 'create-date': - $query->orderByCreatedAt(Criteria::ASC); - break; - case 'create-date-reverse': - $query->orderByCreatedAt(Criteria::DESC); - break; - case 'code': - $query->orderByCode(Criteria::ASC); - break; - case 'code-reverse': - $query->orderByCode(Criteria::DESC); - break; - case 'position': - $query->orderByPosition(Criteria::ASC); - break; - case 'position-reverse': - $query->orderByPosition(Criteria::DESC); - break; - } - } - } - - /** - * @param LoopResult $loopResult - * - * @return LoopResult - */ - public function parseResults(LoopResult $loopResult): LoopResult - { - /** @var \CreditNote\Model\CreditNoteStatus $entry */ - foreach ($loopResult->getResultDataCollection() as $entry) { - $row = new LoopResultRow($entry); - $row - ->set("ID", $entry->getId()) - ->set("CODE", $entry->getCode()) - ->set("COLOR", $entry->getColor()) - ->set("POSITION", $entry->getPosition()) - ->set("TITLE", $entry->getVirtualColumn('i18n_TITLE')) - ->set("CHAPO", $entry->getVirtualColumn('i18n_CHAPO')) - ->set("DESCRIPTION", $entry->getVirtualColumn('i18n_DESCRIPTION')) - ->set("POSTSCRIPTUM", $entry->getVirtualColumn('i18n_POSTSCRIPTUM')) - ; - $this->addOutputFields($row, $entry); - $loopResult->addRow($row); - } - - return $loopResult; - } -} diff --git a/Loop/CreditNoteType.php b/Loop/CreditNoteType.php deleted file mode 100755 index 9bc8058..0000000 --- a/Loop/CreditNoteType.php +++ /dev/null @@ -1,141 +0,0 @@ - - * - * @method string[] getCode() - * @method int[] getId() - * @method int[] getPosition() - * @method string[] getOrder() - */ -class CreditNoteType extends BaseI18nLoop implements PropelSearchLoopInterface -{ - protected $timestampable = true; - - protected function getArgDefinitions(): \Thelia\Core\Template\Loop\Argument\ArgumentCollection - { - return new ArgumentCollection( - Argument::createAnyListTypeArgument('code'), - Argument::createIntListTypeArgument("id"), - Argument::createIntListTypeArgument("position"), - Argument::createEnumListTypeArgument( - "order", - [ - "id", "id-reverse", - "create-date", "create-date-reverse", - "code", "code-reverse", - "position", "position-reverse" - ], - "position" - ) - ); - } - - /** - * this method returns a Propel ModelCriteria - * - * @return \Propel\Runtime\ActiveQuery\ModelCriteria - */ - public function buildModelCriteria(): ModelCriteria - { - $query = new CreditNoteTypeQuery(); - - if (null !== $id = $this->getId()) { - $query->filterById($id); - } - - if (null !== $code = $this->getCode()) { - $query->filterByCode($code); - } - - if (null !== $position = $this->getPosition()) { - $query->filterByPosition($position); - } - - $this->configureI18nProcessing($query, ['TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM']); - - $this->buildModelCriteriaOrder($query); - - return $query; - } - - /** - * @param CreditNoteTypeQuery $query - */ - protected function buildModelCriteriaOrder($query) - { - foreach ($this->getOrder() as $order) { - switch ($order) { - case "id": - $query->orderById(); - break; - case "id-reverse": - $query->orderById(Criteria::DESC); - break; - case 'create-date': - $query->orderByCreatedAt(Criteria::ASC); - break; - case 'create-date-reverse': - $query->orderByCreatedAt(Criteria::DESC); - break; - case 'code': - $query->orderByCode(Criteria::ASC); - break; - case 'code-reverse': - $query->orderByCode(Criteria::DESC); - break; - case 'position': - $query->orderByPosition(Criteria::ASC); - break; - case 'position-reverse': - $query->orderByPosition(Criteria::DESC); - break; - } - } - } - - /** - * @param LoopResult $loopResult - * - * @return LoopResult - */ - public function parseResults(LoopResult $loopResult): LoopResult - { - /** @var \CreditNote\Model\CreditNoteType $entry */ - foreach ($loopResult->getResultDataCollection() as $entry) { - $row = new LoopResultRow($entry); - $row - ->set("ID", $entry->getId()) - ->set("CODE", $entry->getCode()) - ->set("COLOR", $entry->getColor()) - ->set("POSITION", $entry->getPosition()) - ->set("TITLE", $entry->getVirtualColumn('i18n_TITLE')) - ->set("CHAPO", $entry->getVirtualColumn('i18n_CHAPO')) - ->set("DESCRIPTION", $entry->getVirtualColumn('i18n_DESCRIPTION')) - ->set("POSTSCRIPTUM", $entry->getVirtualColumn('i18n_POSTSCRIPTUM')) - ; - $this->addOutputFields($row, $entry); - $loopResult->addRow($row); - } - - return $loopResult; - } -} diff --git a/Loop/CreditNoteVersion.php b/Loop/CreditNoteVersion.php deleted file mode 100755 index 311615b..0000000 --- a/Loop/CreditNoteVersion.php +++ /dev/null @@ -1,154 +0,0 @@ - - * - * @method string[] getRef() - * @method int[] getId() - * @method string[] getOrder() - */ -class CreditNoteVersion extends BaseLoop implements PropelSearchLoopInterface -{ - protected $timestampable = true; - - protected function getArgDefinitions(): \Thelia\Core\Template\Loop\Argument\ArgumentCollection - { - return new ArgumentCollection( - Argument::createAnyListTypeArgument('ref'), - Argument::createIntListTypeArgument("id"), - Argument::createEnumListTypeArgument( - "order", - [ - "id", "id-reverse", - "create-date", "create-date-reverse" - ], - "id" - ) - ); - } - - /** - * this method returns a Propel ModelCriteria - * - * @return \Propel\Runtime\ActiveQuery\ModelCriteria - */ - public function buildModelCriteria(): ModelCriteria - { - $query = new CreditNoteVersionQuery(); - - if (null !== $id = $this->getId()) { - $query->filterById($id); - } - - if (null !== $ref = $this->getRef()) { - $query->filterByRef($ref); - } - - $this->addJoin($query); - - $this->addVirtualColumn($query); - - $this->buildModelCriteriaOrder($query); - - $query->groupById(); - - return $query; - } - - /** - * @param CreditNoteVersionQuery $query - */ - protected function buildModelCriteriaOrder($query) - { - foreach ($this->getOrder() as $order) { - switch ($order) { - case "id": - $query->orderById(); - break; - case "id-reverse": - $query->orderById(Criteria::DESC); - break; - case 'create-date': - $query->orderByCreatedAt(Criteria::ASC); - break; - case 'create-date-reverse': - $query->orderByCreatedAt(Criteria::DESC); - break; - } - } - } - - /** - * @param CreditNoteVersionQuery $query - */ - protected function addJoin($query) - { - - } - - /** - * @param CreditNoteVersionQuery $query - */ - protected function addVirtualColumn($query) - { - - } - - /** - * @param LoopResult $loopResult - * - * @return LoopResult - */ - public function parseResults(LoopResult $loopResult): LoopResult - { - /** @var \CreditNote\Model\CreditNoteVersion $entry */ - foreach ($loopResult->getResultDataCollection() as $entry) { - $row = new LoopResultRow($entry); - $row - ->set("ID", $entry->getId()) - ->set("REF", $entry->getRef()) - ->set("TYPE_ID", $entry->getTypeId()) - ->set("STATUS_ID", $entry->getStatusId()) - ->set("ORDER_ID", $entry->getOrderId()) - ->set("PARENT_ID", $entry->getParentId()) - ->set("CUSTOMER_ID", $entry->getCustomerId()) - ->set("TOTAL_AMOUNT_PRICE", $entry->getTotalPriceWithTax()) - ; - $this->addOutputFields($row, $entry); - $loopResult->addRow($row); - } - - return $loopResult; - } - - /** - * @return string - */ - protected function getLocale() - { - $request = $this->requestStack->getCurrentRequest(); - if (null === $request || !$request->hasSession()) { - return \Thelia\Model\LangQuery::create()->findOneByByDefault(true)?->getLocale() ?? 'en_US'; - } - - return $request->getSession()->getAdminEditionLang()->getLocale(); - } -} diff --git a/Loop/OrderCreditNote.php b/Loop/OrderCreditNote.php deleted file mode 100644 index 82d2072..0000000 --- a/Loop/OrderCreditNote.php +++ /dev/null @@ -1,79 +0,0 @@ - - * - * @method int[] getCreditNoteId() - * @method int[] getOrderId() - */ -class OrderCreditNote extends BaseI18nLoop implements PropelSearchLoopInterface -{ - protected $timestampable = true; - - protected function getArgDefinitions(): \Thelia\Core\Template\Loop\Argument\ArgumentCollection - { - return new ArgumentCollection( - Argument::createIntListTypeArgument("credit_note_id"), - Argument::createIntListTypeArgument("order_id") - ); - } - - /** - * this method returns a Propel ModelCriteria - * - * @return \Propel\Runtime\ActiveQuery\ModelCriteria - */ - public function buildModelCriteria(): ModelCriteria - { - $query = new OrderCreditNoteQuery(); - - if (null !== $creditNoteId = $this->getCreditNoteId()) { - $query->filterByCreditNoteId($creditNoteId); - } - - if (null !== $orderId = $this->getOrderId()) { - $query->filterByOrderId($orderId); - } - - return $query; - } - - /** - * @param LoopResult $loopResult - * - * @return LoopResult - */ - public function parseResults(LoopResult $loopResult): LoopResult - { - /** @var \CreditNote\Model\OrderCreditNote $entry */ - foreach ($loopResult->getResultDataCollection() as $entry) { - $row = new LoopResultRow($entry); - $row - ->set("ORDER_ID", $entry->getOrderId()) - ->set("CREDIT_NOTE_ID", $entry->getCreditNoteId()) - ->set("AMOUNT", $entry->getAmountPrice()) - ; - $this->addOutputFields($row, $entry); - $loopResult->addRow($row); - } - - return $loopResult; - } -} diff --git a/Model/CreditNoteVersion.php b/Model/CreditNoteVersion.php deleted file mode 100755 index ba4bc2c..0000000 --- a/Model/CreditNoteVersion.php +++ /dev/null @@ -1,10 +0,0 @@ -getEventDispatcher()->dispatch($event, CreditNoteEvents::PROPEL_PRE_INSERT . $this->getTableName()); @@ -54,7 +52,6 @@ public function postInsert(?ConnectionInterface $con = null): void parent::postInsert($con); if ($con !== null) { - /** @var ActiveRecordInterface $this */ $event = new PropelEvent($this); $con->getEventDispatcher()->dispatch($event, CreditNoteEvents::PROPEL_POST_INSERT . $this->getTableName()); } @@ -70,7 +67,6 @@ public function preUpdate(?ConnectionInterface $con = null): bool parent::preUpdate($con); if ($con !== null) { - /** @var ActiveRecordInterface $this */ $event = new PropelEvent($this); $con->getEventDispatcher()->dispatch($event, CreditNoteEvents::PROPEL_PRE_UPDATE . $this->getTableName()); @@ -90,7 +86,6 @@ public function postUpdate(?ConnectionInterface $con = null): void parent::postUpdate($con); if ($con !== null) { - /** @var ActiveRecordInterface $this */ $event = new PropelEvent($this); $con->getEventDispatcher()->dispatch($event, CreditNoteEvents::PROPEL_POST_UPDATE . $this->getTableName()); } @@ -106,7 +101,6 @@ public function preDelete(?ConnectionInterface $con = null): bool parent::preDelete($con); if ($con !== null) { - /** @var ActiveRecordInterface $this */ $event = new PropelEvent($this); $con->getEventDispatcher()->dispatch($event, CreditNoteEvents::PROPEL_PRE_DELETE . $this->getTableName()); @@ -126,7 +120,6 @@ public function postDelete(?ConnectionInterface $con = null): void parent::postDelete($con); if ($con !== null) { - /** @var ActiveRecordInterface $this */ $event = new PropelEvent($this); $con->getEventDispatcher()->dispatch($event, CreditNoteEvents::PROPEL_POST_DELETE . $this->getTableName()); } diff --git a/Smarty/Plugins/CreditNoteFormat.php b/Smarty/Plugins/CreditNoteFormat.php deleted file mode 100644 index 736973e..0000000 --- a/Smarty/Plugins/CreditNoteFormat.php +++ /dev/null @@ -1,204 +0,0 @@ -gilles.bourgeat@gmail.com> - */ -class CreditNoteFormat extends AbstractSmartyPlugin -{ - /** @var RequestStack */ - protected $requestStack; - - public function __construct(RequestStack $requestStack) - { - $this->requestStack = $requestStack; - } - - /** - * - * display an address in expected format - * - * available parameters : - * address => the id of the address to display - * order_address => the id of the order address to display - * from_country_id => the country id - * dec_point => separator for the decimal point - * thousands_sep => thousands separator - * symbol => Currency symbol - * - * ex : {format_money number="1246.12" decimals="1" dec_point="," thousands_sep=" " symbol="€"} will output "1 246,1 €" - * - * @param $params - * @param null $template - * @throws \TheliaSmarty\Template\Exception\SmartyPluginException - * @return string the expected number formatted - */ - public function formatAddress($params, $template = null) - { - $postal = filter_var( - $this->getParam($params, "postal", null), - FILTER_VALIDATE_BOOLEAN - ); - - $html = filter_var( - $this->getParam($params, "html", true), - FILTER_VALIDATE_BOOLEAN - ); - - $htmlTag = $this->getParam($params, "html_tag", "p"); - $originCountry = $this->getParam($params, "origin_country", null); - $locale = $this->getParam($params, "locale", $this->getDefaultLocale()); - - // extract html attributes - $htmlAttributes = []; - foreach ($params as $k => $v) { - if (strpos($k, 'html_') !== false && $k !== 'html_tag') { - $htmlAttributes[substr($k, 5)] = $v; - } - } - - // get address or order address - $address = null; - if (null !== $id = $this->getParam($params, "credit_note_id", null)) { - $creditNoteAddress = CreditNoteAddressQuery::create()->findOneById( - CreditNoteQuery::create()->findOneById($id)->getInvoiceAddressId() - ); - - if (null === $creditNoteAddress) { - return ''; - } - - // Thelia 3 type-hints AddressFormat::formatTheliaAddress() against - // OrderAddress, so wrap the CreditNoteAddress into a transient - // (never persisted) OrderAddress with the same fields. - $address = $this->toOrderAddress($creditNoteAddress); - } else { - // try to parse arguments to build address - $address = $this->getAddressFormParams($params); - } - - if (null === $address) { - throw new SmartyPluginException( - "Either address, order_address or full list of address fields should be provided" - ); - } - - $addressFormat = AddressFormat::getInstance(); - if ($postal) { - if ($address instanceof Address) { - $formattedAddress = $addressFormat->postalLabelFormat($address, $locale, $originCountry); - } else { - $formattedAddress = $addressFormat->postalLabelFormatTheliaAddress($address, $locale, $originCountry); - } - } else { - if ($address instanceof Address) { - $formattedAddress = $addressFormat->format($address, $locale, $html, $htmlTag, $htmlAttributes); - } else { - $formattedAddress = $addressFormat->formatTheliaAddress($address, $locale, $html, $htmlTag, $htmlAttributes); - } - } - - return $formattedAddress; - } - - /** - * Wrap a CreditNoteAddress into a transient OrderAddress (identical columns), - * so it can be passed to Thelia 3's OrderAddress-typed AddressFormat helpers. - */ - protected function toOrderAddress(CreditNoteAddress $creditNoteAddress) - { - return (new OrderAddress()) - ->setCustomerTitleId($creditNoteAddress->getCustomerTitleId()) - ->setCompany($creditNoteAddress->getCompany()) - ->setFirstname($creditNoteAddress->getFirstname()) - ->setLastname($creditNoteAddress->getLastname()) - ->setAddress1($creditNoteAddress->getAddress1()) - ->setAddress2($creditNoteAddress->getAddress2()) - ->setAddress3($creditNoteAddress->getAddress3()) - ->setZipcode($creditNoteAddress->getZipcode()) - ->setCity($creditNoteAddress->getCity()) - ->setPhone($creditNoteAddress->getPhone()) - ->setCellphone($creditNoteAddress->getCellphone()) - ->setCountryId($creditNoteAddress->getCountryId()) - ->setStateId($creditNoteAddress->getStateId()); - } - - protected function getAddressFormParams($params) - { - // Check if there is arguments - $addressArgs = [ - 'country_code', - 'administrative_area', - 'locality', - 'dependent_locality', - 'postal_code', - 'sorting_code', - 'address_line1', - 'address_line2', - 'organization', - 'recipient', - 'locale' - ]; - $valid = false; - - $address = new Address(); - - foreach ($addressArgs as $arg) { - if (null !== $argVal = $this->getParam($params, $arg, null)) { - $valid = true; - $functionName = 'with' . Container::camelize($arg); - $address = $address->$functionName($argVal); - } - } - - if (false === $valid) { - return null; - } - - return $address; - } - - /** - * @return SmartyPluginDescriptor[] - */ - public function getPluginDescriptors() - { - return array( - new SmartyPluginDescriptor("function", "credit_note_format_address", $this, "formatAddress"), - ); - } - - protected function getSession() - { - return $this->requestStack->getCurrentRequest()->getSession(); - } - - protected function getDefaultLocale(): string - { - $request = $this->requestStack->getCurrentRequest(); - if (null === $request || !$request->hasSession()) { - return \Thelia\Model\LangQuery::create()->findOneByByDefault(true)?->getLocale() ?? 'en_US'; - } - - return $request->getSession()->getLang()->getLocale(); - } -} diff --git a/templates/backOffice/default/ajax/credit-note-modal.html b/templates/backOffice/default/ajax/credit-note-modal.html deleted file mode 100755 index b366db6..0000000 --- a/templates/backOffice/default/ajax/credit-note-modal.html +++ /dev/null @@ -1,451 +0,0 @@ -{form name="credit_note_create"} - -{if $creditNote->getInvoiceRef() } - {$invoiced = true} -{else} - {$invoiced = false} -{/if} - -
getId()}}{else}{url path="/admin/credit-note/create"}{/if}"> - {if $app->request->get('success-url')} - - {/if} - - - -
-
- -
- {form_field field='currency_id'} - {if $creditNote->getOrder()} - - {intl l="This credit note use the currency : %currency" d="creditnote.bo.default" currency=$creditNote->getCurrency()->getSymbol()} - {else} - {capture name="currency"} - - {/capture} - {intl l="This credit note use the currency : %currency" d="creditnote.bo.default" currency=$smarty.capture.currency} - {/if} - {/form_field} -
- - {if $creditNote->getRef()} -
- {intl l="Credit note ref : %ref" d="creditnote.bo.default" ref=$creditNote->getRef()} -
- {/if} - - {if $creditNote->getInvoiceRef()} -
- {intl l="Invoice ref : %ref" d="creditnote.bo.default" ref=$creditNote->getInvoiceRef()} -
- {/if} - - {* Credit note status select *} -
- - {form_field field='status_id'} - - {/form_field} -
- - {* Credit note type select *} -
- - {form_field field='type_id'} - - {/form_field} -
- - {* Credit note customer select *} -
- - {form_field field='customer_id'} - - {/form_field} -
- - {* Credit note order select *} - {$hasError = false} - {if $creditNote->getCreditNoteType()->getRequiredOrder() && !$creditNote->getOrder()} - {$hasError = true} - {/if} - -
- - {form_field field='order_id'} - - {/form_field} -
- - -
- {* address invoice *} -
-
-
{intl l="Invoice address" d="creditnote.bo.default"}
-
- - {$other = false} -
- {form_field field='invoice_address_id'} - {if !$data} - {$other = true} - {/if} - - {/form_field} -
- -
- {form_field field='invoice_address_title'} -
- - {if !$creditNote->getCreditNoteAddress()->getCustomerTitleId()} - - {else} - {$data = $creditNote->getCreditNoteAddress()->getCustomerTitleId()} - {/if} - -
- {/form_field} - {form_field field='invoice_address_firstname'} -
- - -
- {/form_field} - {form_field field='invoice_address_lastname'} -
- - -
- {/form_field} - {form_field field='invoice_address_address1'} -
- - -
- {/form_field} - {form_field field='invoice_address_address2'} -
- - -
- {/form_field} - {form_field field='invoice_address_city'} -
- - -
- {/form_field} - {form_field field='invoice_address_zipcode'} -
- - -
- {/form_field} - {form_field field='invoice_address_country_id'} -
- - -
- {/form_field} - {form_field field='invoice_address_company'} -
- - -
- {/form_field} -
- -
-
-
- - {* Credit note order *} - {if $creditNote->getOrderId()} -
- {include file="includes/credit-note-order.html" invoiced=$invoiced} -
- {/if} - - {* Credit note order *} -
-
-
{intl l="Free amount : " d="creditnote.bo.default"}
-
-
- - - - - - - - - - - - - - {$i = 0} - {foreach from=$creditNote->getCreditNoteDetails() key=key item=creditNoteDetail} - {if !$creditNoteDetail->getOrderProductId()} - {$i = $i + 1} - {include file="includes/credit-note-free-amount.html"} - {/if} - {/foreach} - - - - -
- {intl l="Type" d="creditnote.bo.default"} - - {intl l="Title" d="creditnote.bo.default"} - - {intl l="Amount without tax %currency" d="creditnote.bo.default" currency=$creditNote->getCurrency()->getSymbol()} - - {intl l="Tax rule" d="creditnote.bo.default"} - - {intl l="Amount with tax %currency" d="creditnote.bo.default" currency=$creditNote->getCurrency()->getSymbol()} - - {if !$invoiced} - - {/if} -
-
- {intl l="No free amount." d="creditnote.bo.default"} -
-
- -
-
-
-
- -
- {if $creditNote->getOrder() !== null && $creditNote->getOrder()->getDiscount() > 0} -
-
{intl l="Order discount informations : " d="creditnote.bo.default"}
-
-
-
- {form_field field='discount_without_tax'} -
- {intl l="Discount without tax : " d="creditnote.bo.default"} - getCreditNoteType()->getCode() == 'order_full_refund'}disabled{/if} /> -
- {/form_field} -
-
- {form_field field='discount_with_tax'} -
- {intl l="Discount with tax : " d="creditnote.bo.default"} - getCreditNoteType()->getCode() == 'order_full_refund'}disabled{/if} /> -
- {/form_field} -
-
-
-
- {/if} -
- -
-
-
{intl l="Credit Note Informations : " d="creditnote.bo.default"}
-
-
-
-

- {intl l="Total without tax : " d="creditnote.bo.default"}{format_money number=$creditNote->getTotalPrice() currency_id=$creditNote->getCurrencyId()} -

-
-
-

- {intl l="Taxes : " d="creditnote.bo.default"}{format_money number=($creditNote->getTotalPriceWithTax() - $creditNote->getTotalPrice()) currency_id=$creditNote->getCurrencyId()} -

-
-
-

- {intl l="Total with tax : " d="creditnote.bo.default"}{format_money number=$creditNote->getTotalPriceWithTax() currency_id=$creditNote->getCurrencyId()} -

-
-
-
-
-
- - {* Credit note comment *} -
-
-
{intl l="Internal comment : " d="creditnote.bo.default"}
-
- {form_field field='comment'} - - {/form_field} -
-
- {if $creditNote->getId()} - {ifloop rel="credit-note-comment"} -
-
- {loop type="credit-note-comment" name="credit-note-comment" credit_note_id=$creditNote->getId() order="id-reverse"} - {intl l="User" d="creditnote.bo.default"} : {$ADMIN_FIRST_NAME} {$ADMIN_LAST_NAME}{format_date date=$CREATE_DATE} : -

-
- {$COMMENT|nl2br nofilter} -
-
- {/loop} -
-
- {/ifloop} - {elseloop rel="credit-note-comment"} -
- {intl l="No comments found for this credit note" d="creditnote.bo.default"} -
- {/elseloop} - {/if} -
-
-
- - {if $invoiced} -
-
-
{intl l="Credit note used : " d="creditnote.bo.default"}
-
- {loop type="order-credit-note" name="order-credit-note" credit_note_id=$creditNote->getId()} - {loop type="order" name="order" customer="*" backend_context=true id=$ORDER_ID} -
- {intl l="Used by order :" d="creditnote.bo.default"} {$REF} -
- {/loop} - {/loop} -
-
-
- {/if} - - {* Credit note version *} - {*{if $creditNote->getId()} -
-
-
{intl l="Credit note versions : " d="creditnote.bo.default"}
-
- {ifloop rel="credit-note-version"} - {loop type="credit-note-version" name="credit-note-version" id=$creditNote->getId()} - // toto : credit note version - {/loop} - {/ifloop} - {elseloop rel="credit-note-version"} -
- {intl l="No version found for this credit note" d="creditnote.bo.default"} -
- {/elseloop} -
-
-
- {/if}*} - - - - {form_field field='ui_target'} - - {/form_field} - - {form_field field='ui_target_id'} - - {/form_field} - -{/form} \ No newline at end of file diff --git a/templates/backOffice/default/assets/js/script.js b/templates/backOffice/default/assets/js/script.js deleted file mode 100755 index ccfb4e2..0000000 --- a/templates/backOffice/default/assets/js/script.js +++ /dev/null @@ -1,364 +0,0 @@ -"use strict"; -(function($) { - var $modal = $('#modal-credit-note-delete'); - - $modal.on('show.bs.modal', function(event){ - var url = $(event.relatedTarget).data('ajax-url'); - - $modal.find('form').attr('action', url); - }); - -})(jQuery); - -(function($){ - var $modal = $('#modal-credit-note'); - var currentRequest; - var lastAjaxUrl; - // fix bug bootstrap 3 and select2 - $.fn.modal.Constructor.prototype.enforceFocus = function() {}; - - /****** Modal methods ******/ - $modal.loaderOff = function(){ - $modal.find('.modal-loader').addClass('hidden'); - $modal.find('.modal-body').removeClass('hidden'); - }; - - $modal.loaderOn = function(){ - $modal.find('.modal-loader').removeClass('hidden'); - $modal.find('.modal-body').addClass('hidden'); - }; - - $modal.reset = function(){ - $modal.hideError(); - $modal.loaderOn(); - }; - - $modal.loadAjax = function(event, data){ - if (typeof data === 'undefined') { - data = {}; - } - - // kill last ajax request if not if it's not finished - if (currentRequest) currentRequest.abort(); - - var url = $(event.relatedTarget).data('ajax-url'); - if (typeof url === 'undefined') { - url = lastAjaxUrl; - } else { - lastAjaxUrl = url; - $modal.loaderOn(); - } - - if ($(event.relatedTarget).data('success-url')) { - data['success-url'] = $(event.relatedTarget).data('success-url'); - } - - if (!data['credit_note_create[action]']) { - data['credit_note_create[action]'] = 'view'; - } - - if ($(event.relatedTarget).data('credit-note-id')) { - data['credit_note_create[credit_note_id]'] = $(event.relatedTarget).data('credit-note-id'); - } - - if ($(event.relatedTarget).data('order-id')) { - data['credit_note_create[order_id]'] = $(event.relatedTarget).data('order-id'); - } - - if ($(event.relatedTarget).data('order-product-id')) { - data['credit_note_create[order_product_quantity][' + $(event.relatedTarget).data('order-product-id') + ']'] = 1; - } - - if ($(event.relatedTarget).data('type-id')) { - data['credit_note_create[type_id]'] = $(event.relatedTarget).data('type-id'); - } - - if ($(event.relatedTarget).data('customer-id')) { - data['credit_note_create[customer_id]'] = $(event.relatedTarget).data('customer-id'); - } - - // to avoid a display bug with select2 - setTimeout(function(data){ - // ajax start - currentRequest = $.ajax({ - url: url, - data: data, - method: 'POST' - }); - - // ajax success - currentRequest.done(function(data){ - $modal.loaderOff(); - $modal.find('.modal-body').html(data); - $modal.modalReady(); - }); - - // ajax error - currentRequest.fail(function(jqXHR, textStatus){ - $modal.displayError(jqXHR, textStatus); - }); - }, 100, data); - }; - - $modal.displayError = function(jqXHR, textStatus){ - if (jqXHR.statusText === 'abort') return; - $modal.loaderOff(); - $modal.find('.modal-body').addClass('hidden'); - var $error = $modal.find('.modal-error').removeClass('hidden'); - $error.find('.textStatus').html(textStatus); - $error.find('iframe').contents().find('html').html(jqXHR.responseText); - }; - - $modal.hideError = function(){ - $modal.find('.modal-error').addClass('hidden').find('iframe').contents().find('html').empty(); - }; - /****** End Modal methods ******/ - - /****** Modal events ******/ - $modal.on('show.bs.modal', function(event){ - $modal.loadAjax(event); - }); - - $modal.on('hidden.bs.modal', function(){ - $modal.reset(); - lastAjaxUrl = undefined; - }); - /****** End Modal events ******/ - - $modal.modalReady = function(){ - var $form = $modal.find('.modal-body form'); - - var initSelect = function($target){ - return $target.select2({ - templateResult: function(data){ - if (!data.id) return data.text; - var prefix = data.element.dataset.color ? ' ' : ''; - return $(prefix + '' + data.text + ''); - }, - templateSelection: function(data){ - var prefix = data.element.dataset.color ? ' ' : ''; - return $(prefix + '' + data.text + ''); - } - }); - }; - - var initAjaxSelect = function($target){ - return $target.select2({ - ajax: { - url: $target.data('url'), - dataType: 'json', - delay: 250, - data: function (params){ - return { - q: params.term, - customerId: $target.data('customer-id') - }; - }, - processResults: function (data){ - return {results: data.items}; - }, - error: function(jqXHR, textStatus){ - if (jqXHR.statusText === 'abort') return; - $target.select2('destroy'); - $modal.displayError(jqXHR, textStatus); - }, - cache: false - }, - minimumInputLength: 3, - placeholder: $target.data('placeholder'), - templateResult: function(data){ - if (data.loading) return data.text; - - var markup = "
"; - markup += data.ref + ' : (' + data.firstname + ' ' + data.lastname + ')' + '
' + data.address + ''; - markup += "
"; - - return $(markup); - }, - templateSelection: function(data){ - if (data.text) { - return data.text; - } - - return data.ref + ' : (' + data.firstname + ' ' + data.lastname + ')'; - } - }); - }; - - var $selectType = initSelect($form.find('.js-select-type')); - var $selectStatus = initSelect($form.find('.js-select-status')); - var $selectCustomer = initAjaxSelect($form.find('.js-select-customer')); - var $selectInvoiceAddress = initSelect($form.find('.js-select-invoice-address')); - - var $selectOrder = $form.find('.js-select-order'); - if ($selectOrder.data('customer-id')) { - initSelect($selectOrder); - } else { - initAjaxSelect($selectOrder); - } - - var getFormData = function(data){ - var formData = $form.serializeArray(); - - for (var i in formData) { - for (var e in data) { - if (formData[i].name === e) { - formData[i].value = data[e]; - delete data[e]; - } - } - } - - for (var e in data) { - formData.push({ - name: i, - value: data[i] - } - ); - } - - return formData - }; - - $selectOrder.on('select2:select', function(event){ - $modal.loadAjax(event, getFormData({ - 'credit_note_create[order_id]': event.params.data.id, - 'credit_note_create[action]': 'refresh' - })); - }); - - $selectCustomer.on('select2:select', function(event){ - $modal.loadAjax(event, getFormData({ - 'credit_note_create[customer_id]': event.params.data.id, - 'credit_note_create[action]': 'refresh' - })); - }); - - $selectStatus.on('select2:select', function(event){ - $modal.loadAjax(event, getFormData({ - 'credit_note_create[action]': 'refresh' - })); - }); - - $selectInvoiceAddress.on('select2:select', function(event){ - $modal.loadAjax(event, getFormData({ - 'credit_note_create[action]': 'refresh' - })); - }); - - $selectType.on('select2:select', function(event){ - $modal.loadAjax(event, getFormData({ - 'credit_note_create[action]': 'refresh' - })); - }); - - $form.on('change', '.js-field-currency', function(event){ - $modal.loadAjax(event, getFormData({ - 'credit_note_create[action]': 'refresh' - })); - }); - - $form.on('change', '.js-order-product-quantity', function(event){ - $modal.loadAjax(event, getFormData({ - 'credit_note_create[action]': 'refresh' - })); - }); - - $form.on('keyup change', '.js-action-refresh', function(event){ - if ($(this).val().length) { - refreshWithTimer($form, event); - } - }); - - /*******************************************/ - /*********** Table Free Amount *************/ - /*******************************************/ - var $tableFreeAmount = $form.find('.js-table-free-amount'); - var templateFreeAmount = $('#template-credit-note-free-amount').html(); - - $tableFreeAmount.on('click', '.js-action-add', function(event){ - event.preventDefault(); - $(this).data('key', parseInt($(this).data('key')) + 1); - - var templateFreeAmountWithKey = templateFreeAmount.replace(/\[\]/g, '[' + $(this).data('key') + ']'); - $tableFreeAmount.find('tbody').append(templateFreeAmountWithKey); - - if ($tableFreeAmount.find('tbody tr').not('.js-no-free-amount').length) { - $tableFreeAmount.find('.js-no-free-amount').addClass('hidden'); - } else { - $tableFreeAmount.find('.js-no-free-amount').removeClass('hidden'); - } - }); - - $tableFreeAmount.on('click', '.js-action-delete', function(event){ - event.preventDefault(); - $(this).parents('tr').remove(); - - if ($tableFreeAmount.find('tbody tr').not('.js-no-free-amount').length) { - $tableFreeAmount.find('.js-no-free-amount').addClass('hidden'); - } else { - $tableFreeAmount.find('.js-no-free-amount').removeClass('hidden'); - } - - $modal.loadAjax(event, getFormData({ - 'credit_note_create[action]': 'refresh' - })); - }); - - $tableFreeAmount.on('change', '.js-field-tax-rule', function(event){ - $(this).parents('tr').find('.js-field-amount-without-tax').trigger('keyup'); - }); - - var currentRequestFreeAmount; - $tableFreeAmount.on('keyup', '.js-field-amount-without-tax, .js-field-amount-with-tax', function(event){ - if (currentRequestFreeAmount) currentRequestFreeAmount.abort(); - - var $th = $(this), $thr = $th.parents('tr'); - - currentRequestFreeAmount = $.ajax({ - url: $(this).data('url'), - dataType: 'json', - data: { - price: parseFloat($(this).val()), - tax_rule: parseInt($thr.find('.js-field-tax-rule').val()) - } - }); - - // ajax success - currentRequestFreeAmount.done(function(data){ - if ($th.hasClass('js-field-amount-without-tax')) { - $thr.find('.js-field-amount-with-tax').val(data.result); - } else { - $thr.find('.js-field-amount-without-tax').val(data.result); - } - - refreshWithTimer(event); - }); - - // ajax error - currentRequestFreeAmount.fail(function(jqXHR, textStatus){ - if (jqXHR.statusText === 'abort') return; - $modal.displayError(jqXHR, textStatus); - }); - }); - - var timer = null; - function refreshWithTimer(event) { - if (timer !== null) { - clearTimeout(timer); - timer = null; - } - timer = setTimeout(function(){ - $modal.loadAjax(event, getFormData({ - 'credit_note_create[action]': 'refresh' - })); - }, 700); - } - - /*******************************************/ - /********* End Table Free Amount ***********/ - /*******************************************/ - }; -})( - jQuery -); diff --git a/templates/backOffice/default/credit-note-list.html b/templates/backOffice/default/credit-note-list.html deleted file mode 100755 index c128899..0000000 --- a/templates/backOffice/default/credit-note-list.html +++ /dev/null @@ -1,48 +0,0 @@ -{extends file="admin-layout.tpl"} - -{block name="no-return-functions"} - {$admin_current_location = 'credit-notes'} -{/block} - -{block name="page-title"}{intl l='Credit notes' d="creditnote.bo.default"}{/block} - -{block name="check-resource"}admin.credit-note{/block} -{block name="check-access"}view{/block} - -{block name="main-content"} -
-
- - - - {hook name="credit-notes.top"} - - {include file="includes/credit-note-search.html"} - -
-
-
- {include file="includes/credit-note-table.html"} -
-
-
- - {hook name="credit-notes.bottom"} - -
- - {include file="includes/credit-note-modal.html"} -
- -{/block} - -{block name="javascript-initialization"} - {include file="includes/credit-note-js.html"} -{/block} - -{block name="javascript-last-call"} - {hook name="credit-notes.js"} -{/block} diff --git a/templates/backOffice/default/hook/customer.edit.html b/templates/backOffice/default/hook/customer.edit.html deleted file mode 100755 index 41a6347..0000000 --- a/templates/backOffice/default/hook/customer.edit.html +++ /dev/null @@ -1,5 +0,0 @@ -
-
- {include file="includes/credit-note-table.html" customer_id=$customer_id|default:null} -
-
\ No newline at end of file diff --git a/templates/backOffice/default/hook/main.footer-js.html b/templates/backOffice/default/hook/main.footer-js.html deleted file mode 100755 index 00260c9..0000000 --- a/templates/backOffice/default/hook/main.footer-js.html +++ /dev/null @@ -1,52 +0,0 @@ - - \ No newline at end of file diff --git a/templates/backOffice/default/hook/order-edit.product-list.html b/templates/backOffice/default/hook/order-edit.product-list.html deleted file mode 100644 index c2bdc74..0000000 --- a/templates/backOffice/default/hook/order-edit.product-list.html +++ /dev/null @@ -1,39 +0,0 @@ -{if $creditNoteDetails|default:[]|count > 0} - - - - - - - - - - {foreach from=$creditNoteDetails item=creditNoteDetail} - {if $creditNoteDetail.quantity > 0} - - - - - - {/if} - {/foreach} - -
- {intl l="Credit Note ref" d="creditnote.bo.default"} - - {intl l="Status" d="creditnote.bo.default"} - - {intl l="Quantity" d="creditnote.bo.default"} -
- - {$creditNoteDetail.ref} - - - {$creditNoteDetail.status_title} - - {$creditNoteDetail.quantity} -
-{/if} diff --git a/templates/backOffice/default/hook/order.edit-js.html b/templates/backOffice/default/hook/order.edit-js.html deleted file mode 100644 index 2ac65e2..0000000 --- a/templates/backOffice/default/hook/order.edit-js.html +++ /dev/null @@ -1,37 +0,0 @@ -{include file="includes/credit-note-js.html"} - - - - \ No newline at end of file diff --git a/templates/backOffice/default/hook/order.tab.html b/templates/backOffice/default/hook/order.tab.html deleted file mode 100755 index e8a5705..0000000 --- a/templates/backOffice/default/hook/order.tab.html +++ /dev/null @@ -1,28 +0,0 @@ -{loop type="order" name="order-tab-credit-note" id=$id customer="*" backend_context=true} - {if $STATUS != 1 && $STATUS != 5} -
-
- {include file="includes/credit-note-table.html" order_id=$id} -
-
- {else} -
- - - - - - - - -
- {intl l="Credit notes" d="creditnote.bo.default"} -
-
- {intl l="You can not create a credit note for this order because it is not invoiced." d="creditnote.bo.default"} -
-
-
- - {/if} -{/loop} \ No newline at end of file diff --git a/templates/backOffice/default/includes/credit-note-free-amount.html b/templates/backOffice/default/includes/credit-note-free-amount.html deleted file mode 100755 index f4113db..0000000 --- a/templates/backOffice/default/includes/credit-note-free-amount.html +++ /dev/null @@ -1,65 +0,0 @@ -{$creditNoteDetail = $creditNoteDetail|default:null} - - - {form_field field='free_amount_type' value_key=$key} -
- -
- {/form_field} - - - {form_field field='free_amount_title' value_key=$key} -
- -
- {/form_field} - - - {form_field field='free_amount_price' value_key=$key} -
- -
- {/form_field} - - - {form_field field='free_amount_tax_rule_id' value_key=$key} -
- -
- {/form_field} - - - {form_field field='free_amount_price_with_tax' value_key=$key} -
- -
- {/form_field} - - -
- {form_field field='free_amount_id' value_key=$key} - - {/form_field} - - {if !$invoiced|default:null} - - {/if} -
- - \ No newline at end of file diff --git a/templates/backOffice/default/includes/credit-note-js.html b/templates/backOffice/default/includes/credit-note-js.html deleted file mode 100755 index f32dd1f..0000000 --- a/templates/backOffice/default/includes/credit-note-js.html +++ /dev/null @@ -1,46 +0,0 @@ - - -{javascripts file='assets/js/script.js' source="CreditNote"} - -{/javascripts} - - -{javascripts file='assets/js/moment-with-locales.min.js'} - -{/javascripts} - -{javascripts file='assets/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js'} - -{/javascripts} - - diff --git a/templates/backOffice/default/includes/credit-note-modal.html b/templates/backOffice/default/includes/credit-note-modal.html deleted file mode 100755 index 6418d23..0000000 --- a/templates/backOffice/default/includes/credit-note-modal.html +++ /dev/null @@ -1,53 +0,0 @@ - - - \ No newline at end of file diff --git a/templates/backOffice/default/includes/credit-note-order.html b/templates/backOffice/default/includes/credit-note-order.html deleted file mode 100755 index 6a98989..0000000 --- a/templates/backOffice/default/includes/credit-note-order.html +++ /dev/null @@ -1,156 +0,0 @@ -{loop type="order" name="the-order" id=$creditNote->getOrderId() customer="*" backend_context=true} -
-
- {intl l="Order Informations : " d="creditnote.bo.default"} - - {loop type="order-status" name="all-status" id=$STATUS} - {intl l="Status : %title" d="creditnote.bo.default" title=$TITLE} - {/loop} - - {intl l="Ref :" d="creditnote.bo.default"} {$REF} - -
-
-
- - - - - {hook name="order-edit.order-product-table-header" location="order_edit_table_header" } - - - - - - - - - - {loop type="order_product" name="order-products" order=$ID} - {if $WAS_IN_PROMO == 1} - {assign "realPrice" $PROMO_PRICE} - {assign "realTax" $PROMO_PRICE_TAX} - {assign "realTaxedPrice" $TAXED_PROMO_PRICE} - {assign "realTotalPrice" $TOTAL_TAXED_PROMO_PRICE} - {else} - {assign "realPrice" $PRICE} - {assign "realTax" $PRICE_TAX} - {assign "realTaxedPrice" $TAXED_PRICE} - {assign "realTotalPrice" $TOTAL_TAXED_PRICE} - {/if} - {hook name="order-edit.before-order-product-row" location="before-order-product-row" order_id=$order_id order_product_id=$ID} - - - {hook name="order-edit.order-product-table-row" location="order_edit_table_row" order_product_id={$ID} } - - - - - - - {hook name="order-edit.after-order-product-row" location="after-order-product-row" order_id=$order_id order_product_id=$ID} - {/loop} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{intl l="Product" d="creditnote.bo.default"}{intl l="Unit. price" d="creditnote.bo.default"}{intl l="Tax" d="creditnote.bo.default"}{intl l="Unit taxed price" d="creditnote.bo.default"}{intl l="Quantity" d="creditnote.bo.default"}{intl l="Total with tax" d="creditnote.bo.default"}
- {ifloop rel="my_product_loop"} - {loop type="product" name="my_product_loop" visible="*" ref=$REF return_url=false} - {$REF} - {$TITLE} - {if $VIRTUAL}{/if} - {/loop} -
-
{intl l='Combination reference' d="creditnote.bo.default"}
-
- {$PRODUCT_SALE_ELEMENTS_REF} -
-
- {/ifloop} - {elseloop rel="my_product_loop"} - {* The product doesn't exist anymore *} - {$TITLE} - {if $VIRTUAL}{/if} - {/elseloop} - {ifloop rel="combinations"} -
- {loop type="order_product_attribute_combination" name="combinations" order_product=$ID} -
{$ATTRIBUTE_TITLE}
-
{$ATTRIBUTE_AVAILABILITY_TITLE}
- {/loop} -
- {/ifloop} - {hook name="order-edit.product-list" location="order-product-list" order_id=$order_id order_product_id=$ID} -
{format_money number=$realPrice currency_id=$CURRENCY}{format_money number=$realTax currency_id=$CURRENCY}{format_money number=$realTaxedPrice currency_id=$CURRENCY} - {if $creditNote->getCreditNoteType()} - - {$currentQuantity = 0} - - {if $creditNote->getCreditNoteType()->getCode() == 'order_full_refund'} - {$currentQuantity = $QUANTITY} - {else} - {foreach from=$creditNote->getCreditNoteDetails() item=creditNoteDetail} - {if $creditNoteDetail->getOrderProductId() == $ID} - {$currentQuantity = $creditNoteDetail->getQuantity()} - {/if} - {/foreach} - {/if} - - {form_field field='order_product_quantity' key=$ID} - {if $invoiced|default:null or $creditNote->getCreditNoteType()->getCode() == 'order_full_refund'} - - {$currentQuantity} - {else} - - {/if} - {/form_field} - {/if} - / {$QUANTITY} - {format_money number=$realTotalPrice currency_id=$CURRENCY}
- {intl l="Total without discount" d="creditnote.bo.default"}{format_money number=$TOTAL_TAXED_AMOUNT-$POSTAGE+$DISCOUNT currency_id=$CURRENCY}
{intl l="Discount" d="creditnote.bo.default"}{format_money number=$DISCOUNT currency_id=$CURRENCY}
{intl l="Coupon code" d="creditnote.bo.default"} - {loop type="order_coupon" name="couponcode" order=$ID} - {$CODE}{if $LOOP_COUNT != $LOOP_TOTAL}, {/if} - {/loop} - {elseloop rel="couponcode"} - Ø - {/elseloop} -
{intl l="Total including discount" d="creditnote.bo.default"}{format_money number=$TOTAL_TAXED_AMOUNT-$POSTAGE currency_id=$CURRENCY}
{intl l="Postage" d="creditnote.bo.default"} - {format_money number=$POSTAGE currency_id=$CURRENCY} - ({format_money number=$POSTAGE_TAX currency_id=$CURRENCY}) -
{intl l="Total" d="creditnote.bo.default"}{format_money number=$TOTAL_TAXED_AMOUNT currency_id=$CURRENCY}
-
-
-
- -{/loop} \ No newline at end of file diff --git a/templates/backOffice/default/includes/credit-note-search.html b/templates/backOffice/default/includes/credit-note-search.html deleted file mode 100644 index cece2f5..0000000 --- a/templates/backOffice/default/includes/credit-note-search.html +++ /dev/null @@ -1,78 +0,0 @@ -{assign credit_note_ref {$smarty.get.ref|default:null}} -{assign date_min {$smarty.get.creditNoteDateMin|default:null}} -{assign date_max {$smarty.get.creditNoteDateMax|default:null}} - -{if $date_max} - {$date_max = date("d/m/Y", strtotime($date_max))} -{/if} - -{if $date_min} - {$date_min = date("d/m/Y", strtotime($date_min))} -{/if} - -
-
-
-
- {intl l="Search" d="creditnote.bo.default"} -
- - {form name='credit_note_search_form'} -
- - {form_hidden_fields form=$form} - -
-
- {form_field form=$form field="ref"} -
- - -
- {/form_field} -
-
- {form_field form=$form field="creditNoteDateMin"} -
- - -
- - -
-
- {/form_field} -
- -
- {form_field form=$form field="creditNoteDateMax"} -
- - -
- - -
-
- {/form_field} -
-
- - - {hook name='credit-notes.search.form'} - - - - - -
- {/form} -
-
-
diff --git a/templates/backOffice/default/includes/credit-note-table.html b/templates/backOffice/default/includes/credit-note-table.html deleted file mode 100755 index 206ba6b..0000000 --- a/templates/backOffice/default/includes/credit-note-table.html +++ /dev/null @@ -1,217 +0,0 @@ -{assign credit_note_page {$smarty.get.credit_note_page|default:1}} - -{assign credit_note_order {$smarty.get.credit_note_order|default:'id'}} -{assign credit_note_status {$smarty.get.status_id|default:null}} - -{assign credit_note_ref {$smarty.get.ref|default:null}} -{assign credit_note_date_min {$smarty.get.creditNoteDateMin|default:null}} -{assign credit_note_date_max {$smarty.get.creditNoteDateMax|default:null}} - -
- - - - - - - - - - - - - {if !$customer_id|default:null && !$order_id|default:null} - - {/if} - {if !$order_id|default:null} - - {/if} - - - - - - - - - {ifloop rel="credit-note"} - - {loop type="credit-note" name="credit-note" - status_id=$credit_note_status - order=$credit_note_order - page=$credit_note_page - customer_id=$customer_id|default:null - order_id=$order_id|default:null - limit={config key="number_default_results_per_page.credit_note_list" default=20} - search_by_ref=$credit_note_ref - min_date=$credit_note_date_min|default:null - max_date=$credit_note_date_max|default:null - } - - - - - - - - {if !($customer_id|default:null) && !$order_id|default:null} - - {/if} - {if !$order_id|default:null} - - {/if} - - - - - - - {/loop} - - - - - - - {/ifloop} - - {elseloop rel="credit-note"} - - - - - - {/elseloop} - -
- {intl l="Credit notes" d="creditnote.bo.default"} - - - {intl l="Add a new credit note" d="creditnote.bo.default"} - -
- {intl l="#" d="creditnote.bo.default"} - - {intl l="Ref" d="creditnote.bo.default"} - - {intl l="Invoice ref" d="creditnote.bo.default"} - - {intl l="Invoice date" d="creditnote.bo.default"} - - {admin_sortable_header - current_order=$credit_note_order - order='create-date' - reverse_order='create-date-reverse' - path={url path='/admin/credit-note'} - request_parameter_name='credit_note_order' - label="{intl l='Create date' d="creditnote.bo.default"}" - } - - {admin_sortable_header - current_order=$credit_note_order - order='update-date' - reverse_order='update-date-reverse' - path={url path='/admin/credit-note'} - request_parameter_name='credit_note_order' - label="{intl l='Update date' d="creditnote.bo.default"}" - } - - {intl l="Customer" d="creditnote.bo.default"} - - {intl l="Order" d="creditnote.bo.default"} - - {intl l="Status" d="creditnote.bo.default"} - - {intl l="Type" d="creditnote.bo.default"} - - {intl l="Total with tax" d="creditnote.bo.default"} - - {intl l="Total without tax" d="creditnote.bo.default"} - - {intl l="Action" d="creditnote.bo.default"} -
- {$ID} - - {$REF} - - {$INVOICE_REF} - - {if $INVOICE_DATE != null} - {format_date date=$INVOICE_DATE} - {/if} - {format_date date=$CREATE_DATE}{format_date date=$UPDATE_DATE} - {$CUSTOMER_NAME} - - {if $ORDER_ID} - {$ORDER_REF} - {/if} - - {$STATUS_TITLE} - - {$TYPE_TITLE} - - {format_money number=$TOTAL_PRICE_WITH_TAX currency_id=$CURRENCY_ID} - - {format_money number=$TOTAL_PRICE currency_id=$CURRENCY_ID} - - {if !$INVOICE_REF} - - {else} - - {intl l="PDF" d="creditnote.bo.default"} - {/if} - {if !$INVOICE_REF} - - {/if} -
- {include - file = "includes/pagination.html" - - loop_ref = "credit-note" - page_param_name = 'credit_note_page' - max_page_count = 10 - page_url = {url path="/admin/credit-note" - type=$type_filter|default:null - status_id=$credit_note_status - credit_note_order=$credit_note_order - search_term=$search_term|default:null - search_in=$search_in|default:null - ref=$credit_note_ref|default:null - creditNoteDateMin=$credit_note_date_min|default:null - creditNoteDateMax=$credit_note_date_max|default:null - } - } -
-
- {intl l='You have no credit notes for the moment.' d="creditnote.bo.default"} -
-
-
diff --git a/templates/backOffice/default/module-configuration.html b/templates/backOffice/default/module-configuration.html deleted file mode 100644 index e72476a..0000000 --- a/templates/backOffice/default/module-configuration.html +++ /dev/null @@ -1,102 +0,0 @@ -{* Credit Note module configuration — Smarty fallback for the legacy back-office. - Rendered by ConfigHook on module.configuration. Mirrors module-configuration.html.twig. *} -
-

{intl l="Credit note configuration" d="creditnote"}

- - {form name="credit_note_config"} -
- {form_hidden_fields} - -

{intl l="Credit notes" d="creditnote"}

-
-
- {form_field field="ref_prefix"} - - - {if $error}{$message}{/if} - {/form_field} -
-
- {form_field field="ref_min_length"} - - - {if $error}{$message}{/if} - {/form_field} -
-
- {form_field field="ref_increment"} - - - {if $error}{$message}{/if} - {/form_field} -
-
- -

{intl l="Invoices" d="creditnote"}

-
-
- {form_field field="invoice_ref_prefix"} - - - {if $error}{$message}{/if} - {/form_field} -
-
- {form_field field="invoice_ref_min_length"} - - - {if $error}{$message}{/if} - {/form_field} -
-
- {form_field field="invoice_ref_increment"} - - - {if $error}{$message}{/if} - {/form_field} -
-
- -
- {form_field field="invoice_ref_with_thelia_order"} - {$use_thelia_order = {module_config module="CreditNote" key="invoice_ref_with_thelia_order" default="0"}} - - {/form_field} -
- -
- {form_field field="order_ceiling"} - {$ceiling = {module_config module="CreditNote" key="order_ceiling" default="1"}} - - {/form_field} -
- -
- {form_field field="document_locales"} - - - {if $error}{$message}{/if} - {/form_field} -
- -
- -
-
- {/form} -
diff --git a/templates/pdf/default/credit-note.html b/templates/pdf/default/credit-note.html deleted file mode 100644 index 1c3a43e..0000000 --- a/templates/pdf/default/credit-note.html +++ /dev/null @@ -1,309 +0,0 @@ -{* Set the default translation domain, that will be used by {intl} when the 'd' parameter is not set *} -{default_translation_domain domain="creditnote.pdf.default"} -{literal} - -{/literal} - - - {hook name="pdf.credit-note.header" credit_note_id=$credit_note_id} - - - - {hook name="pdf.credit-note.footer-top" credit_note_id=$credit_note_id} - - - - - - - - - -
- {hook name="pdf.credit-note.imprint" credit_note_id=$credit_note_id} - {elsehook rel="pdf.credit-note.imprint"} - - {config key="store_name"} - {$addresses="{config key="store_address1"} {config key="store_address2"} {config key="store_address3"}"} - {$city="{config key="store_zipcode"} {config key="store_city"}"} - {if $addresses != " "}- {$addresses}{/if} - {if $city != " " }- {$city}{/if} - {if {config key="store_country"} } - {loop type="country" visible="*" name="address.country.title" id={config key="store_country"}} - {$TITLE}{/loop} - {/if} - {if {config key="store_business_id"} } - - {config key="store_business_id"} - {/if} -
- {if {config key="store_phone"} } - {intl l="Phone: "}{config key="store_phone"} - {/if} - {if {config key="store_email"} } - {intl l="Email: "}{config key="store_email"} - {/if} - {/elsehook} -
{intl l="page"} [[page_cu]]/[[page_nb]]
- {hook name="pdf.credit-note.footer-bottom" order=$order_id|default:null} -
- - {$taxes = []} - - {loop name="credit-note.invoice" type="credit-note" id=$credit_note_id customer="*"} - - - - - - - - - - - - - - - - - - {if $ORDER_ID} - {loop name="order" type="order" id=$ORDER_ID customer="*"} - - - - - - - {/loop} - {/if} - {hookblock name="pdf.credit-note.information" credit_note_id=$credit_note_id fields="title,value"} - {forhook rel="pdf.credit-note.information"} - - - - {/forhook} - {/hookblock} -
-

{intl l="CREDIT NOTE INVOICE"}

-

{intl l="Invoice date"} : {format_date date=$INVOICE_DATE output="date"}

{intl l="Invoice REF"} : {$INVOICE_REF}

{intl l="Credit note REF"} : {$REF}

{intl l="Customer Number"} : {loop type="customer" name="customer.invoice" id=$CUSTOMER_ID current="0"}{$REF}{/loop}

{intl l="Referance invoice REF"} : {$INVOICE_REF}

{intl l="Referance order REF"} : {$REF}

{$title} : {$value}

- - {hook name="pdf.credit-note.after-information" credit_note_id=$credit_note_id} - - - - - - - -
-

{intl l="Invoice address"}

- {credit_note_format_address credit_note_id=$ID locale=$locale} -
- - {hook name="pdf.credit-note.after-addresses" credit_note_id=$credit_note_id} - - - - - - - - - - - - - - - - - - {loop type="credit-note-detail" name="credit-note-detail" credit_note_id=$credit_note_id} - {$detailRef = ""} - {$detailPseRef = ""} - {$detailTitle = $TITLE} - {if $ORDER_PRODUCT_ID} - {loop type="order_product" name="order-product-$ORDER_PRODUCT_ID" id=$ORDER_PRODUCT_ID order=$ORDER_ID} - {$detailRef = $REF} - {$detailTitle = $TITLE} - {$detailPseRef = $PRODUCT_SALE_ELEMENTS_REF} - {/loop} - {/if} - - - - - - - - - - - {hook name="pdf.credit-note.order-product" credit_note_id=$credit_note_id order_product=$ID} - {/loop} -

{intl l="Product"}

{intl l="Unit. price"}

{intl l="Tax"}

{intl l="Unit taxed price"}

{intl l="Quantity"}

{intl l="Total with tax"}

-

{$TITLE}

-

- {if $detailRef} - {intl l="Product ref : "}{$detailRef}
- {/if} - {if $detailPseRef} - {intl l="Combination ref : "}{$detailPseRef} - {/if} -

- {if $ORDER_PRODUCT_ID} - {ifloop rel="combinations"} - {loop type="order_product_attribute_combination" name="combinations" order_product=$ORDER_PRODUCT_ID} - {$ATTRIBUTE_TITLE} - {$ATTRIBUTE_AVAILABILITY_TITLE}
- {/loop} - {/ifloop} - {/if} - {hook name="pdf.credit-note.detail-list" order_product=$ID order=$order_id|default:null} -

{if $QUANTITY}{format_money number={$PRICE / $QUANTITY} currency_id=$CURRENCY_ID}{else}{format_money number=0 currency_id=$CURRENCY_ID}{/if}

{if $QUANTITY}{format_money number={{$PRICE_WITH_TAX - $PRICE} / $QUANTITY} currency_id=$CURRENCY_ID}{else}{format_money number=0 currency_id=$CURRENCY_ID}{/if}

{if $QUANTITY}{format_money number={$PRICE_WITH_TAX / $QUANTITY} currency_id=$CURRENCY_ID}{else}{format_money number=0 currency_id=$CURRENCY_ID}{/if}

{$QUANTITY}

{format_money number=$PRICE_WITH_TAX currency_id=$CURRENCY_ID}

- - {hook name="pdf.credit-note.after-products" credit_note_id=$credit_note_id} - - - - - - - -
- - - - - - - - - - - - - - - - - - - -

{intl l="Discount"}

{format_money number=$DISCOUNT_WITH_TAX currency_id=$CURRENCY}

{intl l="Total without tax"}

{format_money number=$TOTAL_PRICE currency_id=$CURRENCY}

{intl l="Tax"}

{format_money number={$TOTAL_PRICE_WITH_TAX - $TOTAL_PRICE} currency_id=$CURRENCY}

{intl l="Total with tax"}

{format_money number=$TOTAL_PRICE_WITH_TAX currency_id=$CURRENCY}

-
- - {hook name="pdf.credit-note.after-summary" credit_note_id=$credit_note_id} - - {/loop} -
diff --git a/tests/Integration/CreditNoteDocumentLocaleTest.php b/tests/Integration/CreditNoteDocumentLocaleTest.php index f3a4ff4..294292f 100644 --- a/tests/Integration/CreditNoteDocumentLocaleTest.php +++ b/tests/Integration/CreditNoteDocumentLocaleTest.php @@ -76,14 +76,16 @@ public function aLanguageTheShopPrintsItsCreditNotesInIsServed(): void ?? $this->fixture->factory()->lang(['locale' => 'de_DE', 'code' => 'de', 'title' => 'Deutsch']); $customer->setLangId($german->getId())->save($this->getPropelConnection()); - // Inside the test transaction: rolled back with the rest. + // Inside the test transaction: rolled back with the rest. A shop without demo data has + // English as its default language: make it French, so that leaving English is visible. + $this->getPropelConnection()->exec("UPDATE lang SET by_default = (locale = 'fr_FR')"); CreditNote::setConfigValue(CreditNote::CONFIG_KEY_DOCUMENT_LOCALES, 'fr_FR, de_DE'); self::assertSame(['fr_FR', 'de_DE'], CreditNote::documentLocales()); self::assertSame('de_DE', $this->locale()->forCreditNote($this->reload($creditNote))); $customer->setLangId($this->lang('en_US')->getId())->save($this->getPropelConnection()); - self::assertNotSame('en_US', $this->locale()->forCreditNote($this->reload($creditNote)), 'English is no longer in the list'); + self::assertSame('fr_FR', $this->locale()->forCreditNote($this->reload($creditNote)), 'English is no longer in the list: the default language of the shop answers'); CreditNote::setConfigValue(CreditNote::CONFIG_KEY_DOCUMENT_LOCALES, ''); self::assertSame(CreditNoteDocumentLocale::PREFERRED, CreditNote::documentLocales(), 'empty: English and French'); diff --git a/tests/Unit/ModuleDescriptorTest.php b/tests/Unit/ModuleDescriptorTest.php index ea031b4..ff42b46 100644 --- a/tests/Unit/ModuleDescriptorTest.php +++ b/tests/Unit/ModuleDescriptorTest.php @@ -47,7 +47,7 @@ public function everyDeclaredLoopIsALoopClassOfTheModule(): void } self::assertSame( - ['credit-note', 'credit-note-address', 'credit-note-comment', 'credit-note-detail', 'credit-note-status', 'credit-note-type', 'credit-note-version', 'order-credit-note'], + ['credit-note', 'credit-note-address', 'credit-note-detail'], array_keys(array_change_key_case($this->sorted($loops))), ); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index ce9f142..0cb9804 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -84,6 +84,20 @@ } } +// The Propel models of the shop (Base/ and Map/) are generated under var/propel/test/model and +// only registered once the kernel boots. Map them now: a class_exists() before the first boot +// (the listener unit test) must see the generated table map, or its stub would be declared and +// stay in place of the real map for the integration tests of the same run. +$generatedModelDirectory = dirname($autoload, 2) . '/var/propel/test/model/'; + +spl_autoload_register(static function (string $class) use ($generatedModelDirectory): void { + $file = $generatedModelDirectory . str_replace('\\', '/', $class) . '.php'; + + if (is_file($file)) { + require $file; + } +}); + // The module and its tests, when the shop autoloader does not map them already // (module checked out outside local/modules). Longest prefix first. spl_autoload_register(static function (string $class): void {