Merge pull request #884 from jitendra-webkul/jitendra

Jitendra
This commit is contained in:
Jitendra Singh 2019-04-26 12:44:24 +05:30 committed by GitHub
commit 34aeeac2d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 17 deletions

View File

@ -259,7 +259,8 @@ class Cart {
*/
public function createItem($id, $data)
{
$product = $parentProduct = $configurable = false;
$childProduct = $configurable = false;
$product = $this->product->findOneByField('id', $id);
if ($product->type == 'configurable') {
@ -267,17 +268,15 @@ class Cart {
return false;
}
$parentProduct = $this->product->findOneByField('id', $data['selected_configurable_option']);
$childProduct = $this->product->findOneByField('id', $data['selected_configurable_option']);
$canAdd = $parentProduct->haveSufficientQuantity($data['quantity']);
$canAdd = $childProduct->haveSufficientQuantity($data['quantity']);
if (! $canAdd) {
session()->flash('warning', trans('shop::app.checkout.cart.quantity.inventory_warning'));
return false;
}
$configurable = true;
} else {
$canAdd = $product->haveSufficientQuantity($data['quantity']);
@ -289,12 +288,12 @@ class Cart {
}
//Check if the product's information is proper or not
if (! isset($data['product']) || !isset($data['quantity'])) {
if (! isset($data['product']) || ! isset($data['quantity'])) {
session()->flash('error', trans('shop::app.checkout.cart.integrity.missing_fields'));
return false;
} else {
if ($product->type == 'configurable' && !isset($data['super_attribute'])) {
if ($product->type == 'configurable' && ! isset($data['super_attribute'])) {
session()->flash('error', trans('shop::app.checkout.cart.integrity.missing_options'));
return false;
@ -305,12 +304,12 @@ class Cart {
$additional = [];
if ($product->type == 'configurable') {
$price = $this->price->getMinimalPrice($parentProduct);
$price = $this->price->getMinimalPrice($childProduct);
} else {
$price = $this->price->getMinimalPrice($product);
}
$weight = ($product->type == 'configurable' ? $parentProduct->weight : $product->weight);
$weight = ($product->type == 'configurable' ? $childProduct->weight : $product->weight);
$parentData = [
'sku' => $product->sku,
@ -330,27 +329,28 @@ class Cart {
'additional' => $data,
];
if ($configurable) {
$attributeDetails = $this->getProductAttributeOptionDetails($parentProduct);
if ($product->type == 'configurable') {
$attributeDetails = $this->getProductAttributeOptionDetails($childProduct);
unset($attributeDetails['html']);
$parentData['additional'] = array_merge($parentData['additional'], $attributeDetails);
$childData['product_id'] = (int)$data['selected_configurable_option'];
$childData['sku'] = $parentProduct->sku;
$childData['name'] = $parentProduct->name;
$childData['sku'] = $childProduct->sku;
$childData['name'] = $childProduct->name;
$childData['type'] = 'simple';
$childData['cart_id'] = $this->getCart()->id;
}
$result = $this->cartItem->create($parentData);
$item = $this->cartItem->create($parentData);
if ($childData != null) {
$childData['parent_id'] = $result->id;
$childData['parent_id'] = $item->id;
$this->cartItem->create($childData);
}
return $result;
return $item;
}
/**

View File

@ -158,9 +158,14 @@ class ProductFlat
{
static $familyAttributes = [];
static $superAttributes = [];
if (! array_key_exists($product->attribute_family->id, $familyAttributes))
$familyAttributes[$product->attribute_family->id] = $product->attribute_family->custom_attributes;
if ($parentProduct && ! array_key_exists($parentProduct->id, $superAttributes))
$superAttributes[$parentProduct->id] = $parentProduct->super_attributes()->pluck('code')->toArray();
foreach (core()->getAllChannels() as $channel) {
foreach ($channel->locales as $locale) {
$productFlat = $this->productFlatRepository->findOneWhere([
@ -178,7 +183,7 @@ class ProductFlat
}
foreach ($familyAttributes[$product->attribute_family->id] as $attribute) {
if ($parentProduct && ! in_array($attribute->code, ['sku', 'name', 'price', 'weight', 'status']))
if ($parentProduct && ! in_array($attribute->code, array_merge($superAttributes[$parentProduct->id], ['sku', 'name', 'price', 'weight', 'status'])))
continue;
if (in_array($attribute->code, ['short_description', 'tax_category_id', 'meta_title', 'meta_keywords', 'meta_description', 'width', 'height']))