2020-01-17 13:42:47 +00:00
|
|
|
<?php
|
2020-01-28 14:38:07 +00:00
|
|
|
|
2020-01-17 13:42:47 +00:00
|
|
|
namespace Webkul\Core\Helpers;
|
|
|
|
|
|
|
|
|
|
// here you can define custom actions
|
|
|
|
|
// all public methods declared in helper class will be available in $I
|
|
|
|
|
|
2020-09-01 05:43:51 +00:00
|
|
|
use StdClass;
|
2020-03-18 13:34:27 +00:00
|
|
|
use Faker\Factory;
|
2020-01-17 13:42:47 +00:00
|
|
|
use Codeception\Module\Laravel5;
|
2020-02-28 10:41:48 +00:00
|
|
|
use Webkul\Checkout\Models\Cart;
|
2020-09-01 05:43:51 +00:00
|
|
|
use Webkul\Product\Models\Product;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
2020-02-28 10:41:48 +00:00
|
|
|
use Webkul\Checkout\Models\CartItem;
|
2020-07-31 06:24:54 +00:00
|
|
|
use Webkul\Customer\Models\Customer;
|
2020-09-01 05:43:51 +00:00
|
|
|
use Illuminate\Support\Facades\Event;
|
|
|
|
|
use Webkul\Attribute\Models\Attribute;
|
|
|
|
|
use Webkul\Checkout\Models\CartAddress;
|
2020-02-28 10:41:48 +00:00
|
|
|
use Webkul\Customer\Models\CustomerAddress;
|
2020-09-01 05:43:51 +00:00
|
|
|
use Webkul\Product\Models\ProductInventory;
|
|
|
|
|
use Webkul\Attribute\Models\AttributeOption;
|
|
|
|
|
use Webkul\BookingProduct\Models\BookingProduct;
|
2020-01-28 14:38:07 +00:00
|
|
|
use Webkul\Product\Models\ProductAttributeValue;
|
|
|
|
|
use Webkul\Product\Models\ProductDownloadableLink;
|
2020-09-01 05:43:51 +00:00
|
|
|
use Webkul\BookingProduct\Models\BookingProductEventTicket;
|
2020-01-28 14:38:07 +00:00
|
|
|
use Webkul\Product\Models\ProductDownloadableLinkTranslation;
|
2020-01-17 13:42:47 +00:00
|
|
|
|
2020-03-30 13:03:27 +00:00
|
|
|
/**
|
|
|
|
|
* Class Laravel5Helper
|
|
|
|
|
*
|
|
|
|
|
* @package Webkul\Core\Helpers
|
|
|
|
|
*/
|
2020-01-17 13:42:47 +00:00
|
|
|
class Laravel5Helper extends Laravel5
|
|
|
|
|
{
|
2020-01-28 14:38:07 +00:00
|
|
|
public const SIMPLE_PRODUCT = 1;
|
|
|
|
|
public const VIRTUAL_PRODUCT = 2;
|
|
|
|
|
public const DOWNLOADABLE_PRODUCT = 3;
|
2020-07-31 06:24:54 +00:00
|
|
|
public const BOOKING_EVENT_PRODUCT = 4;
|
2020-01-28 14:38:07 +00:00
|
|
|
|
2020-01-17 13:42:47 +00:00
|
|
|
/**
|
2020-03-18 13:34:27 +00:00
|
|
|
* Returns the field name of the given attribute in which a value should be saved inside
|
|
|
|
|
* the 'product_attribute_values' table. Depends on the type.
|
2020-01-17 13:42:47 +00:00
|
|
|
*
|
2020-07-31 06:24:54 +00:00
|
|
|
* @param string $type
|
2020-01-17 13:42:47 +00:00
|
|
|
*
|
|
|
|
|
* @return string|null
|
|
|
|
|
* @part ORM
|
|
|
|
|
*/
|
2020-03-30 13:03:27 +00:00
|
|
|
public static function getAttributeFieldName(string $type): ?string
|
2020-01-17 13:42:47 +00:00
|
|
|
{
|
2020-03-18 13:34:27 +00:00
|
|
|
$possibleTypes = [
|
|
|
|
|
'text' => 'text_value',
|
|
|
|
|
'select' => 'integer_value',
|
|
|
|
|
'boolean' => 'boolean_value',
|
|
|
|
|
'textarea' => 'text_value',
|
|
|
|
|
'price' => 'float_value',
|
|
|
|
|
'date' => 'date_value',
|
2020-09-01 05:43:51 +00:00
|
|
|
'checkbox' => 'text_value',
|
2020-01-17 13:42:47 +00:00
|
|
|
];
|
2020-03-06 14:50:26 +00:00
|
|
|
|
2020-03-30 13:03:27 +00:00
|
|
|
return $possibleTypes[$type];
|
2020-01-17 13:42:47 +00:00
|
|
|
}
|
2020-01-28 14:38:07 +00:00
|
|
|
|
2020-02-28 10:41:48 +00:00
|
|
|
public function prepareCart(array $options = []): array
|
|
|
|
|
{
|
2020-07-31 06:24:54 +00:00
|
|
|
$faker = Factory::create();
|
2020-02-28 10:41:48 +00:00
|
|
|
|
|
|
|
|
$I = $this;
|
|
|
|
|
|
|
|
|
|
$product = $I->haveProduct(self::SIMPLE_PRODUCT, $options['productOptions'] ?? []);
|
|
|
|
|
|
|
|
|
|
if (isset($options['customer'])) {
|
|
|
|
|
$customer = $options['customer'];
|
|
|
|
|
} else {
|
|
|
|
|
$customer = $I->have(Customer::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$I->have(CustomerAddress::class, [
|
|
|
|
|
'default_address' => 1,
|
2020-03-30 13:03:27 +00:00
|
|
|
'customer_id' => $customer->id,
|
2020-02-28 10:41:48 +00:00
|
|
|
'first_name' => $customer->first_name,
|
|
|
|
|
'last_name' => $customer->last_name,
|
|
|
|
|
'company_name' => $faker->company,
|
|
|
|
|
]);
|
|
|
|
|
|
2020-03-02 08:08:51 +00:00
|
|
|
if (isset($options['payment_method'])
|
|
|
|
|
&& $options['payment_method'] === 'free_of_charge') {
|
2020-02-28 10:41:48 +00:00
|
|
|
$grand_total = '0.0000';
|
|
|
|
|
$base_grand_total = '0.0000';
|
|
|
|
|
} else {
|
|
|
|
|
$grand_total = (string)$faker->numberBetween(1, 666);
|
|
|
|
|
$base_grand_total = $grand_total;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cart = $I->have(Cart::class, [
|
|
|
|
|
'customer_id' => $customer->id,
|
|
|
|
|
'customer_first_name' => $customer->first_name,
|
|
|
|
|
'customer_last_name' => $customer->last_name,
|
|
|
|
|
'customer_email' => $customer->email,
|
2020-03-30 13:03:27 +00:00
|
|
|
'is_active' => $options['is_active'] ?? 1,
|
|
|
|
|
'channel_id' => $options['channel_id'] ?? 1,
|
2020-02-28 10:41:48 +00:00
|
|
|
'grand_total' => $grand_total,
|
|
|
|
|
'base_grand_total' => $base_grand_total,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$cartAddress = $I->have(CartAddress::class, ['cart_id' => $cart->id]);
|
|
|
|
|
|
2020-03-31 12:35:01 +00:00
|
|
|
$type = $options['product_type'] ?? 'simple';
|
2020-02-28 10:41:48 +00:00
|
|
|
|
2020-03-03 10:18:18 +00:00
|
|
|
$totalQtyOrdered = 0;
|
|
|
|
|
|
|
|
|
|
$cartItems = [];
|
|
|
|
|
|
2020-07-31 06:24:54 +00:00
|
|
|
$generatedCartItems = random_int(3, 10);
|
2020-03-03 10:18:18 +00:00
|
|
|
|
2020-02-28 10:41:48 +00:00
|
|
|
for ($i = 2; $i <= $generatedCartItems; $i++) {
|
2020-03-03 10:18:18 +00:00
|
|
|
$quantity = random_int(1, 10);
|
2020-02-28 10:41:48 +00:00
|
|
|
$cartItem = $I->have(CartItem::class, [
|
|
|
|
|
'type' => $type,
|
2020-03-03 10:18:18 +00:00
|
|
|
'quantity' => $quantity,
|
2020-02-28 10:41:48 +00:00
|
|
|
'cart_id' => $cart->id,
|
|
|
|
|
'product_id' => $product->id,
|
|
|
|
|
]);
|
2020-03-03 10:18:18 +00:00
|
|
|
|
|
|
|
|
$totalQtyOrdered += $quantity;
|
|
|
|
|
|
|
|
|
|
$cartItems[] = $cartItem;
|
2020-02-28 10:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// actually set the cart to the user's session
|
|
|
|
|
// when in an functional test:
|
2020-09-01 05:43:51 +00:00
|
|
|
$stub = new StdClass();
|
2020-02-28 10:41:48 +00:00
|
|
|
$stub->id = $cart->id;
|
|
|
|
|
$I->setSession(['cart' => $stub]);
|
|
|
|
|
|
|
|
|
|
return [
|
2020-03-03 10:18:18 +00:00
|
|
|
'cart' => $cart,
|
|
|
|
|
'product' => $product,
|
|
|
|
|
'customer' => $customer,
|
|
|
|
|
'cartAddress' => $cartAddress,
|
|
|
|
|
'cartItems' => $cartItems,
|
|
|
|
|
'totalQtyOrdered' => $totalQtyOrdered,
|
2020-02-28 10:41:48 +00:00
|
|
|
];
|
2020-03-18 13:34:27 +00:00
|
|
|
}
|
2020-02-28 10:41:48 +00:00
|
|
|
|
2020-03-18 13:34:27 +00:00
|
|
|
/**
|
|
|
|
|
* Set all session with the given key and value in the array.
|
|
|
|
|
*
|
|
|
|
|
* @param array $keyValue
|
|
|
|
|
*/
|
2020-03-30 13:03:27 +00:00
|
|
|
public function setSession(array $keyValue): void
|
2020-03-18 13:34:27 +00:00
|
|
|
{
|
|
|
|
|
session($keyValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Flush the session data and regenerate the ID
|
|
|
|
|
* A logged in user will be logged off.
|
|
|
|
|
*/
|
2020-03-30 13:03:27 +00:00
|
|
|
public function invalidateSession(): void
|
2020-03-18 13:34:27 +00:00
|
|
|
{
|
|
|
|
|
session()->invalidate();
|
2020-02-28 10:41:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-01-17 13:42:47 +00:00
|
|
|
/**
|
2020-03-18 13:34:27 +00:00
|
|
|
* Helper function to generate products for testing.
|
2020-01-28 14:38:07 +00:00
|
|
|
*
|
2020-03-18 13:34:27 +00:00
|
|
|
* By default, the product will be generated as saleable, this means it has a price,
|
|
|
|
|
* weight, is active and has a positive inventory stock, if necessary.
|
|
|
|
|
*
|
|
|
|
|
* @param int $productType see constants in this class for usage
|
2020-01-28 14:38:07 +00:00
|
|
|
* @param array $configs
|
|
|
|
|
* @param array $productStates
|
2020-01-17 13:42:47 +00:00
|
|
|
*
|
|
|
|
|
* @return \Webkul\Product\Models\Product
|
2020-02-05 10:18:21 +00:00
|
|
|
* @part ORM
|
2020-01-17 13:42:47 +00:00
|
|
|
*/
|
2020-03-18 13:34:27 +00:00
|
|
|
public function haveProduct(int $productType, array $configs = [], array $productStates = []): Product
|
2020-01-28 14:38:07 +00:00
|
|
|
{
|
2020-01-17 13:42:47 +00:00
|
|
|
$I = $this;
|
2020-01-28 14:38:07 +00:00
|
|
|
|
|
|
|
|
switch ($productType) {
|
2020-07-31 06:24:54 +00:00
|
|
|
case self::BOOKING_EVENT_PRODUCT:
|
|
|
|
|
$product = $I->haveBookingEventProduct($configs, $productStates);
|
|
|
|
|
break;
|
|
|
|
|
|
2020-01-28 14:38:07 +00:00
|
|
|
case self::DOWNLOADABLE_PRODUCT:
|
|
|
|
|
$product = $I->haveDownloadableProduct($configs, $productStates);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case self::VIRTUAL_PRODUCT:
|
|
|
|
|
$product = $I->haveVirtualProduct($configs, $productStates);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case self::SIMPLE_PRODUCT:
|
|
|
|
|
default:
|
|
|
|
|
$product = $I->haveSimpleProduct($configs, $productStates);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($product !== null) {
|
|
|
|
|
Event::dispatch('catalog.product.create.after', $product);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $product;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 13:34:27 +00:00
|
|
|
private function haveSimpleProduct(array $configs = [], array $productStates = []): Product
|
2020-01-28 14:38:07 +00:00
|
|
|
{
|
|
|
|
|
$I = $this;
|
2020-03-02 07:24:51 +00:00
|
|
|
if (! in_array('simple', $productStates)) {
|
2020-01-28 14:38:07 +00:00
|
|
|
$productStates = array_merge($productStates, ['simple']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$product = $I->createProduct($configs['productAttributes'] ?? [], $productStates);
|
|
|
|
|
|
2020-08-27 11:14:31 +00:00
|
|
|
$I->createAttributeValues($product, $configs['attributeValues'] ?? []);
|
2020-01-28 14:38:07 +00:00
|
|
|
|
2020-03-31 12:50:54 +00:00
|
|
|
$I->createInventory($product->id, $configs['productInventory'] ?? []);
|
2020-03-31 12:40:40 +00:00
|
|
|
|
2020-01-28 14:38:07 +00:00
|
|
|
return $product->refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function haveVirtualProduct(array $configs = [], array $productStates = []): Product
|
|
|
|
|
{
|
|
|
|
|
$I = $this;
|
2020-03-02 07:24:51 +00:00
|
|
|
if (! in_array('virtual', $productStates)) {
|
2020-01-28 14:38:07 +00:00
|
|
|
$productStates = array_merge($productStates, ['virtual']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$product = $I->createProduct($configs['productAttributes'] ?? [], $productStates);
|
|
|
|
|
|
2020-08-27 11:14:31 +00:00
|
|
|
$I->createAttributeValues($product, $configs['attributeValues'] ?? []);
|
2020-01-28 14:38:07 +00:00
|
|
|
|
2020-03-31 12:50:54 +00:00
|
|
|
$I->createInventory($product->id, $configs['productInventory'] ?? []);
|
2020-03-31 12:40:40 +00:00
|
|
|
|
2020-01-28 14:38:07 +00:00
|
|
|
return $product->refresh();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function haveDownloadableProduct(array $configs = [], array $productStates = []): Product
|
|
|
|
|
{
|
|
|
|
|
$I = $this;
|
2020-03-02 07:24:51 +00:00
|
|
|
if (! in_array('downloadable', $productStates)) {
|
2020-01-28 14:38:07 +00:00
|
|
|
$productStates = array_merge($productStates, ['downloadable']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$product = $I->createProduct($configs['productAttributes'] ?? [], $productStates);
|
|
|
|
|
|
2020-08-27 11:14:31 +00:00
|
|
|
$I->createAttributeValues($product, $configs['attributeValues'] ?? []);
|
2020-01-28 14:38:07 +00:00
|
|
|
|
|
|
|
|
$I->createDownloadableLink($product->id);
|
|
|
|
|
|
|
|
|
|
return $product->refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 06:24:54 +00:00
|
|
|
private function haveBookingEventProduct(array $configs = [], array $productStates = []): Product
|
|
|
|
|
{
|
|
|
|
|
$I = $this;
|
|
|
|
|
if (! in_array('booking', $productStates)) {
|
|
|
|
|
$productStates = array_merge($productStates, ['booking']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$product = $I->createProduct($configs['productAttributes'] ?? [], $productStates);
|
|
|
|
|
|
2020-08-27 11:14:31 +00:00
|
|
|
$I->createAttributeValues($product, $configs['attributeValues'] ?? []);
|
2020-07-31 06:24:54 +00:00
|
|
|
|
|
|
|
|
$I->createBookingEventProduct($product->id);
|
|
|
|
|
|
|
|
|
|
return $product->refresh();
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 14:38:07 +00:00
|
|
|
private function createProduct(array $attributes = [], array $states = []): Product
|
|
|
|
|
{
|
|
|
|
|
return factory(Product::class)->states($states)->create($attributes);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-31 12:40:40 +00:00
|
|
|
private function createInventory(int $productId, array $inventoryConfig = []): void
|
|
|
|
|
{
|
|
|
|
|
$I = $this;
|
|
|
|
|
$I->have(ProductInventory::class, array_merge($inventoryConfig, [
|
|
|
|
|
'product_id' => $productId,
|
|
|
|
|
'inventory_source_id' => 1,
|
|
|
|
|
]));
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-28 14:38:07 +00:00
|
|
|
private function createDownloadableLink(int $productId): void
|
|
|
|
|
{
|
|
|
|
|
$I = $this;
|
|
|
|
|
$link = $I->have(ProductDownloadableLink::class, [
|
|
|
|
|
'product_id' => $productId,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$I->have(ProductDownloadableLinkTranslation::class, [
|
|
|
|
|
'product_downloadable_link_id' => $link->id,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 06:24:54 +00:00
|
|
|
private function createBookingEventProduct(int $productId): void
|
|
|
|
|
{
|
|
|
|
|
$I = $this;
|
|
|
|
|
$bookingProduct = $I->have(BookingProduct::class, [
|
|
|
|
|
'product_id' => $productId,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$I->have(BookingProductEventTicket::class, [
|
|
|
|
|
'booking_product_id' => $bookingProduct->id,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-27 11:14:31 +00:00
|
|
|
private function createAttributeValues(Product $product, array $attributeValues = []): void
|
2020-01-17 13:42:47 +00:00
|
|
|
{
|
|
|
|
|
$I = $this;
|
2020-03-06 14:50:26 +00:00
|
|
|
|
2020-03-18 13:34:27 +00:00
|
|
|
$faker = Factory::create();
|
|
|
|
|
|
2020-03-30 13:03:27 +00:00
|
|
|
$brand = Attribute::query()
|
|
|
|
|
->where(['code' => 'brand'])
|
2020-08-27 11:14:31 +00:00
|
|
|
->firstOrFail(); // usually 25
|
2020-03-18 13:34:27 +00:00
|
|
|
|
2020-03-30 13:03:27 +00:00
|
|
|
if (! AttributeOption::query()
|
|
|
|
|
->where(['attribute_id' => $brand->id])
|
|
|
|
|
->exists()) {
|
2020-03-18 13:34:27 +00:00
|
|
|
AttributeOption::create([
|
|
|
|
|
'admin_name' => 'Webkul Demo Brand (c) 2020',
|
|
|
|
|
'attribute_id' => $brand->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 06:24:54 +00:00
|
|
|
/**
|
2020-03-18 13:34:27 +00:00
|
|
|
* Some defaults that should apply to all generated products.
|
|
|
|
|
* By defaults products will be generated as saleable.
|
|
|
|
|
* If you do not want this, this defaults can be overriden by $attributeValues.
|
|
|
|
|
*/
|
|
|
|
|
$defaultAttributeValues = [
|
2020-08-27 11:14:31 +00:00
|
|
|
'name' => $faker->words(3, true),
|
2020-03-18 13:34:27 +00:00
|
|
|
'description' => $faker->sentence,
|
|
|
|
|
'short_description' => $faker->sentence,
|
2020-08-27 11:14:31 +00:00
|
|
|
'sku' => $product->sku,
|
2020-03-18 13:34:27 +00:00
|
|
|
'url_key' => $faker->slug,
|
|
|
|
|
'status' => true,
|
2020-03-31 13:10:18 +00:00
|
|
|
'guest_checkout' => true,
|
2020-03-18 13:34:27 +00:00
|
|
|
'visible_individually' => true,
|
|
|
|
|
'special_price_from' => null,
|
|
|
|
|
'special_price_to' => null,
|
|
|
|
|
'special_price' => null,
|
2020-05-01 09:18:56 +00:00
|
|
|
'price' => $faker->randomFloat(2, 1, 1000),
|
2020-03-18 13:34:27 +00:00
|
|
|
'weight' => '1.00', // necessary for shipping
|
2020-07-31 06:24:54 +00:00
|
|
|
'brand' => AttributeOption::query()->firstWhere('attribute_id', $brand->id)->id,
|
2020-01-17 13:42:47 +00:00
|
|
|
];
|
2020-02-19 12:26:12 +00:00
|
|
|
|
2020-03-18 13:34:27 +00:00
|
|
|
$attributeValues = array_merge($defaultAttributeValues, $attributeValues);
|
2020-02-19 12:26:12 +00:00
|
|
|
|
2020-03-18 13:34:27 +00:00
|
|
|
/** @var array $possibleAttributeValues list of the possible attributes a product can have */
|
2020-03-30 13:03:27 +00:00
|
|
|
$possibleAttributeValues = DB::table('attributes')
|
|
|
|
|
->select('id', 'code', 'type')
|
|
|
|
|
->get()
|
|
|
|
|
->toArray();
|
2020-03-18 13:34:27 +00:00
|
|
|
|
2020-03-31 12:35:01 +00:00
|
|
|
foreach ($possibleAttributeValues as $attributeSet) {
|
2020-03-18 13:34:27 +00:00
|
|
|
$data = [
|
2020-08-27 11:14:31 +00:00
|
|
|
'product_id' => $product->id,
|
2020-03-31 12:35:01 +00:00
|
|
|
'attribute_id' => $attributeSet->id,
|
2020-03-18 13:34:27 +00:00
|
|
|
];
|
|
|
|
|
|
2020-03-31 12:35:01 +00:00
|
|
|
$fieldName = self::getAttributeFieldName($attributeSet->type);
|
2020-03-18 13:34:27 +00:00
|
|
|
|
2020-03-31 12:35:01 +00:00
|
|
|
$data[$fieldName] = $attributeValues[$attributeSet->code] ?? null;
|
2020-03-18 13:34:27 +00:00
|
|
|
|
2020-08-27 11:14:31 +00:00
|
|
|
$data = $this->appendAttributeDependencies($attributeSet->code, $data);
|
|
|
|
|
|
2020-03-18 13:34:27 +00:00
|
|
|
$I->have(ProductAttributeValue::class, $data);
|
2020-01-17 13:42:47 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-08-27 11:14:31 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|