Created
July 5, 2021 08:07
-
-
Save ichaykin/40823b94ef5554969da9f643464fe7e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/product_variations/controllers/backend/product_variations.php b/app/addons/product_variations/controllers/backend/product_variations.php | |
index e8edf4830d..20f165a6c4 100644 | |
--- a/app/addons/product_variations/controllers/backend/product_variations.php | |
+++ b/app/addons/product_variations/controllers/backend/product_variations.php | |
@@ -197,7 +197,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
$request = new GenerateProductsAndAttachToGroupRequest( | |
$group_id, | |
$product_id, | |
- $generation_form->getCombinationsData() | |
+ $generation_form->getCombinationsData(), | |
+ $_REQUEST | |
); | |
$request->setFeaturesVariantsMap($generation_form->getFeaturesVariantsMap()); | |
$result = $service->generateProductsAndAttachToGroup($request); | |
@@ -205,7 +206,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { | |
$request = new GenerateProductsAndCreateGroupRequest( | |
$product_id, | |
$generation_form->getCombinationsData(), | |
- $generation_form->getFeatureCollection() | |
+ $generation_form->getFeatureCollection(), | |
+ $_REQUEST | |
); | |
$request->setFeaturesVariantsMap($generation_form->getFeaturesVariantsMap()); | |
$result = $service->generateProductsAndCreateGroup($request); | |
@@ -359,11 +361,14 @@ if ($mode === 'manage') { | |
/** @var \Tygh\SmartyEngine\Core $view */ | |
$view = Tygh::$app['view']; | |
+ | |
+ list($combinations, $combinations_count) = $generation_form->getCombinations(); | |
+ | |
$view->assign([ | |
'product_data' => $product_data, | |
'feature_value_collection' => $generation_form->getFeatureValueCollection(), | |
'group' => $generation_form->getGroup(), | |
- 'combinations' => $generation_form->getCombinations(), | |
+ 'combinations' => $combinations, | |
'selected_features' => $generation_form->getFeatures(), | |
'new_combinations_count' => $generation_form->getNewCombinationsCount(), | |
'feature_ids' => array_keys($generation_form->getFeatures()), | |
@@ -371,6 +376,15 @@ if ($mode === 'manage') { | |
'exists_features_variant_ids' => $generation_form->getExistsFeaturesVariantsMap(), | |
'is_allow_generate_variations' => $product_type->isAllowGenerateVariations(), | |
'is_all_combinations_active' => $generation_form->isAllCombinationsActive(), | |
+ 'combination_search' => [ | |
+ 'page' => !empty($_REQUEST['page']) | |
+ ? $_REQUEST['page'] | |
+ : 1, | |
+ 'items_per_page' => !empty($_REQUEST['items_per_page']) | |
+ ? $_REQUEST['items_per_page'] | |
+ : Registry::get('settings.Appearance.admin_elements_per_page'), | |
+ 'total_items' => $combinations_count, | |
+ ], | |
]); | |
} elseif ($mode === 'find_variations') { | |
$product_id = isset($_REQUEST['product_id']) ? (int) $_REQUEST['product_id'] : 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/product_variations/src/Form/GenerateVariationsForm.php b/app/addons/product_variations/src/Form/GenerateVariationsForm.php | |
index 40ed4bd4a5..866566d538 100644 | |
--- a/app/addons/product_variations/src/Form/GenerateVariationsForm.php | |
+++ b/app/addons/product_variations/src/Form/GenerateVariationsForm.php | |
@@ -23,6 +23,7 @@ use Tygh\Addons\ProductVariations\Product\Group\Repository as GroupRepository; | |
use Tygh\Addons\ProductVariations\Product\Repository as ProductRepository; | |
use Tygh\Addons\ProductVariations\Service; | |
use Tygh\Addons\ProductVariations\ServiceProvider; | |
+use Tygh\Registry; | |
class GenerateVariationsForm | |
{ | |
@@ -204,21 +205,55 @@ class GenerateVariationsForm | |
public function getCombinations() | |
{ | |
if ($this->combinations !== null) { | |
- return $this->combinations; | |
+ return [$this->combinations, $this->combinations_count]; | |
} | |
$this->combinations_generator->setDefaulIsActive(!empty($this->get('features_variants_ids'))); | |
- return $this->combinations = $this->combinations_generator->generateByFeatureVariant( | |
+ $combinations = $this->combinations_generator->generateByFeatureVariant( | |
$this->getFeatureValueCollection(), | |
$this->getProductIds(), | |
$this->getCombinationsData() | |
); | |
+ | |
+ $page = !empty($this->request['page']) | |
+ ? $this->request['page'] | |
+ : 1; | |
+ | |
+ $items_per_page = !empty($this->request['items_per_page']) | |
+ ? $this->request['items_per_page'] | |
+ : Registry::get('settings.Appearance.admin_elements_per_page'); | |
+ | |
+ $this->combinations = array_slice( | |
+ $combinations, | |
+ ($page - 1) * $items_per_page, | |
+ $items_per_page | |
+ ); | |
+ | |
+ $this->combinations_count = count($combinations); | |
+ | |
+ return [$this->combinations, $this->combinations_count]; | |
+ } | |
+ | |
+ public function getCombinationsCount() | |
+ { | |
+ $this->combinations_generator->setDefaulIsActive(!empty($this->get('features_variants_ids'))); | |
+ | |
+ $combinations = $this->combinations_generator->generateByFeatureVariant( | |
+ $this->getFeatureValueCollection(), | |
+ $this->getProductIds(), | |
+ $this->getCombinationsData() | |
+ ); | |
+ | |
+ | |
+ return count($combinations); | |
+ | |
} | |
public function getNewCombinationsCount() | |
{ | |
- return array_reduce($this->getCombinations(), function ($carry, $combination) { | |
+ list($combinations,) = $this->getCombinations(); | |
+ return array_reduce($combinations, function ($carry, $combination) { | |
if ($combination['active'] && !$combination['linked']) { | |
$carry++; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/product_variations/src/Request/GenerateProductsAndAttachToGroupRequest.php b/app/addons/product_variations/src/Request/GenerateProductsAndAttachToGroupRequest.php | |
index 87d36425bc..ceb3681045 100644 | |
--- a/app/addons/product_variations/src/Request/GenerateProductsAndAttachToGroupRequest.php | |
+++ b/app/addons/product_variations/src/Request/GenerateProductsAndAttachToGroupRequest.php | |
@@ -15,12 +15,15 @@ | |
namespace Tygh\Addons\ProductVariations\Request; | |
+use Tygh\Registry; | |
+ | |
class GenerateProductsAndAttachToGroupRequest extends ABaseGenerateProductsRequest | |
{ | |
/** | |
* @var int | |
*/ | |
protected $group_id = 0; | |
+ public $request = []; | |
/** | |
* GenerateProductsAndAttachToVariationGroupCommand constructor. | |
@@ -30,9 +33,10 @@ class GenerateProductsAndAttachToGroupRequest extends ABaseGenerateProductsReque | |
* @param string[] $combination_ids | |
* @param array $combinations_data | |
*/ | |
- public function __construct($group_id, $base_product_id, array $combinations_data) | |
+ public function __construct($group_id, $base_product_id, array $combinations_data, $request = []) | |
{ | |
$this->group_id = (int) $group_id; | |
+ $this->request = $request; | |
parent::__construct($base_product_id, $combinations_data); | |
} | |
@@ -52,4 +56,18 @@ class GenerateProductsAndAttachToGroupRequest extends ABaseGenerateProductsReque | |
return $self; | |
} | |
+ | |
+ public function getPage() | |
+ { | |
+ return !empty($this->request['page']) | |
+ ? $this->request['page'] | |
+ : 1; | |
+ } | |
+ | |
+ public function getItemsPerPage() | |
+ { | |
+ return !empty($this->request['items_per_page']) | |
+ ? $this->request['items_per_page'] | |
+ : Registry::get('settings.Appearance.admin_elements_per_page'); | |
+ } | |
} | |
\ No newline at end of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/product_variations/src/Request/GenerateProductsAndCreateGroupRequest.php b/app/addons/product_variations/src/Request/GenerateProductsAndCreateGroupRequest.php | |
index 50ff0a3d5b..4df4326c93 100644 | |
--- a/app/addons/product_variations/src/Request/GenerateProductsAndCreateGroupRequest.php | |
+++ b/app/addons/product_variations/src/Request/GenerateProductsAndCreateGroupRequest.php | |
@@ -16,6 +16,7 @@ | |
namespace Tygh\Addons\ProductVariations\Request; | |
use Tygh\Addons\ProductVariations\Product\Group\GroupFeatureCollection; | |
+use Tygh\Registry; | |
class GenerateProductsAndCreateGroupRequest extends ABaseGenerateProductsRequest | |
{ | |
@@ -23,6 +24,7 @@ class GenerateProductsAndCreateGroupRequest extends ABaseGenerateProductsRequest | |
* @var null|\Tygh\Addons\ProductVariations\Product\Group\GroupFeatureCollection | |
*/ | |
protected $group_features = null; | |
+ public $request = []; | |
/** | |
* GenerateProductsAndCreateVariationGroupCommand constructor. | |
@@ -35,9 +37,11 @@ class GenerateProductsAndCreateGroupRequest extends ABaseGenerateProductsRequest | |
public function __construct( | |
$base_product_id, | |
array $combinations_data, | |
- GroupFeatureCollection $group_features = null | |
+ GroupFeatureCollection $group_features = null, | |
+ $request = [] | |
) { | |
$this->group_features = $group_features; | |
+ $this->request = $request; | |
parent::__construct($base_product_id, $combinations_data); | |
} | |
@@ -57,4 +61,18 @@ class GenerateProductsAndCreateGroupRequest extends ABaseGenerateProductsRequest | |
return $self; | |
} | |
+ | |
+ public function getPage() | |
+ { | |
+ return !empty($this->request['page']) | |
+ ? $this->request['page'] | |
+ : 1; | |
+ } | |
+ | |
+ public function getItemsPerPage() | |
+ { | |
+ return !empty($this->request['items_per_page']) | |
+ ? $this->request['items_per_page'] | |
+ : Registry::get('settings.Appearance.admin_elements_per_page'); | |
+ } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/addons/product_variations/src/Service.php b/app/addons/product_variations/src/Service.php | |
index 9577ab4d89..1a6448cd60 100644 | |
--- a/app/addons/product_variations/src/Service.php | |
+++ b/app/addons/product_variations/src/Service.php | |
@@ -1114,6 +1114,16 @@ class Service | |
); | |
} | |
+ $page = $request->getPage(); | |
+ | |
+ $items_per_page = $request->getItemsPerPage(); | |
+ | |
+ $combinations = array_slice( | |
+ $combinations, | |
+ ($page - 1) * $items_per_page, | |
+ $items_per_page | |
+ ); | |
+ | |
foreach ($combinations as $key => $combination) { | |
if (!$combination['active']) { | |
unset($combinations[$key]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/design/backend/templates/addons/product_variations/views/product_variations/components/generate_variations.tpl b/design/backend/templates/addons/product_variations/views/product_variations/components/generate_variations.tpl | |
index 77d4806d43..c551b16ced 100644 | |
--- a/design/backend/templates/addons/product_variations/views/product_variations/components/generate_variations.tpl | |
+++ b/design/backend/templates/addons/product_variations/views/product_variations/components/generate_variations.tpl | |
@@ -99,6 +99,12 @@ | |
<div class="cm-variations-generator__combinations" id="generate_variations__combinations_container"> | |
{if $combinations} | |
+ {include file="common/pagination.tpl" | |
+ div_id="generate_variations__combinations_container_pagination" | |
+ search=$combination_search | |
+ save_current_page=true | |
+ save_current_items_per_page=true | |
+ } | |
<p>{__("product_variations.generator.table.title")}</p> | |
<table width="100%" class="table table-middle table--relative"> | |
<thead> | |
@@ -129,6 +135,13 @@ | |
{/foreach} | |
</tbody> | |
</table> | |
+ | |
+ {include file="common/pagination.tpl" | |
+ div_id="generate_variations__combinations_container_pagination" | |
+ search=$combination_search | |
+ save_current_page=true | |
+ save_current_items_per_page=true | |
+ } | |
{/if} | |
<!--generate_variations__combinations_container--></div> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/design/backend/templates/common/pagination.tpl b/design/backend/templates/common/pagination.tpl | |
index d93054b7d5..da7fed873e 100644 | |
--- a/design/backend/templates/common/pagination.tpl | |
+++ b/design/backend/templates/common/pagination.tpl | |
@@ -16,6 +16,9 @@ | |
{if $save_current_page} | |
<input type="hidden" name="page" value="{$search.page|default:$smarty.request.page|default:1}" /> | |
{/if} | |
+ {if $save_current_items_per_page} | |
+ <input type="hidden" name="items_per_page" value="{$search.items_per_page|default:$smarty.request.items_per_page|default:1}" /> | |
+ {/if} | |
{if $save_current_url} | |
<input type="hidden" name="redirect_url" value="{$config.current_url}" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment