Skip to content

Commit

Permalink
Fix #16
Browse files Browse the repository at this point in the history
  • Loading branch information
andris-sevcenko committed Oct 10, 2018
1 parent 44c38f7 commit 2798071
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Changelog
- Fixed a bug where product element slugs would not work. ([#9](https://github.com/craftcms/commerce-digital-products/issues/9))
- Fixed a bug where querying for licenses would not work in some cases. ([#11](https://github.com/craftcms/commerce-digital-products/issues/11))
- Fixed a bug where it was impossible to delete a product. ([#12](https://github.com/craftcms/commerce-digital-products/issues/12))
- Fixed a bug where template path and product type URI format generator would not work correctly. ([#16](https://github.com/craftcms/commerce-digital-products/issues/16))

### Added
- Added `craft\digitalproducts\models\ProductTypeSite::getSite()`
Expand Down
18 changes: 12 additions & 6 deletions src/controllers/ProductTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,22 @@ public function actionEdit(int $productTypeId = null, ProductType $productType =
'productType' => $productType,
];

$variables['brandNewProductType'] = false;

if (empty($variables['productType'])) {
$productType = $productTypeId ? DigitalProducts::getInstance()->getProductTypes()->getProductTypeById($productTypeId) : new ProductType();
if (!empty($variables['productTypeId'])) {
$productTypeId = $variables['productTypeId'];
$variables['productType'] = DigitalProducts::getInstance()->getProductTypes()->getProductTypeById($productTypeId);

if (!$productType) {
throw new Exception('Product type not found.');
if (!$variables['productType']) {
throw new HttpException(404);
}
} else {
$variables['productType'] = new ProductType();
$variables['brandNewProductType'] = true;
}

$variables['productType'] = $productType;
}

$variables['title'] = $variables['productType']->id ? $variables['productType']->name : Craft::t('digital-products', 'Create a new digital product type');

return $this->renderTemplate('digital-products/producttypes/_edit', $variables);
Expand Down
19 changes: 10 additions & 9 deletions src/templates/producttypes/_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@

{% endblock %}

{% includejs %}
{% if not productType.handle %}new Craft.HandleGenerator('#name', '#handle');{% endif %}

{% for site in craft.app.sites.getAllSites() %}
new Craft.UriFormatGenerator('#name', '#sites tr[data-id="{{ site.handle }}"] textarea[name$="[uriFormat]"]', { suffix: '/{slug}' });
new Craft.UriFormatGenerator('#name', '#sites tr[data-id="{{ site.handle }}"] textarea[name$="[template]"]', { suffix: '/_product' });
{% endfor %}

{% endincludejs %}
{% if brandNewProductType %}
{% js %}
new Craft.HandleGenerator('#name', '#handle');

{% for site in craft.app.sites.getAllSites() %}
new Craft.UriFormatGenerator('#name', '#sites tr[data-id="{{ site.handle }}"] textarea[name$="[uriFormat]"]', { suffix: '/{slug}' });
new Craft.UriFormatGenerator('#name', '#sites tr[data-id="{{ site.handle }}"] textarea[name$="[template]"]', { suffix: '/_product' });
{% endfor %}
{% endjs %}
{% endif %}

0 comments on commit 2798071

Please sign in to comment.