variant options coming along - add test passing
CI / testsuite (mysql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 0s
Details
CI / Coding Standard & Static Analysis (push) Failing after 0s
Details
CI / testsuite (mysql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (mysql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (pgsql, 8.4, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, ) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.1, prefer-lowest) (push) Failing after 0s
Details
CI / testsuite (sqlite, 8.4, ) (push) Failing after 0s
Details
CI / Coding Standard & Static Analysis (push) Failing after 0s
Details
This commit is contained in:
parent
5adc791c20
commit
59a38758e9
|
@ -48,14 +48,14 @@ class CreateProductCategoryVariants extends AbstractMigration
|
|||
'name' => 'VARIANTS_BY_PRODUCT_ID',
|
||||
'unique' => false,
|
||||
]);
|
||||
$table->addIndex([
|
||||
'name',
|
||||
'product_category_id',
|
||||
'product_id',
|
||||
], [
|
||||
'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE',
|
||||
'unique' => true,
|
||||
]);
|
||||
// $table->addIndex([
|
||||
// 'name',
|
||||
// 'product_category_id',
|
||||
// 'product_id',
|
||||
// ], [
|
||||
// 'name' => 'VARIANTS_BY_NAME_AND_PRODUCT_CATEGORY_ID_AND_PRODUCT_ID_UNIQUE',
|
||||
// 'unique' => true,
|
||||
// ]);
|
||||
$table->create();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,7 @@ class CreateProductCategoryVariantOptions extends BaseMigration
|
|||
'default' => true,
|
||||
'null' => false,
|
||||
]);
|
||||
|
||||
$table->addForeignKey('product_category_variant_id', 'product_category_variants');
|
||||
// $table->addForeignKey('product_category_variant_id', 'product_category_variants'); // @TODO why cant this be included??? breaks tests on tearDown
|
||||
|
||||
$table->create();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace CakeProducts\Controller;
|
|||
|
||||
use App\Controller\AppController;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Log\Log;
|
||||
use Cake\ORM\Table;
|
||||
use Cake\ORM\TableRegistry;
|
||||
use CheeseCake\Controller\Traits\OverrideTableTrait;
|
||||
|
@ -66,12 +67,23 @@ class ProductCategoryVariantsController extends AppController
|
|||
|
||||
$productCategoryVariant = $productCategoryVariantsTable->newEmptyEntity();
|
||||
if ($this->request->is('post')) {
|
||||
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $this->request->getData());
|
||||
$postData = $this->request->getData();
|
||||
if ($this->request->getSession()->read('Auth.User.id')) {
|
||||
$postData['created_by'] = $this->request->getSession()->read('Auth.User.id');
|
||||
}
|
||||
$saveOptions = [
|
||||
'associated' => [
|
||||
'ProductCategoryVariantOptions'
|
||||
],
|
||||
];
|
||||
$productCategoryVariant = $productCategoryVariantsTable->patchEntity($productCategoryVariant, $postData, $saveOptions);
|
||||
if ($productCategoryVariantsTable->save($productCategoryVariant)) {
|
||||
$this->Flash->success(__('The product category variant has been saved.'));
|
||||
|
||||
return $this->redirect(['action' => 'index']);
|
||||
}
|
||||
Log::debug('print_r($productCategoryVariant->getErrors(), true) failed to save in product category variants add');
|
||||
Log::debug(print_r($productCategoryVariant->getErrors(), true));
|
||||
$this->Flash->error(__('The product category variant could not be saved. Please, try again.'));
|
||||
}
|
||||
$productCategories = $productCategoryVariantsTable->ProductCategories->find('list', keyField: 'internal_id', valueField: 'name')->all();
|
||||
|
|
|
@ -57,6 +57,8 @@ class ProductCategoryVariantsTable extends Table
|
|||
$this->hasMany('ProductCategoryVariantOptions', [
|
||||
'foreignKey' => 'product_category_variant_id',
|
||||
'className' => 'CakeProducts.ProductCategoryVariantOptions',
|
||||
'dependent' => true,
|
||||
'cascadeCallbacks' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -99,7 +101,7 @@ class ProductCategoryVariantsTable extends Table
|
|||
*/
|
||||
public function buildRules(RulesChecker $rules): RulesChecker
|
||||
{
|
||||
$rules->add($rules->isUnique(['name', 'product_category_id', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
|
||||
// $rules->add($rules->isUnique(['name', 'product_category_id', 'product_id'], ['allowMultipleNulls' => true]), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_category_id'], 'ProductCategories'), ['errorField' => 'product_category_id']);
|
||||
$rules->add($rules->existsIn(['product_id'], 'Products'), ['errorField' => 'product_id']);
|
||||
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
use App\View\AppView;
|
||||
use Cake\Datasource\EntityInterface;
|
||||
|
||||
/**
|
||||
* @var AppView $this
|
||||
* @var EntityInterface $productCategoryAttributeOption
|
||||
*/
|
||||
|
||||
$this->setLayout('ajax');
|
||||
$prefix = $prefix ?? '';
|
||||
if ($this->request->getQuery('prefix') !== null) {
|
||||
$prefix = 'product_category_variant_options.' . $this->request->getQuery('prefix') . '.';
|
||||
}
|
||||
echo '<hr class="my-2">';
|
||||
echo $this->element('ProductCategoryVariants/product_category_variant_option_form', [
|
||||
'prefix' => $prefix
|
||||
]);
|
||||
?>
|
|
@ -43,6 +43,34 @@
|
|||
<td><?= $productCategoryVariant->enabled ? __('Yes') : __('No'); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
<div class="related">
|
||||
<h4><?= __('Related Product Category Variant Options') ?></h4>
|
||||
<?php if (!empty($productCategoryVariant->product_category_variant_options)) : ?>
|
||||
<div class="table-responsive">
|
||||
<table>
|
||||
<tr>
|
||||
<th><?= __('Variant Value') ?></th>
|
||||
<th><?= __('Variant Label') ?></th>
|
||||
<th><?= __('Enabled') ?></th>
|
||||
<th class="actions"><?= __('Actions') ?></th>
|
||||
</tr>
|
||||
<?php foreach ($productCategoryVariant->product_category_variant_options as $productCategoryVariantOption) : ?>
|
||||
<tr>
|
||||
<td><?= h($productCategoryVariantOption->variant_value) ?></td>
|
||||
<td><?= h($productCategoryVariantOption->variant_label) ?></td>
|
||||
<td><?= h($productCategoryVariantOption->enabled) ?></td>
|
||||
<td class="actions">
|
||||
<?= $this->Html->link(__('View'), ['controller' => 'ProductCategoryVariantOptions', 'action' => 'view', $productCategoryVariantOption->id]) ?>
|
||||
<?= $this->Html->link(__('Edit'), ['controller' => 'ProductCategoryVariantOptions', 'action' => 'edit', $productCategoryVariantOption->id]) ?>
|
||||
<?= $this->Form->postLink(__('Delete'), ['controller' => 'ProductCategoryVariantOptions', 'action' => 'delete', $productCategoryVariantOption->id], ['confirm' => __('Are you sure you want to delete # {0}?', $productCategoryVariantOption->id)]) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -8,15 +8,15 @@ $prefix = $prefix ?? '';
|
|||
\Cake\Log\Log::debug('$prefix');
|
||||
\Cake\Log\Log::debug($prefix);
|
||||
?>
|
||||
<div class="container product-category-attribute-options-container" data-test="1" data-prefix="<?= $prefix; ?>">
|
||||
<div class="container product-category-variant-options-container" data-test="1" data-prefix="<?= $prefix; ?>">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<?= $this->Form->control($prefix . 'attribute_value', [
|
||||
<?= $this->Form->control($prefix . 'variant_value', [
|
||||
'label' => 'Value',
|
||||
]); ?>
|
||||
</div>
|
||||
<div class="col">
|
||||
<?= $this->Form->control($prefix . 'attribute_label', [
|
||||
<?= $this->Form->control($prefix . 'variant_label', [
|
||||
'label' => 'Label',
|
||||
]); ?>
|
||||
</div>
|
||||
|
|
|
@ -19,8 +19,8 @@ class ProductCategoryVariantOptionsFixture extends TestFixture
|
|||
{
|
||||
$this->records = [
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'variant_value' => 'Color',
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d23',
|
||||
'variant_value' => 'Blue',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
|
@ -28,8 +28,8 @@ class ProductCategoryVariantOptionsFixture extends TestFixture
|
|||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'variant_value' => 'Size',
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d24',
|
||||
'variant_value' => 'Red',
|
||||
'variant_label' => null,
|
||||
'product_category_variant_id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'created' => '2025-07-04 12:00:00',
|
||||
|
|
|
@ -21,18 +21,17 @@ class ProductCategoryVariantsFixture extends TestFixture
|
|||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d93',
|
||||
'name' => 'Color',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'product_id' => null,
|
||||
'enabled' => 1,
|
||||
],
|
||||
[
|
||||
'id' => '5a386e9f-6e7a-4ae7-9360-c8e529f78d94',
|
||||
'name' => 'Color',
|
||||
'product_category_id' => '6d223283-361b-4f9f-a7f1-c97aa0ca4c23',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'product_id' => 'cfc98a9a-29b2-44c8-b587-8156adc05317',
|
||||
'enabled' => 1,
|
||||
],
|
||||
|
||||
];
|
||||
parent::init();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace CakeProducts\Test\TestCase\Controller;
|
|||
use CakeProducts\Controller\ProductCategoryVariantsController;
|
||||
use Cake\TestSuite\IntegrationTestTrait;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use CakeProducts\Model\Table\ProductCategoryVariantOptionsTable;
|
||||
use CakeProducts\Model\Table\ProductCategoryVariantsTable;
|
||||
use PHPUnit\Exception;
|
||||
|
||||
|
@ -22,6 +23,13 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
|
|||
* @var ProductCategoryVariantsTable|Table
|
||||
*/
|
||||
protected $ProductCategoryVariants;
|
||||
|
||||
/**
|
||||
* Test subject
|
||||
*
|
||||
* @var ProductCategoryVariantOptionsTable|Table
|
||||
*/
|
||||
protected $ProductCategoryVariantOptions;
|
||||
/**
|
||||
* Fixtures
|
||||
*
|
||||
|
@ -42,6 +50,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
|
|||
{
|
||||
parent::setUp();
|
||||
$this->ProductCategoryVariants = $this->getTableLocator()->get('ProductCategoryVariants');
|
||||
$this->ProductCategoryVariantOptions = $this->getTableLocator()->get('ProductCategoryVariantOptions');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,6 +61,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
|
|||
protected function tearDown(): void
|
||||
{
|
||||
unset($this->ProductCategoryVariants);
|
||||
unset($this->ProductCategoryVariantOptions);
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
@ -142,6 +152,7 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
|
|||
public function testAddPostLoggedInSuccess(): void
|
||||
{
|
||||
$cntBefore = $this->ProductCategoryVariants->find()->count();
|
||||
$cntBeforeOptions = $this->ProductCategoryVariantOptions->find()->count();
|
||||
|
||||
$this->loginUserByRole('admin');
|
||||
$url = [
|
||||
|
@ -152,14 +163,29 @@ class ProductCategoryVariantsControllerTest extends BaseControllerTest
|
|||
$data = [
|
||||
'name' => 'Size',
|
||||
'product_category_id' => 'db4b4273-eddc-46d4-93c8-45cf7c6e058e',
|
||||
'product_id' => '',
|
||||
'enabled' => true,
|
||||
'product_category_variant_options' => [
|
||||
[
|
||||
'variant_value' => 'XL',
|
||||
'variant_label' => 'XL',
|
||||
'enabled' => true,
|
||||
],
|
||||
[
|
||||
'variant_value' => 'XXL',
|
||||
'variant_label' => 'XXL',
|
||||
'enabled' => true,
|
||||
],
|
||||
]
|
||||
];
|
||||
$this->post($url, $data);
|
||||
$this->assertResponseCode(302);
|
||||
$this->assertRedirectContains('product-category-variants');
|
||||
|
||||
$cntAfter = $this->ProductCategoryVariants->find()->count();
|
||||
$cntAfterOptions = $this->ProductCategoryVariantOptions->find()->count();
|
||||
$this->assertEquals($cntBefore + 1, $cntAfter);
|
||||
$this->assertEquals($cntBeforeOptions + 2, $cntAfterOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,8 +24,8 @@ class ProductCategoryVariantOptionsTableTest extends TestCase
|
|||
* @var array<string>
|
||||
*/
|
||||
protected array $fixtures = [
|
||||
// 'ProductCategoryVariantOptions',
|
||||
// 'ProductCategoryVariants',
|
||||
'plugin.CakeProducts.ProductCategoryVariants',
|
||||
'plugin.CakeProducts.ProductCategoryVariantOptions',
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue