existing skus working now too
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Cake\Log\Log;
|
||||
use function BenTools\CartesianProduct\combinations;
|
||||
|
||||
/**
|
||||
* @var \App\View\AppView $this
|
||||
* @var \App\Model\Entity\ProductSku $productSku
|
||||
* @var \Cake\Collection\CollectionInterface|string[] $products
|
||||
* @var array $optionMapping
|
||||
* @var array $variantNameMapping
|
||||
* @var \App\Model\Entity\ProductSku[] $productSkus
|
||||
* @var \App\Model\Entity\ProductSku $product
|
||||
* @var array $toGetCartesianProductsFrom
|
||||
*/
|
||||
|
||||
@@ -17,6 +16,11 @@ use function BenTools\CartesianProduct\combinations;
|
||||
<aside class="column">
|
||||
<div class="side-nav">
|
||||
<h4 class="heading"><?= __('Actions') ?></h4>
|
||||
<?= $this->Html->link(__('View Product'), [
|
||||
'controller' => 'Products',
|
||||
'action' => 'view',
|
||||
$product->id,
|
||||
], ['class' => 'side-nav-item']) ?>
|
||||
<?= $this->Html->link(__('List Product SKUs'), ['action' => 'index'], ['class' => 'side-nav-item']) ?>
|
||||
</div>
|
||||
</aside>
|
||||
@@ -24,12 +28,11 @@ use function BenTools\CartesianProduct\combinations;
|
||||
<div class="productSkus form content">
|
||||
<?= $this->Form->create($productSkus) ?>
|
||||
<fieldset>
|
||||
<legend><?= __('Add Product Skus') ?></legend>
|
||||
<legend><?= __('Add Product SKU(s) for Product: ' . $product->name) ?></legend>
|
||||
<div id="product-skus-container" class="container">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Add?</th>
|
||||
<th>SKU</th>
|
||||
<th>Barcode</th>
|
||||
<th>Price</th>
|
||||
@@ -45,28 +48,83 @@ use function BenTools\CartesianProduct\combinations;
|
||||
<?php
|
||||
$cnt = 0;
|
||||
$labelFalse = ['label' => false];
|
||||
$found = [];
|
||||
foreach (combinations($toGetCartesianProductsFrom) as $c => $combination) : ?>
|
||||
|
||||
<?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']);
|
||||
// }
|
||||
?>
|
||||
<tr>
|
||||
<td><?= $this->Form->control($cnt . '.add', ['label' => false, 'type' => 'checkbox', 'checked' => true]); ?></td>
|
||||
<td><?= $this->Form->control($cnt . '.sku', $labelFalse); ?></td>
|
||||
<td>
|
||||
<?= $this->Form->hidden($cnt . '.id', ['value' => $foundSku]); ?>
|
||||
<?= $this->Form->control($cnt . '.sku', $skuInputOptions); ?>
|
||||
|
||||
</td>
|
||||
<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;
|
||||
foreach ($variantNameMapping as $singleVariantId => $singleVariantName) : ?>
|
||||
<td>
|
||||
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_category_variant_id', ['value' => $singleVariantId ?? null]); ?>
|
||||
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_category_variant_option_id', ['value' => $combination[$singleVariantId] ?? null]); ?>
|
||||
<?= $optionMapping[$combination[$singleVariantId]]; ?>
|
||||
</td>
|
||||
<?php
|
||||
$variantCnt++;
|
||||
endforeach; ?>
|
||||
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]); ?>
|
||||
<?= $this->Form->hidden($cnt . '.product_sku_variant_values.' . $variantCnt . '.product_category_variant_id', ['value' => $existingVariantValueRecord->product_category_variant_id ?? null]); ?>
|
||||
<?= $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; ?>
|
||||
</tr>
|
||||
<?php
|
||||
$cnt++;
|
||||
endforeach; ?>
|
||||
|
||||
endforeach;
|
||||
|
||||
// dd($found);
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* @var \App\View\AppView $this
|
||||
* @var \Cake\Datasource\EntityInterface $productSku
|
||||
* @var \App\Model\Entity\ProductSkus $productSku
|
||||
*/
|
||||
?>
|
||||
<div class="row">
|
||||
@@ -52,22 +52,22 @@
|
||||
</tr>
|
||||
</table>
|
||||
<div class="related">
|
||||
<h4><?= __('Product Attributes') ?></h4>
|
||||
<h4><?= __('SKU Variant Attributes') ?></h4>
|
||||
<?php if (!empty($productSku->product_sku_variant_values)) : ?>
|
||||
<div class="table-responsive">
|
||||
<table>
|
||||
<?php foreach ($productSku->product_sku_variant_values as $variantValue) : ?>
|
||||
<?php
|
||||
if (!$variantValue->hasValue('product_category_variant')) {
|
||||
if (!isset($variantValue->product_variant->product_category_variant)) {
|
||||
continue;
|
||||
}
|
||||
if (!$variantValue->hasValue('product_category_variant_option')) {
|
||||
if (!isset($variantValue->product_category_variant_option)) {
|
||||
continue;
|
||||
}
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<th><?= h($variantValue->product_category_variant->name) ?></th>
|
||||
<th><?= h($variantValue->product_variant->product_category_variant->name) ?></th>
|
||||
<td><?= h($variantValue->product_category_variant_option->variant_label ?? $variantValue->product_category_variant_option->variant_value) ?></td>
|
||||
</tr>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user