category id not null but product id can be null same with sku id - product photos
This commit is contained in:
@@ -34,4 +34,24 @@ class SecondToggleBehavior extends ToggleBehavior {
|
||||
'findOrder' => null, // null = autodetect modified/created, false to disable
|
||||
'implementedMethods' => [], // to prevent conflict with public toggleField method
|
||||
];
|
||||
|
||||
/**
|
||||
* @param \Cake\Datasource\EntityInterface $entity
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildConditions(EntityInterface $entity) {
|
||||
$conditions = $this->getConfig('scope');
|
||||
$scopeFields = (array)$this->getConfig('scopeFields');
|
||||
|
||||
foreach ($scopeFields as $scopeField) {
|
||||
if ($entity->get($scopeField) === null) {
|
||||
continue;
|
||||
}
|
||||
$conditions[$scopeField] = $entity->get($scopeField);
|
||||
}
|
||||
// dd($conditions);
|
||||
|
||||
return $conditions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,13 @@ class ProductPhotosTable extends Table
|
||||
$this->addBehavior('Timestamp');
|
||||
|
||||
$this->addBehavior('Tools.Toggle', [
|
||||
'field' => 'primary_category_photo',
|
||||
'scopeFields' => ['product_category_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.SecondToggle', [
|
||||
'field' => 'primary_photo',
|
||||
'scopeFields' => ['product_id'],
|
||||
'scope' => [
|
||||
@@ -67,14 +74,6 @@ class ProductPhotosTable extends Table
|
||||
'product_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.SecondToggle', [
|
||||
'field' => 'primary_category_photo',
|
||||
'scopeFields' => ['product_category_id'],
|
||||
'scope' => [
|
||||
'deleted IS' => null,
|
||||
'product_category_id IS NOT' => null,
|
||||
],
|
||||
]);
|
||||
$this->addBehavior('CakeProducts.ThirdToggle', [
|
||||
'field' => 'primary_sku_photo',
|
||||
'scopeFields' => ['product_sku_id'],
|
||||
@@ -92,7 +91,7 @@ class ProductPhotosTable extends Table
|
||||
$this->belongsTo('ProductCategories', [
|
||||
'foreignKey' => 'product_category_id',
|
||||
'bindingKey' => 'internal_id',
|
||||
'joinType' => 'LEFT',
|
||||
'joinType' => 'INNER',
|
||||
'className' => 'CakeProducts.ProductCategories',
|
||||
]);
|
||||
|
||||
@@ -121,7 +120,8 @@ class ProductPhotosTable extends Table
|
||||
|
||||
$validator
|
||||
->uuid('product_category_id')
|
||||
->allowEmptyString('product_category_id');
|
||||
->requirePresence('product_category_id', 'create')
|
||||
->notEmptyString('product_category_id');
|
||||
|
||||
$validator
|
||||
->scalar('photo_dir')
|
||||
|
||||
Reference in New Issue
Block a user