Skip to content

Commit

Permalink
Order-Id was added when a license is determined by the "license_colle…
Browse files Browse the repository at this point in the history
…ction" insert tag
  • Loading branch information
doishub committed Dec 4, 2020
1 parent e2ba051 commit 9d881ce
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This extension complements a license key management and its assignment to products which can then be picked up (via insert tags) and sent via the Notification Center.

> If a member is logged in, this member will automatically be assigned the license key.
>
>When using "license_collection", it is also checked whether the member can be determined from the order record, so that licenses can be sent later and the member can be assigned to it. Furthermore, the order ID is stored in the license.
The following insert tags are available:
- `{{license_collection::*}}`
Expand Down
8 changes: 4 additions & 4 deletions src/EventListener/InsertTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,19 @@ private function replaceLicenseInsertTags($insertTag, $intId)
{
for($i=0; $i<$productsInCollection->quantity; $i++)
{
$arrProductIds[] = [$productsInCollection->product_id, $intMember];
$arrProductIds[] = [$productsInCollection->product_id, $intMember, $intId];
}
}
}else{
$arrProductIds[] = [$intId, null];
$arrProductIds[] = [$intId, null, null];
}

foreach ($arrProductIds as $product)
{
list($productId, $memberId) = $product;
list($productId, $memberId, $orderId) = $product;
$objLicences = LicenseModel::findOneByProduct($productId);

if($newLicence = LicenseHandler::getNextLicense($objLicences, $memberId))
if($newLicence = LicenseHandler::getNextLicense($objLicences, $memberId, $orderId))
{
$arrProductLicenses[] = sprintf("%s: %s", $objLicences->title, $newLicence);
}
Expand Down
10 changes: 8 additions & 2 deletions src/Resources/contao/classes/LicenseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ class LicenseHandler
* Generate and return the next valid license of a product
*
* @param int|object $varProductLicence
* @param int|null $intMemberId
* @param int|null $intMemberId
* @param int|null $intOrderId
*
* @return string
*/
public static function getNextLicense($varProductLicence, $intMemberId)
public static function getNextLicense($varProductLicence, $intMemberId = null, $intOrderId = null)
{
$logger = \System::getContainer()->get('monolog.logger.contao');

Expand Down Expand Up @@ -61,6 +62,11 @@ public static function getNextLicense($varProductLicence, $intMemberId)
$objLicence->member = $intMemberId;
}

if($intOrderId)
{
$objLicence->order = $intOrderId;
}

$objLicence->published = 1;
$objLicence->save();

Expand Down
8 changes: 7 additions & 1 deletion src/Resources/contao/dca/tl_license_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
// Subpalettes
'subpalettes' => array
(
'published' => 'member',
'published' => 'member,order',
),

// Fields
Expand Down Expand Up @@ -122,6 +122,12 @@
'eval' => array('chosen'=>true, 'includeBlankOption'=>true, 'tl_class'=>'w50'),
'sql' => "int(10) unsigned NOT NULL default 0",
),
'order' => array
(
'inputType' => 'text',
'eval' => array('tl_class'=>'w50'),
'sql' => "int(10) unsigned NOT NULL default 0"
),
'published' => array
(
'exclude' => true,
Expand Down
7 changes: 6 additions & 1 deletion src/Resources/contao/models/LicenseItemModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@

namespace Oveleon\IsotopeProductLicenses;

use Contao\Model;

/**
* Reads and writes licence items
*
* @property integer $id
* @property integer $pid
* @property string $licence
* @property integer $member
* @property integer $order
* @property string $published
*
* @method static LicenseItemModel|null findById($id, array $opt=array())
Expand All @@ -23,6 +26,7 @@
* @method static LicenseItemModel|null findOneByPid($val, array $opt=array())
* @method static LicenseItemModel|null findOneByLicence($val, array $opt=array())
* @method static LicenseItemModel|null findOneByMember($val, array $opt=array())
* @method static LicenseItemModel|null findOneByOrder($val, array $opt=array())
* @method static LicenseItemModel|null findOneByPublished($val, array $opt=array())
*
* @method static Collection|LicenseItemModel[]|LicenseItemModel|null findByPid($val, array $opt=array())
Expand All @@ -31,6 +35,7 @@
* @method static Collection|LicenseItemModel[]|LicenseItemModel|null findBy($col, $val, array $opt=array())
* @method static Collection|LicenseItemModel[]|LicenseItemModel|null findByLicence($val, array $opt=array())
* @method static Collection|LicenseItemModel[]|LicenseItemModel|null findByMember($val, array $opt=array())
* @method static Collection|LicenseItemModel[]|LicenseItemModel|null findByOrder($val, array $opt=array())
* @method static Collection|LicenseItemModel[]|LicenseItemModel|null findByPublished($val, array $opt=array())
* @method static Collection|LicenseItemModel[]|LicenseItemModel|null findAll(array $opt=array())
*
Expand All @@ -43,7 +48,7 @@
*
* @author Daniele Sciannimanica <https://github.com/doishub>
*/
class LicenseItemModel extends \Model
class LicenseItemModel extends Model
{
/**
* Table name
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/contao/models/LicenseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Oveleon\IsotopeProductLicenses;

use Contao\Model;

/**
* Reads and writes licences
*
Expand All @@ -27,7 +29,7 @@
*
* @author Daniele Sciannimanica <https://github.com/doishub>
*/
class LicenseModel extends \Model
class LicenseModel extends Model
{
/**
* Table name
Expand Down

0 comments on commit 9d881ce

Please sign in to comment.