Skip to content

Commit

Permalink
Merge pull request #2 from gillesbourgeat/fix/module-activation
Browse files Browse the repository at this point in the history
Fix module activation
  • Loading branch information
gillesbourgeat authored Jan 22, 2019
2 parents dc1688f + fb5f87a commit c28a823
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.0.0</version>
<version>1.1.0</version>
<author>
<name>Manuel Raynaud</name>
<email>[email protected]</email>
Expand Down
22 changes: 15 additions & 7 deletions InvoiceRef.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,30 @@

namespace InvoiceRef;

use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Connection\ConnectionInterface;
use Thelia\Model\ConfigQuery;
use Thelia\Model\OrderQuery;
use Thelia\Module\BaseModule;

class InvoiceRef extends BaseModule
{
const DOMAIN_NAME = "invoiceref";
/*
* You may now override BaseModuleInterface methods, such as:
* install, destroy, preActivation, postActivation, preDeactivation, postDeactivation
*
* Have fun !
*/

public function postActivation(ConnectionInterface $con = null)
{
ConfigQuery::write('invoiceRef', 1, true, true);
if (null === ConfigQuery::read('invoiceRef', null)) {
if (null !== $lastOderPaid = OrderQuery::create()
->filterByInvoiceRef(null, Criteria::NOT_EQUAL)
->orderByInvoiceRef(Criteria::DESC)
->findOne()) {
$nextRef = (int) $lastOderPaid->getInvoiceRef();
$nextRef++;

ConfigQuery::write('invoiceRef', $nextRef, true, true);
} else {
ConfigQuery::write('invoiceRef', 1, true, true);
}
}
}
}

0 comments on commit c28a823

Please sign in to comment.