Skip to content

Commit

Permalink
used consistant code in all class
Browse files Browse the repository at this point in the history
  • Loading branch information
sunel committed Mar 3, 2019
1 parent 019e4e0 commit 0e6fcaa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public static function add(array $data)
$instance = new static;

try {
$eavEntity = Entity::where('entity_code', '=', $data['entity_code'])->firstOrFail();
$eavEntity = Entity::findByCode($data['entity_code']);
} catch (ModelNotFoundException $e) {
throw new \Exception("Unable to load Entity : ".$data['entity_code']);
}
Expand Down Expand Up @@ -313,7 +313,7 @@ public static function remove(array $data)
$instance = new static;

try {
$eavEntity = Entity::where('entity_code', '=', $data['entity_code'])->firstOrFail();
$eavEntity = Entity::findByCode($data['entity_code']);
} catch (ModelNotFoundException $e) {
throw new \Exception("Unable to load Entity : ".$data['entity_code']);
}
Expand Down
28 changes: 14 additions & 14 deletions src/EntityAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ public static function map(array $data)
{
$instance = new static;

$eavEntity = $instance->findEntity($data['entity_code']);
$entity = $instance->findEntity($data['entity_code']);

$eavAttribute = $instance->findAttribute($data['attribute_code'], $eavEntity);
$attribute = $instance->findAttribute($data['attribute_code'], $entity);

$eavAttributeSet = $instance->findOrCreateSet($data['attribute_set'], $eavEntity);
$set = $instance->findOrCreateSet($data['attribute_set'], $entity);

$eavAttributeGroup = $instance->findOrCreateGroup($data['attribute_group'], $eavAttributeSet);
$group = $instance->findOrCreateGroup($data['attribute_group'], $set);

$instance->fill([
'entity_id' => $eavEntity->entity_id,
'attribute_set_id' => $eavAttributeSet->attribute_set_id,
'attribute_group_id' => $eavAttributeGroup->attribute_group_id,
'attribute_id' => $eavAttribute->attribute_id
'entity_id' => $entity->entity_id,
'attribute_set_id' => $set->attribute_set_id,
'attribute_group_id' => $group->attribute_group_id,
'attribute_id' => $attribute->attribute_id
])->save();
}

Expand All @@ -61,13 +61,13 @@ public static function unmap(array $data)
{
$instance = new static;

$eavEntity = $instance->findEntity($data['entity_code']);
$entity = $instance->findEntity($data['entity_code']);

$eavAttribute = $instance->findAttribute($data['attribute_code'], $eavEntity);
$attribute = $instance->findAttribute($data['attribute_code'], $entity);

$instance->where([
'entity_id' => $eavEntity->entity_id,
'attribute_id' => $eavAttribute->attribute_id
'entity_id' => $entity->entity_id,
'attribute_id' => $attribute->attribute_id
])->delete();
}

Expand Down Expand Up @@ -100,10 +100,10 @@ private function findOrCreateSet($code, $entity)
]);
}

private function findOrCreateGroup($code, $attributeSet)
private function findOrCreateGroup($code, $set)
{
return AttributeGroup::firstOrCreate([
'attribute_set_id' => $attributeSet->attribute_set_id,
'attribute_set_id' => $set->attribute_set_id,
'attribute_group_name' => $code,
]);
}
Expand Down

0 comments on commit 0e6fcaa

Please sign in to comment.