product flat all set with data structure with all the permutations of channels and locales now being recorded from the product attribute values

This commit is contained in:
Prashant Singh 2019-01-22 18:25:47 +05:30
parent f156511e97
commit 810d5928c3
3 changed files with 105 additions and 97 deletions

View File

@ -53,7 +53,7 @@ Bagisto is using power of both of these frameworks and making best out of it out
* **OS**: Ubuntu 16.04 LTS or higher.
* **SERVER**: Apache 2 or NGINX
* **RAM**: 2 GB or higer.
* **RAM**: 2 GB or higher.
* **PHP**: 7.1.17 or higher.
* **Processor**: Clock Cycle 1Ghz or higher.
* **Mysql**: 5.7.23 or higher.

View File

@ -279,106 +279,114 @@ class ProductController extends Controller
*/
public function testProductFlat() {
$product = $this->product->find(4);
$allChannelAndLocales = [];
$productMapped = [];
$channelLocaleMap = [];
$productAttributes = $product->attribute_family->custom_attributes;
$allLocales = core()->getAllLocales();
$productsFlat = array();
$attributeNames = array();
$channelLocaleMap = array();
$nonDependentAttributes = array();
$localeDependentAttributes = array();
$channelDependentAttributes = array();
$channelLocaleDependentAttributes = array();
foreach($productAttributes as $key => $productAttribute) {
$attributeNames[$key] = [
'id' => $productAttribute->id,
'code' => $productAttribute->code,
'value_per_locale' => $productAttribute->value_per_locale,
'value_per_channel' => $productAttribute->value_per_channel,
];
}
foreach($productAttributes as $productAttribute) {
if($productAttribute->value_per_channel) {
if($productAttribute->value_per_locale) {
array_push($channelLocaleDependentAttributes, ['id' => $productAttribute->id, 'code' => $productAttribute->code]);
} else {
array_push($channelDependentAttributes, ['id' => $productAttribute->id, 'code' => $productAttribute->code]);
}
} else if($productAttribute->value_per_locale && !$productAttribute->value_per_channel) {
array_push($localeDependentAttributes, ['id' => $productAttribute->id, 'code' => $productAttribute->code]);
} else {
array_push($nonDependentAttributes, ['id' => $productAttribute->id, 'code' => $productAttribute->code]);
}
}
foreach(core()->getAllChannels() as $channel) {
array_push($productMapped, [
$dummy = [
'product_id' => $product->id,
'type' => $product->type,
'channel_code' => $channel->code,
'locale_code' => 'null',
]);
'channel' => $channel->code,
'locale' => null,
'data' => $channelDependentAttributes
];
array_push($channelLocaleMap, [
'product_id' => $product->id,
'type' => $product->type,
'channel_code' => $channel->code,
'locale_code' => 'null',
]);
array_push($channelLocaleMap, $dummy);
$dummy = [];
foreach($channel->locales as $locale) {
array_push($productMapped, [
$dummy = [
'product_id' => $product->id,
'type' => $product->type,
'channel_code' => $channel->code,
'locale_code' => $locale->code
]);
'channel' => $channel->code,
'locale' => $locale->code,
'data' => $channelLocaleDependentAttributes
];
array_push($channelLocaleMap, [
'product_id' => $product->id,
'type' => $product->type,
'channel_code' => $channel->code,
'locale_code' => $locale->code,
]);
array_push($channelLocaleMap, $dummy);
array_push($productMapped, [
'product_id' => $product->id,
'type' => $product->type,
'channel_code' => 'null',
'locale_code' => $locale->code,
]);
array_push($channelLocaleMap, [
'product_id' => $product->id,
'type' => $product->type,
'channel_code' => 'null',
'locale_code' => $locale->code,
]);
$dummy = [];
}
}
$attributes = $product->attribute_family->custom_attributes;
$dummy = [
'product_id' => $product->id,
'channel' => null,
'locale' => null,
'data' => $nonDependentAttributes
];
foreach($attributes as $key => $attribute) {
if($attribute->value_per_channel && $attribute->value_per_locale) {
$values = $this->productAttributeValue->findWhere(['attribute_id' => $attribute->id, 'product_id' => $product->id]);
array_push($channelLocaleMap, $dummy);
foreach($values as $key => $value) {
$this->pushCorrect($value->channel, $value->locale, $productMapped);
$dummy = [];
foreach($allLocales as $key => $allLocale) {
$dummy = [
'product_id' => $product->id,
'channel' => null,
'locale' => $allLocale->code,
'data' => $localeDependentAttributes
];
array_push($channelLocaleMap, $dummy);
$dummy = [];
}
$productFlatObjects = $channelLocaleMap;
foreach($productAttributes as $productAttribute) {
foreach($productFlatObjects as $flatKey => $productFlatObject) {
foreach($productFlatObject['data'] as $key => $value) {
if($productAttribute->code == $value['code']) {
$valueOf = $this->productAttributeValue->findOneWhere([
'product_id' => $product->id,
'channel' => $productFlatObject['channel'],
'locale' => $productFlatObject['locale'],
'attribute_id' => $productAttribute->id
]);
$productAttributeColumn = $this->productAttributeValue->model()::$attributeTypeFields[$productAttribute->type];
dump($productAttributeColumn);
$valueOf = $valueOf->{$productAttributeColumn};
$productFlatObjects[$flatKey][$productAttribute->code] = $valueOf;
}
}
} else if($attribute->value_per_channel && !$attribute->value_per_locale) {
$this->pushCorrect($value->channel, $value->locale, $productMapped);
} else if($attribute->value_per_locale) {
$this->pushCorrect($value->channel, $value->locale, $productMapped);
} else {
$this->pushCorrect($value->channel, $value->locale, $productMapped);
}
// if($attribute->type == 'select') {
// if($attribute->value_per_channel && $attribute->value_per_locale) {
// dd($this->productAttributeValue->findWhere(['attribute_id' => $attribute->id]));
// // $this->pushCorrect($attribute->channel);
// } else if($attribute->value_per_channel && !$attribute->value_per_locale) {
// // $this->pushCorrect();
// } else if($attribute->value_per_locale) {
// // $this->pushCorrect();
// } else {
// // $this->pushCorrect();
// }
// } else if($attribute->type == 'multiselect') {
// // $this->pushCorrect();
// } else {
// if($attribute->value_per_channel && $attribute->value_per_locale) {
// dd($this->productAttributeValue->findWhere(['attribute_id' => $attribute->id]));
// // $this->pushCorrect($attribute->channel);
// } else if($attribute->value_per_channel && !$attribute->value_per_locale) {
// // $this->pushCorrect();
// } else if($attribute->value_per_locale) {
// // $this->pushCorrect();
// } else {
// // $this->pushCorrect();
// }
// }
}
dd($productMapped);
}
public function pushCorrect($channelCode = null, $localeCode = null, $productMapped) {
dd($channelCode, $localeCode, $productMapped);
dd($productFlatObjects);
}
}

View File

@ -28,19 +28,19 @@ class ProductAttributeValue extends Model
];
protected $fillable = [
'product_id',
'attribute_id',
'channel_id',
'locale',
'channel',
'text_value',
'boolean_value',
'integer_value',
'float_value',
'datetime_value',
'date_value',
'json_value'
];
'product_id',
'attribute_id',
'channel_id',
'locale',
'channel',
'text_value',
'boolean_value',
'integer_value',
'float_value',
'datetime_value',
'date_value',
'json_value'
];
/**
* Get the attribute that owns the attribute value.