product attributes add/edit
This commit is contained in:
parent
25cb12d810
commit
4549f30930
|
@ -78,10 +78,52 @@ class ProductsController extends AppController
|
||||||
$saveOptions = [
|
$saveOptions = [
|
||||||
'associated' => ['ProductAttributes'],
|
'associated' => ['ProductAttributes'],
|
||||||
];
|
];
|
||||||
// Log::debug(print_r('$postData', true));
|
Log::debug(print_r('$postData', 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));
|
||||||
// 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);
|
$product = $productsTable->patchEntity($product, $postData, $saveOptions);
|
||||||
if ($productsTable->save($product, $saveOptions)) {
|
if ($productsTable->save($product, $saveOptions)) {
|
||||||
$this->Flash->success(__('The product has been saved.'));
|
$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;
|
$productCategory = $product->product_category_id ? $productsTable->ProductCategories->find()->where(['internal_id' => $product->product_category_id])->first() : null;
|
||||||
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
$productCatalogs = $productsTable->ProductCategories->ProductCatalogs->find('list')->toArray();
|
||||||
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
$this->set(compact('product', 'productCatalogs', 'productCategory'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue