Skip to content

Commit

Permalink
Resolves #1. Move custom product fields to shipment, fix 0 limit, use…
Browse files Browse the repository at this point in the history
… new empty SelectField option
  • Loading branch information
tonyklapatch committed Dec 20, 2018
1 parent 383e3eb commit bf1d5d6
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 45 deletions.
2 changes: 1 addition & 1 deletion _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function getChunkContent($filename)
/* define version */
define('PKG_NAME', 'Commerce_DigitalProduct');
define('PKG_NAMESPACE', 'commerce_digitalproduct');
define('PKG_VERSION', '1.0.0');
define('PKG_VERSION', '1.1.0');
define('PKG_RELEASE', 'pl');

/* load modx */
Expand Down
8 changes: 8 additions & 0 deletions core/components/commerce_digitalproduct/docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
Digitalproduct for Commerce

1.1.0-pl Released on 12/19/2018
==============
- Move custom product fields to shipment (can use your own custom product)
- Add getUserFiles method on service class for future snippet
- Fix 0 download limit not giving unlimited downloads
- Use new empty option for user group SelectField (requires Commerce 0.11.4 or higher)
- Fix download method lexican

1.0.0-pl Released on 7/30/2018
==============
- First public release
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
$_lang['commerce_digitalproduct.dl_limit_desc'] = 'Maximum amount of times the user can download the files / resources attached to this product.';
$_lang['commerce_digitalproduct.dl_expiry'] = 'Expiration Time';
$_lang['commerce_digitalproduct.dl_expiry_desc'] = 'Time the user has to download the files / resources attached to this product.';
$_lang['commerce_digitalproduct.dl_method'] = 'Download Method';
$_lang['commerce_digitalproduct.dl_method_desc'] = 'Download method used for the file.';
$_lang['commerce_digitalproduct.dl_expiry_format'] = 'Invalid time format.';
$_lang['commerce_digitalproduct.user_group'] = 'User Group';
$_lang['commerce_digitalproduct.user_group_desc'] = 'The user group to grant customers access to when they\'ve bought this product.';
$_lang['commerce_digitalproduct.user_group_none'] = 'None';

// Product fields
$_lang['commerce_digitalproduct.resources'] = 'Resources';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getDigitalProduct()
* @param boolean checks the expiration date on the file
* @return boolean
*/
public function hasPermission($checkUser = true, $checkCount = true, $checkExpiry = true)
public function hasPermission($checkUser = false, $checkCount = true, $checkExpiry = true)
{
$product = $this->getDigitalProduct();
$currentUser = $this->adapter->getUser() ? $this->adapter->getUser()->get('id') : 0;
Expand All @@ -46,7 +46,7 @@ public function hasPermission($checkUser = true, $checkCount = true, $checkExpir
}

// Check the download count
if ($checkCount && $this->get('download_count') >= $this->get('download_limit')) {
if ($checkCount && $this->get('download_count') >= $this->get('download_limit') && $this->get('download_limit') !== 0) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

use modmore\Commerce\Admin\Widgets\Form\NumberField;
use modmore\Commerce\Admin\Widgets\Form\SelectField;
use modmore\Commerce\Admin\Widgets\Form\Tab;
use RogueClarity\Digitalproduct\Admin\Widgets\Form\ResourceField;
use RogueClarity\Digitalproduct\Admin\Widgets\Form\FileLinksField;

/**
* Digitalproduct for Commerce.
Expand Down Expand Up @@ -45,27 +49,33 @@ public static function getFieldsForProduct(Commerce $commerce, comProduct $produ
'value' => $product->getProperty('download_method')
]);

// We're not using SelectField's modUserGroup options class because we also want a none selector
$modUserGroups = $commerce->adapter->getCollection('modUserGroup');
$userGroups[] = [
'label' => $commerce->adapter->lexicon('commerce_digitalproduct.user_group_none'),
'value' => ''
];
foreach ($modUserGroups as $modUserGroup) {
$userGroups[] = [
'label' => $modUserGroup->get('name'),
'value' => $modUserGroup->get('id')
];
}

$fields[] = new SelectField($commerce, [
'label' => $commerce->adapter->lexicon('commerce_digitalproduct.user_group'),
'name' => 'properties[usergroup]',
'description' => $commerce->adapter->lexicon('commerce_digitalproduct.user_group_desc'),
'options' => $userGroups,
'optionsClass' => 'modUserGroup',
'emptyOption' => true,
'value' => $product->getProperty('usergroup')
]);

$fields[] = new Tab($commerce, [
'label' => $commerce->adapter->lexicon('commerce_digitalproduct.product_tab')
]);

$fields[] = new ResourceField($commerce, [
'label' => $commerce->adapter->lexicon('commerce_digitalproduct.resources'),
'name' => 'properties[resources]',
'description' => $commerce->adapter->lexicon('commerce_digitalproduct.resources_desc'),
'value' => $product->getProperty('resources')
]);

$fields[] = new FileLinksField($commerce, [
'label' => $commerce->adapter->lexicon('commerce_digitalproduct.files'),
'name' => 'properties[files]',
'description' => $commerce->adapter->lexicon('commerce_digitalproduct.files_desc'),
'value' => $product->getProperty('files')
]);

return $fields;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php

use modmore\Commerce\Admin\Widgets\Form\TextField;
use modmore\Commerce\Admin\Widgets\Form\Tab;
use RogueClarity\Digitalproduct\Admin\Widgets\Form\ResourceField;
use RogueClarity\Digitalproduct\Admin\Widgets\Form\FileLinksField;

/**
* Digitalproduct for Commerce.
Expand All @@ -27,24 +26,6 @@ public function getModelFields()
}
}

$fields[] = new Tab($this->commerce, [
'label' => $this->adapter->lexicon('commerce_digitalproduct.product_tab')
]);

$fields[] = new ResourceField($this->commerce, [
'label' => $this->adapter->lexicon('commerce_digitalproduct.resources'),
'name' => 'properties[resources]',
'description' => $this->adapter->lexicon('commerce_digitalproduct.resources_desc'),
'value' => $this->getProperty('resources')
]);

$fields[] = new FileLinksField($this->commerce, [
'label' => $this->adapter->lexicon('commerce_digitalproduct.files'),
'name' => 'properties[files]',
'description' => $this->adapter->lexicon('commerce_digitalproduct.files_desc'),
'value' => $this->getProperty('files')
]);

return $fields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,21 @@ public function getFile($secret)
'secret' => $secret
]);
}

/**
* Gets a user's files based on user id
*
* @param [type] $userId
* @return void
*/
public function getUserFiles($userId)
{
$files = $this->modx->newQuery('DigitalproductFile');
$files->innerJoin('Digitalproduct');
$files->where([
'Digitalproduct.user' => $userId
]);

return $this->modx->getCollection('DigitalproductFile', $files);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ public function getDigitalProducts(Checkout $event)
}

$order = $event->getOrder();
if ($order->getState() !== \comOrder::STATE_CART) {
return;
}

$digitalProducts = $this->processDigitalProducts($order);

$step->setPlaceholder('digitalProducts', $digitalProducts);
Expand All @@ -80,12 +76,14 @@ public function processDigitalProducts($order)
$user = $this->adapter->getUser();

foreach ($orderItems as $orderItem) {
$product = $orderItem->getProduct();
// This could support class variations in the future?
if ($product->get('class_key') !== 'DigitalproductProduct') {
// Determine if item is a digital product
$deliveryType = $orderItem->getOne('DeliveryType');
if ($deliveryType->get('shipment_type') !== 'DigitalproductOrderShipment') {
continue;
}

$product = $orderItem->getProduct();

// Add the product to the digitalproduct table for tracking
$digitalProduct = $this->adapter->newObject('Digitalproduct', [
'order' => $order->get('id'),
Expand Down

0 comments on commit bf1d5d6

Please sign in to comment.