2025-04-15 09:39:35 +00:00
|
|
|
<?php
|
2025-09-05 09:51:43 +00:00
|
|
|
|
2025-10-03 10:04:57 +00:00
|
|
|
use Cake\Log\Log;
|
2025-09-05 09:51:43 +00:00
|
|
|
use function BenTools\CartesianProduct\combinations;
|
|
|
|
|
2025-04-15 09:39:35 +00:00
|
|
|
/**
|
|
|
|
* @var \App\View\AppView $this
|
2025-10-03 10:04:57 +00:00
|
|
|
* @var \App\Model\Entity\ProductSku[] $productSkus
|
|
|
|
* @var \App\Model\Entity\ProductSku $product
|
2025-09-11 05:06:12 +00:00
|
|
|
* @var array $toGetCartesianProductsFrom
|
2025-04-15 09:39:35 +00:00
|
|
|
*/
|
2025-09-05 09:51:43 +00:00
|
|
|
|
|
|
|
|
2025-04-15 09:39:35 +00:00
|
|
|
?>
|
|
|
|
<div class="row">
|
|
|
|
<aside class="column">
|
|
|
|
<div class="side-nav">
|
|
|
|
<h4 class="heading"><?= __('Actions') ?></h4>
|
2025-10-03 10:04:57 +00:00
|
|
|
<?= $this->Html->link(__('View Product'), [
|
|
|
|
'controller' => 'Products',
|
|
|
|
'action' => 'view',
|
|
|
|
$product->id,
|
|
|
|
], ['class' => 'side-nav-item']) ?>
|
2025-09-05 09:51:43 +00:00
|
|
|
<?= $this->Html->link(__('List Product SKUs'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
|
2025-04-15 09:39:35 +00:00
|
|
|
</div>
|
|
|
|
</aside>
|
|
|
|
<div class="column column-80">
|
|
|
|
<div class="productSkus form content">
|
2025-09-05 09:51:43 +00:00
|
|
|
<?= $this->Form->create($productSkus) ?>
|
2025-04-15 09:39:35 +00:00
|
|
|
<fieldset>
|
2025-10-03 10:04:57 +00:00
|
|
|
<legend><?= __('Add Product SKU(s) for Product: ' . $product->name) ?></legend>
|
2025-09-05 09:51:43 +00:00
|
|
|
<div id="product-skus-container" class="container">
|
|
|
|
<table class="table">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>SKU</th>
|
|
|
|
<th>Barcode</th>
|
|
|
|
<th>Price</th>
|
|
|
|
<th>Cost</th>
|
|
|
|
<?php
|
|
|
|
$cnt = 0;
|
|
|
|
foreach ($variantNameMapping as $singleVariantName) : ?>
|
|
|
|
<th><?= $singleVariantName; ?></th>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<?php
|
|
|
|
$cnt = 0;
|
|
|
|
$labelFalse = ['label' => false];
|
2025-10-03 10:04:57 +00:00
|
|
|
$found = [];
|
2025-09-05 09:51:43 +00:00
|
|
|
foreach (combinations($toGetCartesianProductsFrom) as $c => $combination) : ?>
|
2025-10-03 10:04:57 +00:00
|
|
|
|
|
|
|
<?php
|
|
|
|
// $singleVariantId
|
|
|
|
$foundSku = null;
|
|
|
|
// dd($existingSkusForCartesianComparison);
|
|
|
|
|
|
|
|
foreach($existingSkusForCartesianComparison as $existingSkuForCartesianComparisonId => $existingSkuForCartesianComparison) {
|
|
|
|
$allMatch = false;
|
|
|
|
Log::debug(print_r(['$combination' => $combination, '$existingSkuForCartesianComparison' => $existingSkuForCartesianComparison], true));
|
|
|
|
if ($existingSkuForCartesianComparison == $combination) {
|
|
|
|
$foundSku = $existingSkuForCartesianComparisonId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$found[$c] = $foundSku;
|
|
|
|
|
|
|
|
$addInputOptions = [
|
|
|
|
'label' => false,
|
|
|
|
'type' => 'checkbox',
|
|
|
|
'checked' => true,
|
|
|
|
'readonly' => isset($foundSku),
|
|
|
|
];
|
|
|
|
|
|
|
|
$skuInputOptions = [
|
|
|
|
'label' => false,
|
|
|
|
'required' => isset($foundSku),
|
|
|
|
'value' => $foundSku && isset($existingProductSkus[$foundSku]['sku']) ? $existingProductSkus[$foundSku]['sku'] : '',
|
|
|
|
];
|
|
|
|
|
|
|
|
// if ($foundSku) {
|
|
|
|
// dd($existingProductSkus[$foundSku]['sku']);
|
|
|
|
// }
|
|
|
|
?>
|
2025-09-05 09:51:43 +00:00
|
|
|
<tr>
|
2025-10-03 10:04:57 +00:00
|
|
|
<td>
|
|
|
|
<?= $this->Form->hidden($cnt . '.id', ['value' => $foundSku]); ?>
|
|
|
|
<?= $this->Form->control($cnt . '.sku', $skuInputOptions); ?>
|
|
|
|
|
|
|
|
</td>
|
2025-09-06 08:11:51 +00:00
|
|
|
<td><?= $this->Form->control($cnt . '.barcode', $labelFalse); ?></td>
|
|
|
|
<td><?= $this->Form->control($cnt . '.price', $labelFalse); ?></td>
|
|
|
|
<td><?= $this->Form->control($cnt . '.cost', $labelFalse); ?></td>
|
|
|
|
<?php
|
|
|
|
$variantCnt = 0;
|
2025-10-03 10:04:57 +00:00
|
|
|
if (isset($foundSku) && isset($existingProductSkus[$foundSku])) : ?>
|
|
|
|
<?php foreach ($existingProductSkus[$foundSku]['product_sku_variant_values'] as $existingVariantValueRecord) : ?>
|
|
|
|
<td>
|
|
|
|
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.id', ['value' => $existingVariantValueRecord->id]); ?>
|
|
|
|
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_sku_id', ['value' => $foundSku]); ?>
|
2025-10-03 10:09:34 +00:00
|
|
|
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_variant_id', ['value' => $existingVariantValueRecord->product_variant_id ?? null]); ?>
|
2025-10-03 10:04:57 +00:00
|
|
|
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_category_variant_option_id', ['value' => $existingVariantValueRecord->product_category_variant_option_id ?? null]); ?>
|
|
|
|
<?= $optionMapping[$combination[$existingVariantValueRecord->product_variant_id]]; ?>
|
|
|
|
</td>
|
|
|
|
<?php
|
|
|
|
$variantCnt++;
|
|
|
|
endforeach; ?>
|
|
|
|
<?php else : ?>
|
|
|
|
<?php foreach ($variantNameMapping as $singleVariantId => $singleVariantName) : ?>
|
|
|
|
<td>
|
|
|
|
<?= isset($foundSku) ? $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_sku_id', ['value' => $foundSku]) : ''; ?>
|
|
|
|
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_variant_id', ['value' => $productVariantsMapping[$singleVariantId] ?? null]); ?>
|
|
|
|
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_category_variant_option_id', ['value' => $combination[$productVariantsMapping[$singleVariantId]] ?? null]); ?>
|
|
|
|
<?= $optionMapping[$combination[$productVariantsMapping[$singleVariantId]]]; ?>
|
|
|
|
</td>
|
|
|
|
<?php
|
|
|
|
$variantCnt++;
|
|
|
|
endforeach; ?>
|
|
|
|
<?php endif; ?>
|
2025-09-05 09:51:43 +00:00
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
$cnt++;
|
2025-10-03 10:04:57 +00:00
|
|
|
|
|
|
|
endforeach;
|
|
|
|
|
|
|
|
// dd($found);
|
|
|
|
?>
|
2025-09-05 09:51:43 +00:00
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2025-04-15 09:39:35 +00:00
|
|
|
</fieldset>
|
|
|
|
<?= $this->Form->button(__('Submit')) ?>
|
|
|
|
<?= $this->Form->end() ?>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|