product attributes add/edit
CI / testsuite (mysql, 8.2, ) (push) Failing after 6m11s Details
CI / testsuite (mysql, 8.4, ) (push) Successful in 10m19s Details
CI / testsuite (sqlite, 8.2, prefer-lowest) (push) Failing after 6m10s Details
CI / Coding Standard & Static Analysis (push) Failing after 5m51s Details

This commit is contained in:
Brandon Shipley 2025-09-19 23:44:18 -07:00
parent 25cb12d810
commit 4549f30930
Signed by: bmfs
GPG Key ID: 14E38571D8BB0DE4
1 changed files with 46 additions and 5 deletions

View File

@ -78,10 +78,52 @@ class ProductsController extends AppController
$saveOptions = [
'associated' => ['ProductAttributes'],
];
// Log::debug(print_r('$postData', true));
// Log::debug(print_r($postData, true));
// Log::debug(print_r('$saveOptions', true));
// Log::debug(print_r($saveOptions, true));
Log::debug(print_r('$postData', true));
Log::debug(print_r($postData, true));
Log::debug(print_r('$saveOptions', true));
Log::debug(print_r($saveOptions, true));
$productVariantsData = [];
if (isset($postData['product_variants']) && $postData['product_variants']) {
foreach ($postData['product_variants'] as $postedProductVariant) {
if (!isset($postedProductVariant['enabled']) || !$postedProductVariant['enabled'] || !isset($postedProductVariant['product_category_variant_id'])) {
continue;
}
$existingVariant = $this->Products->ProductCategories->ProductCategoryVariants->get($postedProductVariant['product_category_variant_id'], contain: ['ProductCategoryVariantOptions']);
$optionsData = [];
foreach ($existingVariant->product_category_variant_options as $existingOption) {
$optionsData[] = [
'variant_value' => $existingOption->variant_value,
'variant_label' => $existingOption->variant_label ?? null,
'enabled' => $existingOption->enabled,
];
}
$tmpVariantData = [
'name' => $existingVariant->name,
'product_category_variant_id' => $postedProductVariant['product_category_variant_id'],
'enabled' => true,
'product_category_variant_options' => $optionsData,
];
$productVariantsData[] = $tmpVariantData;
}
}
if ($productVariantsData) {
$saveOptions['fields'] = [
'name',
'product_category_id',
'product_type_id',
'product_attributes',
'product_category_variants'
];
$saveOptions['associated']['ProductCategoryVariants'] = [
'fields' => [
'name',
'enabled',
'product_category_variant_options',
]
];
$saveOptions['associated'][] = 'ProductCategoryVariants.ProductCategoryVariantOptions';
$postData['product_category_variants'] = $productVariantsData;
}
$product = $productsTable->patchEntity($product, $postData, $saveOptions);
if ($productsTable->save($product, $saveOptions)) {
$this->Flash->success(__('The product has been saved.'));
@ -129,7 +171,6 @@ class ProductsController extends AppController
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
$this->set(compact('product', 'productCatalogs', 'productCategory'));
}
/**