Skip to content

Commit

Permalink
Added a config option to disable freshly created variants from admini…
Browse files Browse the repository at this point in the history
…stration panel (#886)

* Added a config option to disable freshly created variants from administration interface

* Replaced ``boolval`` with ``!empty``

This change handles the case in which ``$args['newVariantDisable']``
would be undefined.
  • Loading branch information
QuentindevePro authored Jul 9, 2024
1 parent 998c213 commit 7d61133
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/products.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@
'updateOpenGraph' >= false,
],
],

'newVariantDisable' => false,
];
3 changes: 3 additions & 0 deletions controllers/single_page/dashboard/store/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ public function save()
Config::save('community_store::products.hideSize', !empty($args['hideSize']));
Config::save('community_store::products.hideWeight', !empty($args['hideWeight']));
Config::save('community_store::products.hideBarcode', !empty($args['hideBarcode']));

Config::save('community_store::products.newVariantDisable', !empty($args['newVariantDisable']));

Config::save('community_store.hideVariationPrices', isset($args['hideVariationPrices']) ?? false);
Config::save('community_store.hideVariationShippingFields', isset($args['hideVariationShippingFields']) ?? false);
Config::save('community_store.hideSalePrice', isset($args['hideSalePrice']) ?? false);
Expand Down
8 changes: 7 additions & 1 deletion single_pages/dashboard/store/products.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
defined('C5_EXECUTE') or die("Access Denied.");

use Concrete\Controller\Element\Attribute\Form;
use Concrete\Core\Page\Page;
use Concrete\Core\Support\Facade\Config;
use Concrete\Core\Support\Facade\Url;
use Concrete\Package\CommunityStore\Src\CommunityStore\Product\Product;
use Concrete\Package\CommunityStore\Src\CommunityStore\Product\ProductVariation\ProductVariation;
use Concrete\Package\CommunityStore\Src\CommunityStore\Utilities\AutoUpdaterQuantitiesFromVariations;
use Concrete\Core\Support\Facade\Log;

/**
* @var Concrete\Core\Application\Service\FileManager $al
Expand Down Expand Up @@ -1550,7 +1552,11 @@ function addOptionItem(group) {

<div class="form-group pull-right mt-2">
<?= $form->label('pvDisabled[' . $varid . ']', t('Disabled')); ?>
<?= $form->checkbox('pvDisabled[' . $varid . ']', 1, $variation ? $variation->getVariationDisabled() : false, ['data-combokey'=>$comboKey, 'class'=>'optionDisabled']) ?>
<?php
$newVariantDisable = Config::get("community_store::products.newVariantDisable");
Log::addInfo('newVariantDisable: ' . $newVariantDisable);
?>
<?= $form->checkbox('pvDisabled[' . $varid . ']', 1, $variation ? $variation->getVariationDisabled() : $newVariantDisable, ['data-combokey'=>$comboKey, 'class'=>'optionDisabled']) ?>
</div>

</div>
Expand Down
12 changes: 12 additions & 0 deletions single_pages/dashboard/store/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,18 @@ class="dialog-launch"
<div class="small text-muted"><?= $automaticProductQuantitiesMessage ?></div>
</div>

<div class="form-group">
<label><?= t('Disable new variants by default') ?></label>
<div class="checkbox form-check">
<?php
$newVariantDisable = Config::get("community_store::products.newVariantDisable") ? '1' : '0';
?>
<div class="radio"><label><?= $form->radio('newVariantDisable', '1', $newVariantDisable) ?><?= t('Yes, disable new variants at their creation') ?></label></div>
<div class="radio"><label><?= $form->radio('newVariantDisable', '0', $newVariantDisable) ?><?= t('No, do not disable new variants when they are created') ?></label></div>
</div>
<div class="small text-muted"><?= t("Disabling new variants when they are created can be relevant if not all combinations of options are not meant to be available") ?></div>
</div>

</div>

<!-- #settings-product-images -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public static function addVariations(array $data, Product $product)
'pvHeight' => '',
'pvLength' => '',
'pvSort' => $sort,
'pvDisabled' => 0,
'pvDisabled' => Config::get('community_store::products.newVariantDisable'),
true, ]
);

Expand Down Expand Up @@ -669,6 +669,7 @@ public static function add($product, $data, $persistonly = false)
$variation->setVariationWidth($data['pvWeight']);
$variation->setVariationPackageData(isset($data['pvPackageData']) ? $data['pvPackageData'] : '');
$variation->setVariationSort($data['pvSort']);
$variation->setVariationDisabled(isset($data['pvDisabled']) ? $data['pvDisabled'] : Config::get('community_store::products.newVariantDisable'));
$product->getVariations()->add($variation);
$variation->save($persistonly);

Expand Down

0 comments on commit 7d61133

Please sign in to comment.