Merge pull request #5454 from devansh-webkul/conf-issue

Quantity Added #5451
This commit is contained in:
Devansh 2021-12-22 13:29:58 +05:30 committed by GitHub
commit 837f78fa28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 24 deletions

View File

@ -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)) {