From df152d84cbe3bbda818f8d06a064a1cb46fd9ca2 Mon Sep 17 00:00:00 2001 From: Devansh Date: Wed, 22 Dec 2021 12:30:37 +0530 Subject: [PATCH] Quantity Added --- .../Webkul/Product/src/Type/Configurable.php | 49 ++++++++++--------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/packages/Webkul/Product/src/Type/Configurable.php b/packages/Webkul/Product/src/Type/Configurable.php index 3a0716fe7..2e94547da 100644 --- a/packages/Webkul/Product/src/Type/Configurable.php +++ b/packages/Webkul/Product/src/Type/Configurable.php @@ -95,7 +95,7 @@ class Configurable extends AbstractType public function setDefaultVariantId($defaultVariantId) { $this->product->additional = array_merge($this->product->additional ?? [], [ - 'default_variant_id' => $defaultVariantId + 'default_variant_id' => $defaultVariantId, ]); } @@ -152,7 +152,7 @@ class Configurable extends AbstractType * @param string $attribute * @return \Webkul\Product\Contracts\Product */ - public function update(array $data, $id, $attribute = "id") + public function update(array $data, $id, $attribute = 'id') { $product = parent::update($data, $id, $attribute); @@ -222,7 +222,7 @@ class Configurable extends AbstractType $typeOfVariants = 'simple'; $productInstance = app(config('product_types.' . $product->type . '.class')); - if (isset($productInstance->variantsType) && ! in_array($productInstance->variantsType , ['bundle', 'configurable', 'grouped'])) { + if (isset($productInstance->variantsType) && ! in_array($productInstance->variantsType, ['bundle', 'configurable', 'grouped'])) { $typeOfVariants = $productInstance->variantsType; } @@ -333,7 +333,7 @@ class Configurable extends AbstractType ]); } else { $this->attributeValueRepository->update([ - ProductAttributeValue::$attributeTypeFields[$attribute->type] => $data[$attribute->code] + ProductAttributeValue::$attributeTypeFields[$attribute->type] => $data[$attribute->code], ], $attributeValue->id); } } @@ -356,9 +356,9 @@ class Configurable extends AbstractType * Name field is not present when variant is created so adding sku. */ return array_merge($data, [ - 'url_key' => $data['sku'], + 'url_key' => $data['sku'], 'short_description' => $data['sku'], - 'description' => $data['sku'] + 'description' => $data['sku'], ]); } @@ -487,7 +487,8 @@ class Configurable extends AbstractType * * @return float */ - public function getOfferPrice() { + public function getOfferPrice() + { $rulePrices = $customerGroupPrices = []; foreach ($this->product->variants as $variant) { @@ -507,16 +508,17 @@ class Configurable extends AbstractType return []; } - /** + /** * Check for offer. * * @return bool */ - public function haveOffer() { + public function haveOffer() + { $haveOffer = false; $offerPrice = $this->getOfferPrice(); - $minPrice = $this->getMinimalPrice(); + $minPrice = $this->getMinimalPrice(); if ($offerPrice < $minPrice) { $haveOffer = true; @@ -535,7 +537,7 @@ class Configurable extends AbstractType $productFlat = ProductFlat::join('products', 'product_flat.product_id', '=', 'products.id') ->distinct() ->where('products.parent_id', $this->product->id) - ->selectRaw('MAX('.DB::getTablePrefix().'product_flat.price) AS max_price') + ->selectRaw('MAX(' . DB::getTablePrefix() . 'product_flat.price) AS max_price') ->where('product_flat.channel', core()->getCurrentChannelCode()) ->where('product_flat.locale', app()->getLocale()) ->first(); @@ -551,14 +553,14 @@ class Configurable extends AbstractType public function getProductPrices() { return [ - 'regular_price' => [ + 'regular_price' => [ 'formated_price' => $this->haveOffer() ? core()->currency($this->evaluatePrice($this->getOfferPrice())) : core()->currency($this->evaluatePrice($this->getMinimalPrice())), 'price' => $this->haveOffer() ? $this->evaluatePrice($this->getOfferPrice()) : $this->evaluatePrice($this->getMinimalPrice()), - ] + ], ]; } @@ -607,12 +609,13 @@ class Configurable extends AbstractType $price = $childProduct->getTypeInstance()->getFinalPrice(); - $products = [ + return [ [ 'product_id' => $this->product->id, 'sku' => $this->product->sku, - 'quantity' => $data['quantity'], 'name' => $this->product->name, + 'type' => $this->product->type, + 'quantity' => $data['quantity'], 'price' => $convertedPrice = core()->convertPrice($price), 'base_price' => $price, 'total' => $convertedPrice * $data['quantity'], @@ -620,22 +623,20 @@ class Configurable extends AbstractType 'weight' => $childProduct->weight, 'total_weight' => $childProduct->weight * $data['quantity'], 'base_total_weight' => $childProduct->weight * $data['quantity'], - 'type' => $this->product->type, 'additional' => $this->getAdditionalOptions($data), ], [ 'parent_id' => $this->product->id, 'product_id' => (int) $data['selected_configurable_option'], 'sku' => $childProduct->sku, 'name' => $childProduct->name, - 'type' => 'simple', + 'type' => $childProduct->type, + 'quantity' => $data['quantity'], 'additional' => [ 'product_id' => (int) $data['selected_configurable_option'], - 'parent_id' => $this->product->id + 'parent_id' => $this->product->id, ], - ] + ], ]; - - return $products; } /** @@ -674,7 +675,7 @@ class Configurable extends AbstractType $option = $attribute->options()->where('id', $childProduct->{$attribute->code})->first(); $data['attributes'][$attribute->code] = [ - 'attribute_name' => $attribute->name ? $attribute->name : $attribute->admin_name, + 'attribute_name' => $attribute->name ? $attribute->name : $attribute->admin_name, 'option_id' => $option->id, 'option_label' => $option->label ? $option->label : $option->admin_name, ]; @@ -762,7 +763,7 @@ class Configurable extends AbstractType * @param string $product * @return array */ - public function getProductOptions($product = "") + public function getProductOptions($product = '') { $configurableOption = app('Webkul\Product\Helpers\ConfigurableOption'); $options = $configurableOption->getConfigurationConfig($product); @@ -780,7 +781,7 @@ class Configurable extends AbstractType { $backorders = core()->getConfigData('catalog.inventory.stock_options.backorders'); - $backorders = ! is_null ($backorders) ? $backorders : false; + $backorders = ! is_null($backorders) ? $backorders : false; foreach ($this->product->variants as $variant) { if ($variant->haveSufficientQuantity($qty)) {