Skip to content

Commit

Permalink
1.0.0 rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyklapatch committed Jul 21, 2018
1 parent b112b28 commit bb8bcb3
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 144 deletions.
2 changes: 1 addition & 1 deletion _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function getSnippetContent($filename = '') {
define('PKG_NAME', 'Commerce_ProjectName');
define('PKG_NAMESPACE', 'commerce_digitalproduct');
define('PKG_VERSION', '1.0.0');
define('PKG_RELEASE', 'dev');
define('PKG_RELEASE', 'rc1');

/* load modx */
require_once dirname(dirname(__FILE__)) . '/config.core.php';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<?php
/**
* Digitalproduct for Commerce.
*
* Copyright 2018 by Tony Klapatch <[email protected]>
*
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required.
*
* @package commerce_digitalproduct
* @license See core/components/commerce_digitalproduct/docs/license.txt
*/
require_once (dirname(__DIR__) . '/digitalproduct.class.php');
class Digitalproduct_mysql extends Digitalproduct {}
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
<?php
/**
* Digitalproduct for Commerce.
*
* Copyright 2018 by Tony Klapatch <[email protected]>
*
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required.
*
* @package commerce_digitalproduct
* @license See core/components/commerce_digitalproduct/docs/license.txt
*/

$xpdo_meta_map['Digitalproduct']= array (
'package' => 'commerce_digitalproduct',
'version' => '1.1',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<?php
/**
* Digitalproduct for Commerce.
*
* Copyright 2018 by Tony Klapatch <[email protected]>
*
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required.
*
* @package commerce_digitalproduct
* @license See core/components/commerce_digitalproduct/docs/license.txt
*/
require_once (dirname(__DIR__) . '/digitalproductfile.class.php');
class DigitalproductFile_mysql extends DigitalproductFile {}
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
<?php
/**
* Digitalproduct for Commerce.
*
* Copyright 2018 by Tony Klapatch <[email protected]>
*
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required.
*
* @package commerce_digitalproduct
* @license See core/components/commerce_digitalproduct/docs/license.txt
*/

$xpdo_meta_map['DigitalproductFile']= array (
'package' => 'commerce_digitalproduct',
'version' => '1.1',
Expand All @@ -23,9 +12,11 @@
array (
'digitalproduct_id' => NULL,
'secret' => '',
'resource' => NULL,
'name' => '',
'resource' => 0,
'file' => NULL,
'download_count' => 0,
'download_limit' => 0,
'download_expiry' => 0,
),
'fieldMeta' =>
Expand All @@ -46,11 +37,21 @@
'null' => false,
'default' => '',
),
'resource' =>
'name' =>
array (
'dbtype' => 'text',
'dbtype' => 'varchar',
'precision' => '190',
'phptype' => 'string',
'null' => true,
'null' => false,
'default' => '',
),
'resource' =>
array (
'dbtype' => 'int',
'attributes' => 'unsigned',
'phptype' => 'int',
'null' => false,
'default' => 0,
),
'file' =>
array (
Expand All @@ -67,6 +68,15 @@
'null' => false,
'default' => 0,
),
'download_limit' =>
array (
'dbtype' => 'int',
'attributes' => 'unsigned',
'precision' => '10',
'phptype' => 'int',
'null' => false,
'default' => 0,
),
'download_expiry' =>
array (
'dbtype' => 'int',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<?php
/**
* Digitalproduct for Commerce.
*
* Copyright 2018 by Tony Klapatch <[email protected]>
*
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required.
*
* @package commerce_digitalproduct
* @license See core/components/commerce_digitalproduct/docs/license.txt
*/
require_once (dirname(__DIR__) . '/digitalproductordershipment.class.php');
class DigitalproductOrderShipment_mysql extends DigitalproductOrderShipment {}
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
<?php
/**
* Digitalproduct for Commerce.
*
* Copyright 2018 by Tony Klapatch <[email protected]>
*
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required.
*
* @package commerce_digitalproduct
* @license See core/components/commerce_digitalproduct/docs/license.txt
*/

$xpdo_meta_map['DigitalproductOrderShipment']= array (
'package' => 'commerce_digitalproduct',
'version' => '1.1',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<?php
/**
* Digitalproduct for Commerce.
*
* Copyright 2018 by Tony Klapatch <[email protected]>
*
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required.
*
* @package commerce_digitalproduct
* @license See core/components/commerce_digitalproduct/docs/license.txt
*/
require_once (dirname(__DIR__) . '/digitalproductproduct.class.php');
class DigitalproductProduct_mysql extends DigitalproductProduct {}
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
<?php
/**
* Digitalproduct for Commerce.
*
* Copyright 2018 by Tony Klapatch <[email protected]>
*
* This file is meant to be used with Commerce by modmore. A valid Commerce license is required.
*
* @package commerce_digitalproduct
* @license See core/components/commerce_digitalproduct/docs/license.txt
*/

$xpdo_meta_map['DigitalproductProduct']= array (
'package' => 'commerce_digitalproduct',
'version' => '1.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

<object class="DigitalproductFile" table="commerce_digitalproduct_file" extends="comSimpleObject">
<field key="digitalproduct_id" dbtype="int" attributes="unsigned" precision="10" phptype="int" null="false" />
<!-- Used in URLs for tracking and viewing -->
<field key="secret" dbtype="varchar" precision="190" phptype="string" null="false" default="" />
<field key="name" dbtype="varchar" precision="190" phptype="string" null="false" default="" />

<field key="resource" dbtype="text" phptype="string" null="true" />
<field key="resource" dbtype="int" attributes="unsigned" phptype="int" null="false" default="0" />
<field key="file" dbtype="text" phptype="string" null="true" />

<field key="download_count" dbtype="int" attributes="unsigned" precision="10" phptype="int" null="false" default="0" />
<field key="download_limit" dbtype="int" attributes="unsigned" precision="10" phptype="int" null="false" default="0" />
<field key="download_expiry" dbtype="int" attributes="unsigned" precision="10" phptype="int" null="false" default="0" />

<aggregate alias="resource" class="modResource" local="resource" foreign="id" cardinality="one" owner="foreign" />
Expand Down
111 changes: 58 additions & 53 deletions core/components/commerce_digitalproduct/src/Modules/Digitalproduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public function initialize(EventDispatcher $dispatcher)
public function getDigitalProducts(Checkout $event)
{
$step = $event->getStep();
if (!($step instanceof ThankYou)) {
//if (!($step instanceof ThankYou)) {
if (!($step instanceof Payment)) {
return;
}

Expand Down Expand Up @@ -94,50 +95,22 @@ public function processDigitalProducts($order)
]);
$digitalProduct->save();

$id = $product->get('id');
// Get the resources attached to this product
$resources = $this->getDigitalProductResources($product);
if ($resources) {
$output['resources'][$id] = [
'resources' => $resources,
'product' => $product->toArray(),
];
}

// Get the files attached to this product
$files = $this->getDigitalProductFiles($product);
if ($files) {
$output['files'][$id] = [
'files' => $files,
'product' => $product->toArray(),
];
}
// Get the digital items
$resources = $this->getDigitalProductResources($product, $digitalProduct);
$files = $this->getDigitalProductFiles($product, $digitalProduct);
$all = array_merge($resources, $files);

// Add the files/resources
if ($resource || $files) {
$digitalProductFile = $this->adapter->newObject('DigitalproductFile', [
'digitalproduct_id' => $digitalProduct->get('id'),
'resource' => $resources ? serialize($resources) : '',
'file' => $files ? serialize($files) : '',
'download_expiry' => $this->getDownloadExpiry($product),
'secret' => $this->generateSecret()
]);
$digitalProductFile->save();

if (!empty($digitalProductFile->get('file'))) {
$output['resources'][$id]['data'] = $digitalProductFile->toArray();
}
if (!empty($digitalProductFile->get('resource'))) {
$output['files'][$id]['data'] = $digitalProductFile->toArray();
}

// Also make these accessible in the all array in twig
$output['all'][$id] = array_merge($resources, $files);
}
// In twig, you can see which by checking for an empty array.
$output[] = [
'resources' => $resources,
'files' => $files,
'all' => $all,
'product' => $product->toArray()
];

// Joins the user to the product's usergroup if they are logged in
if ($user && $product->getProperty('usergroup')) {
$user->joinGroup($product->getProperty('usergroup'));
$user->joinGroup(intval($product->getProperty('usergroup')));
}
}

Expand All @@ -148,19 +121,32 @@ public function processDigitalProducts($order)
* Gets resources attached to the product.
*
* @param comProduct $product
* @param Digitalproduct $digitalProduct object
* @return array
*/
public function getDigitalProductResources($product) {
public function getDigitalProductResources($product, $digitalProduct) {
$output = [];
$resources = $product->getProperty('resources');

foreach ((array)$resources as $resource) {
if ($resource) {
$page = $this->adapter->getObject('modResource', $resource);

if ($page) {
$output[] = $page->toArray();
if (!$page) {
continue;
}

$digitalProductFile = $this->adapter->newObject('DigitalproductFile', [
'digitalproduct_id' => $digitalProduct->get('id'),
'name' => $page->get('pagetitle'), //@todo, make custom setting. Maybe let it be set by TV?
'resource' => $page->get('id'),
'download_expiry' => $this->getDownloadExpiry($product),
'download_limit' => $this->getDownloadLimit($product),
'secret' => $this->generateSecret()
]);
$digitalProductFile->save();

$output[] = $digitalProductFile->toArray();
}
}

Expand All @@ -173,7 +159,7 @@ public function getDigitalProductResources($product) {
* @param comProduct $product
* @return array
*/
public function getDigitalProductFiles($product) {
public function getDigitalProductFiles($product, $digitalProduct) {
$output = [];
$files = $product->getProperty('files');

Expand All @@ -183,27 +169,46 @@ public function getDigitalProductFiles($product) {
'display_name' => $file['display_name'],
'url' => $file['url']
];

$digitalProductFile = $this->adapter->newObject('DigitalproductFile', [
'digitalproduct_id' => $digitalProduct->get('id'),
'name' => $file['display_name'],
'file' => $file['url'],
'download_expiry' => $this->getDownloadExpiry($product),
'download_limit' => $this->getDownloadLimit($product),
'secret' => $this->generateSecret()
]);
$digitalProductFile->save();

$output[] = $digitalProductFile->toArray();
}
}

return $output;
}

/**
* Computes the expiration of the download
* Computes the expiration of a product
*
* @param [type] $product
* @return void
* @param comProduct $product
* @return int
*/
public function getDownloadExpiry($product)
{
$expiration = $product->getProperty('download_expiry');
return $expiration ? strtotime($expiration) : 0;
}

if (!$expiration) {
return 0;
}

return strtotime($expiration);
/**
* Gets the download limit of a product
*
* @param comProduct $product
* @return int
*/
public function getDownloadLimit($product)
{
$limit = $product->getProperty('download_limit');
return $limit ? $limit : 0;
}

/**
Expand Down

0 comments on commit bb8bcb3

Please sign in to comment.