PR 1782 Enhancement: Let variants be of other types than simple

This commit is contained in:
Annika Wolff 2019-11-26 13:32:42 +01:00
parent 58bad6fbed
commit 71e8e687c2
3 changed files with 42 additions and 2 deletions

View File

@ -64,7 +64,7 @@
</select>
@if ($familyId)
<input type="hidden" name="type" value="configurable"/>
<input type="hidden" name="type" value="{{ app('request')->input('type') }}"/>
@endif
<span class="control-error" v-if="errors.has('type')">@{{ errors.first('type') }}</span>
</div>

View File

@ -0,0 +1,33 @@
<?php
namespace Webkul\Customer\Http\Listeners;
use Cookie;
use Cart;
class CustomerEventsHandler {
/**
* Handle Customer login events.
*/
public function onCustomerLogin($event)
{
/**
* handle the user login event to manage the after login, if the user has added any products as guest then
* the cart items from session will be transferred from cookie to the cart table in the database.
*
* Check whether cookie is present or not and then check emptiness and then do the appropriate actions.
*/
Cart::mergeCart();
}
/**
* Register the listeners for the subscriber.
*
* @param Illuminate\Events\Dispatcher $events
* @return void
*/
public function subscribe($events)
{
$events->listen('customer.after.login', 'Webkul\Customer\Http\Listeners\CustomerEventsHandler@onCustomerLogin');
}
}

View File

@ -143,9 +143,16 @@ class Configurable extends AbstractType
];
}
$typeOfVariants = 'simple';
$productInstance = app(config('product_types.' . $product->type . '.class'));
if ($productInstance->variantsType && !in_array($productInstance->variantsType , ['bundle', 'configurable', 'grouped']))
{
$typeOfVariants = $productInstance->variantsType;
}
$variant = $this->productRepository->getModel()->create([
'parent_id' => $product->id,
'type' => 'simple',
'type' => $typeOfVariants,
'attribute_family_id' => $product->attribute_family_id,
'sku' => $data['sku'],
]);