fix missing product attribute fields
This commit is contained in:
parent
146338e2a4
commit
2fc815dece
|
|
@ -7,20 +7,20 @@ namespace Webkul\Core\Helpers;
|
|||
|
||||
use Faker\Factory;
|
||||
use Codeception\Module\Laravel5;
|
||||
use Webkul\Attribute\Models\Attribute;
|
||||
use Webkul\Attribute\Models\AttributeOption;
|
||||
use Webkul\BookingProduct\Models\BookingProduct;
|
||||
use Webkul\BookingProduct\Models\BookingProductEventTicket;
|
||||
use Webkul\Checkout\Models\Cart;
|
||||
use Webkul\Checkout\Models\CartAddress;
|
||||
use Webkul\Checkout\Models\CartItem;
|
||||
use Webkul\Customer\Models\Customer;
|
||||
use Webkul\Product\Models\Product;
|
||||
use Webkul\Attribute\Models\Attribute;
|
||||
use Webkul\Checkout\Models\CartAddress;
|
||||
use Webkul\Product\Models\ProductInventory;
|
||||
use Webkul\Customer\Models\CustomerAddress;
|
||||
use Webkul\Attribute\Models\AttributeOption;
|
||||
use Webkul\Product\Models\Product;
|
||||
use Webkul\Product\Models\ProductAttributeValue;
|
||||
use Webkul\Product\Models\ProductDownloadableLink;
|
||||
use Webkul\Product\Models\ProductDownloadableLinkTranslation;
|
||||
use Webkul\Product\Models\ProductInventory;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
|
||||
|
|
@ -212,7 +212,7 @@ class Laravel5Helper extends Laravel5
|
|||
|
||||
$product = $I->createProduct($configs['productAttributes'] ?? [], $productStates);
|
||||
|
||||
$I->createAttributeValues($product->id, $configs['attributeValues'] ?? []);
|
||||
$I->createAttributeValues($product, $configs['attributeValues'] ?? []);
|
||||
|
||||
$I->createInventory($product->id, $configs['productInventory'] ?? []);
|
||||
|
||||
|
|
@ -228,7 +228,7 @@ class Laravel5Helper extends Laravel5
|
|||
|
||||
$product = $I->createProduct($configs['productAttributes'] ?? [], $productStates);
|
||||
|
||||
$I->createAttributeValues($product->id, $configs['attributeValues'] ?? []);
|
||||
$I->createAttributeValues($product, $configs['attributeValues'] ?? []);
|
||||
|
||||
$I->createInventory($product->id, $configs['productInventory'] ?? []);
|
||||
|
||||
|
|
@ -244,7 +244,7 @@ class Laravel5Helper extends Laravel5
|
|||
|
||||
$product = $I->createProduct($configs['productAttributes'] ?? [], $productStates);
|
||||
|
||||
$I->createAttributeValues($product->id, $configs['attributeValues'] ?? []);
|
||||
$I->createAttributeValues($product, $configs['attributeValues'] ?? []);
|
||||
|
||||
$I->createDownloadableLink($product->id);
|
||||
|
||||
|
|
@ -260,7 +260,7 @@ class Laravel5Helper extends Laravel5
|
|||
|
||||
$product = $I->createProduct($configs['productAttributes'] ?? [], $productStates);
|
||||
|
||||
$I->createAttributeValues($product->id, $configs['attributeValues'] ?? []);
|
||||
$I->createAttributeValues($product, $configs['attributeValues'] ?? []);
|
||||
|
||||
$I->createBookingEventProduct($product->id);
|
||||
|
||||
|
|
@ -305,7 +305,7 @@ class Laravel5Helper extends Laravel5
|
|||
]);
|
||||
}
|
||||
|
||||
private function createAttributeValues(int $productId, array $attributeValues = []): void
|
||||
private function createAttributeValues(Product $product, array $attributeValues = []): void
|
||||
{
|
||||
$I = $this;
|
||||
|
||||
|
|
@ -313,7 +313,7 @@ class Laravel5Helper extends Laravel5
|
|||
|
||||
$brand = Attribute::query()
|
||||
->where(['code' => 'brand'])
|
||||
->first(); // usually 25
|
||||
->firstOrFail(); // usually 25
|
||||
|
||||
if (! AttributeOption::query()
|
||||
->where(['attribute_id' => $brand->id])
|
||||
|
|
@ -331,10 +331,10 @@ class Laravel5Helper extends Laravel5
|
|||
* If you do not want this, this defaults can be overriden by $attributeValues.
|
||||
*/
|
||||
$defaultAttributeValues = [
|
||||
'name' => $faker->word,
|
||||
'name' => $faker->words(3, true),
|
||||
'description' => $faker->sentence,
|
||||
'short_description' => $faker->sentence,
|
||||
'sku' => $faker->word,
|
||||
'sku' => $product->sku,
|
||||
'url_key' => $faker->slug,
|
||||
'status' => true,
|
||||
'guest_checkout' => true,
|
||||
|
|
@ -357,7 +357,7 @@ class Laravel5Helper extends Laravel5
|
|||
|
||||
foreach ($possibleAttributeValues as $attributeSet) {
|
||||
$data = [
|
||||
'product_id' => $productId,
|
||||
'product_id' => $product->id,
|
||||
'attribute_id' => $attributeSet->id,
|
||||
];
|
||||
|
||||
|
|
@ -365,7 +365,78 @@ class Laravel5Helper extends Laravel5
|
|||
|
||||
$data[$fieldName] = $attributeValues[$attributeSet->code] ?? null;
|
||||
|
||||
$data = $this->appendAttributeDependencies($attributeSet->code, $data);
|
||||
|
||||
$I->have(ProductAttributeValue::class, $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $attributeCode
|
||||
* @param array $data
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function appendAttributeDependencies(string $attributeCode, array $data): array
|
||||
{
|
||||
$locale = core()->getCurrentLocale()->code;
|
||||
$channel = core()->getCurrentChannelCode();
|
||||
|
||||
$attributeSetDependencies = [
|
||||
'name' => [
|
||||
'locale',
|
||||
'channel',
|
||||
],
|
||||
'tax_category_id' => [
|
||||
'channel',
|
||||
],
|
||||
'short_description' => [
|
||||
'locale',
|
||||
'channel',
|
||||
],
|
||||
'description' => [
|
||||
'locale',
|
||||
'channel',
|
||||
],
|
||||
'cost' => [
|
||||
'channel',
|
||||
],
|
||||
'special_price_from' => [
|
||||
'channel',
|
||||
],
|
||||
'special_price_to' => [
|
||||
'channel',
|
||||
],
|
||||
'meta_title' => [
|
||||
'locale',
|
||||
'channel',
|
||||
],
|
||||
'meta_keywords' => [
|
||||
'locale',
|
||||
'channel',
|
||||
],
|
||||
'meta_description' => [
|
||||
'locale',
|
||||
'channel',
|
||||
],
|
||||
'custom_sale_badge' => [
|
||||
'locale',
|
||||
],
|
||||
];
|
||||
|
||||
if (array_key_exists($attributeCode, $attributeSetDependencies)) {
|
||||
foreach ($attributeSetDependencies[$attributeCode] as $key) {
|
||||
if ($key === 'locale') {
|
||||
$data['locale'] = $locale;
|
||||
}
|
||||
|
||||
if ($key === 'channel') {
|
||||
$data['channel'] = $channel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue