Improved product package code style

This commit is contained in:
Jitendra Singh 2020-02-20 11:42:17 +05:30
parent c81c46f9d6
commit aa1d6d145c
40 changed files with 411 additions and 295 deletions

View File

@ -144,10 +144,11 @@ class Ipn
*/
protected function postBack()
{
if (array_key_exists('test_ipn', $this->post) && 1 === (int) $this->post['test_ipn'])
if (array_key_exists('test_ipn', $this->post) && 1 === (int) $this->post['test_ipn']) {
$url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
else
} else {
$url = 'https://www.paypal.com/cgi-bin/webscr';
}
// Set up request to PayPal
$request = curl_init();

View File

@ -39,7 +39,6 @@ abstract class Paypal extends Payment
$cartItems = $this->getCartItems();
foreach ($cartItems as $item) {
foreach ($this->itemFieldsFormat as $modelField => $paypalField) {
$fields[sprintf($paypalField, $i)] = $item->{$modelField};
}

View File

@ -52,9 +52,9 @@ return array(
*/
'templates' => array(
'small' => 'Webkul\Product\CacheFilters\Small',
'small' => 'Webkul\Product\CacheFilters\Small',
'medium' => 'Webkul\Product\CacheFilters\Medium',
'large' => 'Webkul\Product\CacheFilters\Large',
'large' => 'Webkul\Product\CacheFilters\Large',
),
/*

View File

@ -1,40 +1,45 @@
<?php
return [
'simple' => [
'key' => 'simple',
'name' => 'Simple',
'simple' => [
'key' => 'simple',
'name' => 'Simple',
'class' => 'Webkul\Product\Type\Simple',
'sort' => 1
'sort' => 1
],
'configurable' => [
'key' => 'configurable',
'name' => 'Configurable',
'key' => 'configurable',
'name' => 'Configurable',
'class' => 'Webkul\Product\Type\Configurable',
'sort' => 2
'sort' => 2
],
'virtual' => [
'key' => 'virtual',
'name' => 'Virtual',
'virtual' => [
'key' => 'virtual',
'name' => 'Virtual',
'class' => 'Webkul\Product\Type\Virtual',
'sort' => 3
'sort' => 3
],
'grouped' => [
'key' => 'grouped',
'name' => 'Grouped',
'grouped' => [
'key' => 'grouped',
'name' => 'Grouped',
'class' => 'Webkul\Product\Type\Grouped',
'sort' => 4
'sort' => 4
],
'downloadable' => [
'key' => 'downloadable',
'name' => 'Downloadable',
'key' => 'downloadable',
'name' => 'Downloadable',
'class' => 'Webkul\Product\Type\Downloadable',
'sort' => 5
'sort' => 5
],
'bundle' => [
'key' => 'bundle',
'name' => 'Bundle',
'bundle' => [
'key' => 'bundle',
'name' => 'Bundle',
'class' => 'Webkul\Product\Type\Bundle',
'sort' => 6
'sort' => 6
]
];

View File

@ -32,7 +32,7 @@ class Builder extends BaseBuilder
: $this->model->newCollection();
return $this->paginator($results, $total, $perPage, $page, [
'path' => Paginator::resolveCurrentPath(),
'path' => Paginator::resolveCurrentPath(),
'pageName' => $pageName,
]);
}

View File

@ -16,6 +16,7 @@ $factory->defineAs(ProductAttributeValue::class, 'sku', function (Faker $faker)
'attribute_id' => 1,
];
});
$factory->defineAs(ProductAttributeValue::class, 'name', function (Faker $faker) {
return [
'product_id' => function () {
@ -27,6 +28,7 @@ $factory->defineAs(ProductAttributeValue::class, 'name', function (Faker $faker)
'attribute_id' => 2,
];
});
$factory->defineAs(ProductAttributeValue::class, 'url_key', function (Faker $faker) {
return [
'product_id' => function () {
@ -36,6 +38,7 @@ $factory->defineAs(ProductAttributeValue::class, 'url_key', function (Faker $fak
'attribute_id' => 3,
];
});
$factory->defineAs(ProductAttributeValue::class, 'tax_category_id', function (Faker $faker) {
return [
'product_id' => function () {
@ -46,6 +49,7 @@ $factory->defineAs(ProductAttributeValue::class, 'tax_category_id', function (Fa
'attribute_id' => 4,
];
});
$factory->defineAs(ProductAttributeValue::class, 'new', function (Faker $faker) {
return [
'product_id' => function () {
@ -55,6 +59,7 @@ $factory->defineAs(ProductAttributeValue::class, 'new', function (Faker $faker)
'attribute_id' => 5,
];
});
$factory->defineAs(ProductAttributeValue::class, 'featured', function (Faker $faker) {
return [
'product_id' => function () {
@ -64,6 +69,7 @@ $factory->defineAs(ProductAttributeValue::class, 'featured', function (Faker $fa
'attribute_id' => 6,
];
});
$factory->defineAs(ProductAttributeValue::class, 'visible_individually', function (Faker $faker) {
return [
'product_id' => function () {
@ -73,6 +79,7 @@ $factory->defineAs(ProductAttributeValue::class, 'visible_individually', functio
'attribute_id' => 7,
];
});
$factory->defineAs(ProductAttributeValue::class, 'status', function (Faker $faker) {
return [
'product_id' => function () {
@ -82,6 +89,7 @@ $factory->defineAs(ProductAttributeValue::class, 'status', function (Faker $fake
'attribute_id' => 8,
];
});
$factory->defineAs(ProductAttributeValue::class, 'short_description', function (Faker $faker) {
return [
'product_id' => function () {
@ -93,6 +101,7 @@ $factory->defineAs(ProductAttributeValue::class, 'short_description', function (
'attribute_id' => 9,
];
});
$factory->defineAs(ProductAttributeValue::class, 'description', function (Faker $faker) {
return [
'product_id' => function () {
@ -104,6 +113,7 @@ $factory->defineAs(ProductAttributeValue::class, 'description', function (Faker
'attribute_id' => 10,
];
});
$factory->defineAs(ProductAttributeValue::class, 'price', function (Faker $faker) {
return [
'product_id' => function () {
@ -113,6 +123,7 @@ $factory->defineAs(ProductAttributeValue::class, 'price', function (Faker $faker
'attribute_id' => 11,
];
});
$factory->defineAs(ProductAttributeValue::class, 'cost', function (Faker $faker) {
return [
'product_id' => function () {
@ -123,6 +134,7 @@ $factory->defineAs(ProductAttributeValue::class, 'cost', function (Faker $faker)
'attribute_id' => 12,
];
});
$factory->defineAs(ProductAttributeValue::class, 'special_price', function (Faker $faker) {
return [
'product_id' => function () {
@ -132,6 +144,7 @@ $factory->defineAs(ProductAttributeValue::class, 'special_price', function (Fake
'attribute_id' => 13,
];
});
$factory->defineAs(ProductAttributeValue::class, 'special_price_from', function (Faker $faker) {
return [
'product_id' => function () {
@ -142,6 +155,7 @@ $factory->defineAs(ProductAttributeValue::class, 'special_price_from', function
'attribute_id' => 14,
];
});
$factory->defineAs(ProductAttributeValue::class, 'special_price_to', function (Faker $faker) {
return [
'product_id' => function () {
@ -152,6 +166,7 @@ $factory->defineAs(ProductAttributeValue::class, 'special_price_to', function (F
'attribute_id' => 15,
];
});
$factory->defineAs(ProductAttributeValue::class, 'meta_title', function (Faker $faker) {
return [
'product_id' => function () {
@ -163,6 +178,7 @@ $factory->defineAs(ProductAttributeValue::class, 'meta_title', function (Faker $
'attribute_id' => 16,
];
});
$factory->defineAs(ProductAttributeValue::class, 'meta_keywords', function (Faker $faker) {
return [
'product_id' => function () {
@ -174,6 +190,7 @@ $factory->defineAs(ProductAttributeValue::class, 'meta_keywords', function (Fake
'attribute_id' => 17,
];
});
$factory->defineAs(ProductAttributeValue::class, 'meta_description', function (Faker $faker) {
return [
'product_id' => function () {
@ -185,6 +202,7 @@ $factory->defineAs(ProductAttributeValue::class, 'meta_description', function (F
'attribute_id' => 18,
];
});
$factory->defineAs(ProductAttributeValue::class, 'width', function (Faker $faker) {
return [
'product_id' => function () {
@ -194,6 +212,7 @@ $factory->defineAs(ProductAttributeValue::class, 'width', function (Faker $faker
'attribute_id' => 19,
];
});
$factory->defineAs(ProductAttributeValue::class, 'height', function (Faker $faker) {
return [
'product_id' => function () {
@ -203,6 +222,7 @@ $factory->defineAs(ProductAttributeValue::class, 'height', function (Faker $fake
'attribute_id' => 20,
];
});
$factory->defineAs(ProductAttributeValue::class, 'depth', function (Faker $faker) {
return [
'product_id' => function () {
@ -212,6 +232,7 @@ $factory->defineAs(ProductAttributeValue::class, 'depth', function (Faker $faker
'attribute_id' => 21,
];
});
$factory->defineAs(ProductAttributeValue::class, 'weight', function (Faker $faker) {
return [
'product_id' => function () {
@ -221,6 +242,7 @@ $factory->defineAs(ProductAttributeValue::class, 'weight', function (Faker $fake
'attribute_id' => 22,
];
});
$factory->defineAs(ProductAttributeValue::class, 'color', function (Faker $faker) {
return [
'product_id' => function () {
@ -230,6 +252,7 @@ $factory->defineAs(ProductAttributeValue::class, 'color', function (Faker $faker
'attribute_id' => 23,
];
});
$factory->defineAs(ProductAttributeValue::class, 'size', function (Faker $faker) {
return [
'product_id' => function () {
@ -239,6 +262,7 @@ $factory->defineAs(ProductAttributeValue::class, 'size', function (Faker $faker)
'attribute_id' => 24,
];
});
$factory->defineAs(ProductAttributeValue::class, 'brand', function (Faker $faker) {
return [
'product_id' => function () {
@ -250,6 +274,7 @@ $factory->defineAs(ProductAttributeValue::class, 'brand', function (Faker $faker
},
];
});
$factory->defineAs(ProductAttributeValue::class, 'guest_checkout', function ( Faker $faker) {
return [
'product_id' => function() {

View File

@ -11,6 +11,7 @@ $factory->define(ProductDownloadableLink::class, function (Faker $faker) {
$now = date("Y-m-d H:i:s");
$filename = 'ProductImageExampleForUpload.jpg';
$filepath = '/tests/_data/';
return [
'url' => '',
'file' => $filepath . $filename,

View File

@ -8,8 +8,8 @@ use Webkul\Product\Models\ProductDownloadableLinkTranslation;
$factory->define(ProductDownloadableLinkTranslation::class, function (Faker $faker) {
return [
'locale' => 'en',
'title' => $faker->word,
'locale' => 'en',
'title' => $faker->word,
'product_downloadable_link_id' => function () {
return factory(ProductDownloadableLink::class)->create()->id;
},

View File

@ -7,6 +7,7 @@ use Webkul\Product\Models\Product;
$factory->define(Product::class, function (Faker $faker) {
$now = date("Y-m-d H:i:s");
return [
'sku' => $faker->uuid,
'created_at' => $now,

View File

@ -6,7 +6,7 @@ use Faker\Generator as Faker;
use Webkul\Product\Models\ProductReview;
$factory->define(ProductReview::class, function (Faker $faker, array $attributes) {
if (!array_key_exists('product_id', $attributes)) {
if (! array_key_exists('product_id', $attributes)) {
throw new InvalidArgumentException('product_id must be provided. You may use $I->haveProduct() to generate a product');
}

View File

@ -59,8 +59,9 @@ abstract class AbstractProduct
*/
public function setProductFlat($product)
{
if (array_key_exists($product->id, $this->productFlat))
if (array_key_exists($product->id, $this->productFlat)) {
return;
}
if (! $product instanceof ProductFlat) {
$this->productFlat[$product->id] = ProductFlatProxy::modelClass()

View File

@ -65,12 +65,12 @@ class BundleOption extends AbstractProduct
private function getOptionItemData($option)
{
return [
'id' => $option->id,
'label' => $option->label,
'type' => $option->type,
'id' => $option->id,
'label' => $option->label,
'type' => $option->type,
'is_required' => $option->is_required,
'products' => $this->getOptionProducts($option),
'sort_order' => $option->sort_order
'products' => $this->getOptionProducts($option),
'sort_order' => $option->sort_order
];
}
@ -86,10 +86,10 @@ class BundleOption extends AbstractProduct
foreach ($option->bundle_option_products as $index => $bundleOptionProduct) {
$products[$bundleOptionProduct->id] = [
'id' => $bundleOptionProduct->id,
'qty' => $bundleOptionProduct->qty,
'price' => $bundleOptionProduct->product->getTypeInstance()->getProductPrices(),
'name' => $bundleOptionProduct->product->name,
'id' => $bundleOptionProduct->id,
'qty' => $bundleOptionProduct->qty,
'price' => $bundleOptionProduct->product->getTypeInstance()->getProductPrices(),
'name' => $bundleOptionProduct->product->name,
'product_id' => $bundleOptionProduct->product_id,
'is_default' => $bundleOptionProduct->is_default,
'sort_order' => $bundleOptionProduct->sort_order

View File

@ -55,8 +55,9 @@ class ConfigurableOption extends AbstractProduct
{
static $variants = [];
if (count($variants))
if (count($variants)) {
return $variants;
}
foreach ($product->variants as $variant) {
if ($variant->isSaleable()) {
@ -78,15 +79,15 @@ class ConfigurableOption extends AbstractProduct
$options = $this->getOptions($product, $this->getAllowedProducts($product));
$config = [
'attributes' => $this->getAttributesData($product, $options),
'index' => isset($options['index']) ? $options['index'] : [],
'regular_price' => [
'attributes' => $this->getAttributesData($product, $options),
'index' => isset($options['index']) ? $options['index'] : [],
'regular_price' => [
'formated_price' => core()->currency($product->getTypeInstance()->getMinimalPrice()),
'price' => $product->getTypeInstance()->getMinimalPrice()
'price' => $product->getTypeInstance()->getMinimalPrice()
],
'variant_prices' => $this->getVariantPrices($product),
'variant_images' => $this->getVariantImages($product),
'chooseText' => trans('shop::app.products.choose-option')
'chooseText' => trans('shop::app.products.choose-option')
];
return $config;
@ -128,8 +129,9 @@ class ConfigurableOption extends AbstractProduct
$attributeValue = $product->{$productAttribute->code};
if ($attributeValue == '' && $product instanceof \Webkul\Product\Models\ProductFlat)
if ($attributeValue == '' && $product instanceof \Webkul\Product\Models\ProductFlat) {
$attributeValue = $product->product->{$productAttribute->code};
}
$options[$productAttributeId][$attributeValue][] = $productId;
@ -163,11 +165,11 @@ class ConfigurableOption extends AbstractProduct
$attributeId = $attribute->id;
$attributes[] = [
'id' => $attributeId,
'code' => $attribute->code,
'label' => $attribute->name ? $attribute->name : $attribute->admin_name,
'id' => $attributeId,
'code' => $attribute->code,
'label' => $attribute->name ? $attribute->name : $attribute->admin_name,
'swatch_type' => $attribute->swatch_type,
'options' => $attributeOptionsData
'options' => $attributeOptionsData
];
}
}
@ -190,10 +192,10 @@ class ConfigurableOption extends AbstractProduct
if (isset($options[$attribute->id][$optionId])) {
$attributeOptionsData[] = [
'id' => $optionId,
'label' => $attributeOption->label ? $attributeOption->label : $attributeOption->admin_name,
'id' => $optionId,
'label' => $attributeOption->label ? $attributeOption->label : $attributeOption->admin_name,
'swatch_value' => $attribute->swatch_type == 'image' ? $attributeOption->swatch_value_url : $attributeOption->swatch_value,
'products' => $options[$attribute->id][$optionId]
'products' => $options[$attribute->id][$optionId]
];
}
}

View File

@ -21,8 +21,9 @@ class ProductImage extends AbstractProduct
*/
public function getGalleryImages($product)
{
if (! $product)
if (! $product) {
return [];
}
$images = [];
@ -31,18 +32,18 @@ class ProductImage extends AbstractProduct
continue;
$images[] = [
'small_image_url' => url('cache/small/' . $image->path),
'medium_image_url' => url('cache/medium/' . $image->path),
'large_image_url' => url('cache/large/' . $image->path),
'small_image_url' => url('cache/small/' . $image->path),
'medium_image_url' => url('cache/medium/' . $image->path),
'large_image_url' => url('cache/large/' . $image->path),
'original_image_url' => url('cache/original/' . $image->path),
];
}
if (! $product->parent_id && ! count($images)) {
$images[] = [
'small_image_url' => asset('vendor/webkul/ui/assets/images/product/small-product-placeholder.png'),
'medium_image_url' => asset('vendor/webkul/ui/assets/images/product/meduim-product-placeholder.png'),
'large_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.png'),
'small_image_url' => asset('vendor/webkul/ui/assets/images/product/small-product-placeholder.png'),
'medium_image_url' => asset('vendor/webkul/ui/assets/images/product/meduim-product-placeholder.png'),
'large_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.png'),
'original_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.png')
];
}
@ -62,16 +63,16 @@ class ProductImage extends AbstractProduct
if ($images && $images->count()) {
$image = [
'small_image_url' => url('cache/small/' . $images[0]->path),
'medium_image_url' => url('cache/medium/' . $images[0]->path),
'large_image_url' => url('cache/large/' . $images[0]->path),
'small_image_url' => url('cache/small/' . $images[0]->path),
'medium_image_url' => url('cache/medium/' . $images[0]->path),
'large_image_url' => url('cache/large/' . $images[0]->path),
'original_image_url' => url('cache/original/' . $images[0]->path),
];
} else {
$image = [
'small_image_url' => asset('vendor/webkul/ui/assets/images/product/small-product-placeholder.png'),
'medium_image_url' => asset('vendor/webkul/ui/assets/images/product/meduim-product-placeholder.png'),
'large_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.png'),
'small_image_url' => asset('vendor/webkul/ui/assets/images/product/small-product-placeholder.png'),
'medium_image_url' => asset('vendor/webkul/ui/assets/images/product/meduim-product-placeholder.png'),
'large_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.png'),
'original_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.png'),
];
}

View File

@ -29,6 +29,7 @@ class ProductType extends AbstractProduct
public static function getAllTypesHavingVariants(): array
{
$havingVariants = [];
foreach (config('product_types') as $type) {
if (self::hasVariants($type['key'])) {
array_push($havingVariants, $type['key']);

View File

@ -21,8 +21,9 @@ class Review extends AbstractProduct
{
static $reviews = [];
if(array_key_exists($product->id, $reviews))
if (array_key_exists($product->id, $reviews)) {
return $reviews[$product->id];
}
return $reviews[$product->id] = $product->reviews()->where('status', 'approved');
}
@ -37,8 +38,9 @@ class Review extends AbstractProduct
{
static $avgRating = [];
if(array_key_exists($product->id, $avgRating))
if (array_key_exists($product->id, $avgRating)) {
return $avgRating[$product->id];
}
return $avgRating[$product->id] = number_format(round($product->reviews()->where('status', 'approved')->avg('rating'), 2), 1);
}
@ -53,8 +55,9 @@ class Review extends AbstractProduct
{
static $totalReviews = [];
if(array_key_exists($product->id, $totalReviews))
if (array_key_exists($product->id, $totalReviews)) {
return $totalReviews[$product->id];
}
return $totalReviews[$product->id] = $product->reviews()->where('status', 'approved')->count();
}
@ -69,8 +72,9 @@ class Review extends AbstractProduct
{
static $totalRating = [];
if(array_key_exists($product->id, $totalRating))
if (array_key_exists($product->id, $totalRating)) {
return $totalRating[$product->id];
}
return $totalRating[$product->id] = $product->reviews()->where('status','approved')->sum('rating');
}

View File

@ -19,12 +19,12 @@ class Toolbar extends AbstractProduct
public function getAvailableOrders()
{
return [
'name-asc' => 'from-a-z',
'name-desc' => 'from-z-a',
'name-asc' => 'from-a-z',
'name-desc' => 'from-z-a',
'created_at-desc' => 'newest-first',
'created_at-asc' => 'oldest-first',
'price-asc' => 'cheapest-first',
'price-desc' => 'expensive-first'
'created_at-asc' => 'oldest-first',
'price-asc' => 'cheapest-first',
'price-desc' => 'expensive-first'
];
}
/**
@ -49,7 +49,7 @@ class Toolbar extends AbstractProduct
$keys = explode('-', $key);
return request()->fullUrlWithQuery([
'sort' => current($keys),
'sort' => current($keys),
'order' => end($keys)
]);
}
@ -90,10 +90,11 @@ class Toolbar extends AbstractProduct
{
$params = request()->input();
if (isset($params['sort']) && $key == $params['sort'] . '-' . $params['order'])
if (isset($params['sort']) && $key == $params['sort'] . '-' . $params['order']) {
return true;
else if (! isset($params['sort']) && $key == 'created_at-desc')
} else if (! isset($params['sort']) && $key == 'created_at-desc') {
return true;
}
return false;
}
@ -108,8 +109,9 @@ class Toolbar extends AbstractProduct
{
$params = request()->input();
if (isset($params['limit']) && $limit == $params['limit'])
if (isset($params['limit']) && $limit == $params['limit']) {
return true;
}
return false;
}
@ -124,8 +126,9 @@ class Toolbar extends AbstractProduct
{
$params = request()->input();
if (isset($params['mode']) && $key == $params['mode'])
if (isset($params['mode']) && $key == $params['mode']) {
return true;
}
return false;
}
@ -140,8 +143,9 @@ class Toolbar extends AbstractProduct
{
$params = request()->input();
if (isset($params['mode']))
if (isset($params['mode'])) {
return $params['mode'];
}
return 'grid';
}

View File

@ -60,12 +60,12 @@ class View extends AbstractProduct
}
$data[] = [
'id' => $attribute->id,
'code' => $attribute->code,
'label' => $attribute->name,
'value' => $value,
'id' => $attribute->id,
'code' => $attribute->code,
'label' => $attribute->name,
'value' => $value,
'admin_name' => $attribute->admin_name,
'type' => $attribute->type,
'type' => $attribute->type,
];
}

View File

@ -157,9 +157,9 @@ class ProductController extends Controller
}
$this->validate(request(), [
'type' => 'required',
'type' => 'required',
'attribute_family_id' => 'required',
'sku' => ['required', 'unique:products,sku', new \Webkul\Core\Contracts\Validations\Slug]
'sku' => ['required', 'unique:products,sku', new \Webkul\Core\Contracts\Validations\Slug]
]);
$product = $this->productRepository->create(request()->all());
@ -287,7 +287,7 @@ class ProductController extends Controller
return redirect()->back();
}
if (!$data['massaction-type'] == 'update') {
if (! $data['massaction-type'] == 'update') {
return redirect()->back();
}
@ -296,8 +296,8 @@ class ProductController extends Controller
foreach ($productIds as $productId) {
$this->productRepository->update([
'channel' => null,
'locale' => null,
'status' => $data['update-options']
'locale' => null,
'status' => $data['update-options']
], $productId);
}
@ -328,8 +328,8 @@ class ProductController extends Controller
foreach ($this->productRepository->searchProductByAttribute(request()->input('query')) as $row) {
$results[] = [
'id' => $row->product_id,
'sku' => $row->sku,
'id' => $row->product_id,
'sku' => $row->sku,
'name' => $row->name,
];
}

View File

@ -71,23 +71,25 @@ class ProductForm extends FormRequest
$product = $this->product->find($this->id);
$this->rules = array_merge($product->getTypeInstance()->getTypeValidationRules(), [
'sku' => ['required', 'unique:products,sku,' . $this->id, new \Webkul\Core\Contracts\Validations\Slug],
'images.*' => 'mimes:jpeg,jpg,bmp,png',
'sku' => ['required', 'unique:products,sku,' . $this->id, new \Webkul\Core\Contracts\Validations\Slug],
'images.*' => 'mimes:jpeg,jpg,bmp,png',
'special_price_from' => 'nullable|date',
'special_price_to' => 'nullable|date|after_or_equal:special_price_from',
'special_price' => ['nullable', new \Webkul\Core\Contracts\Validations\Decimal, 'lt:price']
'special_price_to' => 'nullable|date|after_or_equal:special_price_from',
'special_price' => ['nullable', new \Webkul\Core\Contracts\Validations\Decimal, 'lt:price']
]);
foreach ($product->getEditableAttributes() as $attribute) {
if ($attribute->code == 'sku' || $attribute->type == 'boolean')
if ($attribute->code == 'sku' || $attribute->type == 'boolean') {
continue;
}
$validations = [];
if (! isset($this->rules[$attribute->code]))
if (! isset($this->rules[$attribute->code])) {
array_push($validations, $attribute->is_required ? 'required' : 'nullable');
else
} else {
$validations = $this->rules[$attribute->code];
}
if ($attribute->type == 'text' && $attribute->validation) {
array_push($validations,
@ -97,15 +99,17 @@ class ProductForm extends FormRequest
);
}
if ($attribute->type == 'price')
if ($attribute->type == 'price') {
array_push($validations, new \Webkul\Core\Contracts\Validations\Decimal);
}
if ($attribute->is_unique) {
array_push($validations, function ($field, $value, $fail) use ($attribute) {
$column = ProductAttributeValue::$attributeTypeFields[$attribute->type];
if (! $this->attributeValue->isValueUnique($this->id, $attribute->id, $column, request($attribute->code)))
if (! $this->attributeValue->isValueUnique($this->id, $attribute->id, $column, request($attribute->code))) {
$fail('The :attribute has already been taken.');
}
});
}

View File

@ -59,17 +59,17 @@ class ProductFlat
* @var object
*/
public $attributeTypeFields = [
'text' => 'text',
'textarea' => 'text',
'price' => 'float',
'boolean' => 'boolean',
'select' => 'integer',
'text' => 'text',
'textarea' => 'text',
'price' => 'float',
'boolean' => 'boolean',
'select' => 'integer',
'multiselect' => 'text',
'datetime' => 'datetime',
'date' => 'date',
'file' => 'text',
'image' => 'text',
'checkbox' => 'text'
'datetime' => 'datetime',
'date' => 'date',
'file' => 'text',
'image' => 'text',
'checkbox' => 'text'
];
/**
@ -169,11 +169,13 @@ class ProductFlat
static $superAttributes = [];
if (! array_key_exists($product->attribute_family->id, $familyAttributes))
if (! array_key_exists($product->attribute_family->id, $familyAttributes)) {
$familyAttributes[$product->attribute_family->id] = $product->attribute_family->custom_attributes;
}
if ($parentProduct && ! array_key_exists($parentProduct->id, $superAttributes))
if ($parentProduct && ! array_key_exists($parentProduct->id, $superAttributes)) {
$superAttributes[$parentProduct->id] = $parentProduct->super_attributes()->pluck('code')->toArray();
}
if (isset($product['channels'])) {
foreach ($product['channels'] as $channel) {
@ -194,27 +196,30 @@ class ProductFlat
foreach ($channel->locales as $locale) {
$productFlat = $this->productFlatRepository->findOneWhere([
'product_id' => $product->id,
'channel' => $channel->code,
'locale' => $locale->code
'channel' => $channel->code,
'locale' => $locale->code
]);
if (! $productFlat) {
$productFlat = $this->productFlatRepository->create([
'product_id' => $product->id,
'channel' => $channel->code,
'locale' => $locale->code
'channel' => $channel->code,
'locale' => $locale->code
]);
}
foreach ($familyAttributes[$product->attribute_family->id] as $attribute) {
if ($parentProduct && ! in_array($attribute->code, array_merge($superAttributes[$parentProduct->id], ['sku', 'name', 'price', 'weight', 'status'])))
if ($parentProduct && ! in_array($attribute->code, array_merge($superAttributes[$parentProduct->id], ['sku', 'name', 'price', 'weight', 'status']))) {
continue;
}
if (in_array($attribute->code, ['tax_category_id']))
if (in_array($attribute->code, ['tax_category_id'])) {
continue;
}
if (! Schema::hasColumn('product_flat', $attribute->code))
if (! Schema::hasColumn('product_flat', $attribute->code)) {
continue;
}
if ($attribute->value_per_channel) {
if ($attribute->value_per_locale) {
@ -274,12 +279,13 @@ class ProductFlat
if ($parentProduct) {
$parentProductFlat = $this->productFlatRepository->findOneWhere([
'product_id' => $parentProduct->id,
'channel' => $channel->code,
'locale' => $locale->code
'channel' => $channel->code,
'locale' => $locale->code
]);
if ($parentProductFlat)
if ($parentProductFlat) {
$productFlat->parent_id = $parentProductFlat->id;
}
}
$productFlat->save();
@ -290,7 +296,7 @@ class ProductFlat
if ($route == 'admin.catalog.products.update') {
$productFlat = $this->productFlatRepository->findOneWhere([
'product_id' => $product->id,
'channel' => $channel->code,
'channel' => $channel->code,
]);
if ($productFlat) {

View File

@ -192,8 +192,9 @@ class Product extends Model implements ProductContract
*/
public function getTypeInstance()
{
if ($this->typeInstance)
if ($this->typeInstance) {
return $this->typeInstance;
}
$this->typeInstance = app(config('product_types.' . $this->type . '.class'));
@ -306,8 +307,9 @@ class Product extends Model implements ProductContract
*/
public function getCustomAttributeValue($attribute)
{
if (! $attribute)
if (! $attribute) {
return;
}
$channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode());

View File

@ -15,17 +15,17 @@ class ProductAttributeValue extends Model implements ProductAttributeValueContra
* @var array
*/
public static $attributeTypeFields = [
'text' => 'text_value',
'textarea' => 'text_value',
'price' => 'float_value',
'boolean' => 'boolean_value',
'select' => 'integer_value',
'text' => 'text_value',
'textarea' => 'text_value',
'price' => 'float_value',
'boolean' => 'boolean_value',
'select' => 'integer_value',
'multiselect' => 'text_value',
'datetime' => 'datetime_value',
'date' => 'date_value',
'file' => 'text_value',
'image' => 'text_value',
'checkbox' => 'text_value',
'datetime' => 'datetime_value',
'date' => 'date_value',
'file' => 'text_value',
'image' => 'text_value',
'checkbox' => 'text_value',
];
protected $fillable = [

View File

@ -60,8 +60,9 @@ class ProductAttributeValueRepository extends Repository
$attribute = $this->attributeRepository->findOneByField('code', $data['attribute_code']);
}
if (! $attribute)
if (! $attribute) {
return;
}
$data[ProductAttributeValue::$attributeTypeFields[$attribute->type]] = $data['value'];

View File

@ -36,8 +36,9 @@ class ProductBundleOptionProductRepository extends Repository
'product_bundle_option_id' => $productBundleOption->id,
], $bundleOptionProductInputs));
} else {
if (is_numeric($index = $previousBundleOptionProductIds->search($bundleOptionProductId)))
if (is_numeric($index = $previousBundleOptionProductIds->search($bundleOptionProductId))) {
$previousBundleOptionProductIds->forget($index);
}
$this->update($bundleOptionProductInputs, $bundleOptionProductId);
}
@ -55,8 +56,9 @@ class ProductBundleOptionProductRepository extends Repository
*/
public function setIsDefaultFlag(&$data)
{
if (! count($data['products']))
if (! count($data['products'])) {
return;
}
$haveIsDefaulFlag = false;
@ -68,7 +70,8 @@ class ProductBundleOptionProductRepository extends Repository
}
}
if (! $haveIsDefaulFlag && $data['is_required'])
if (! $haveIsDefaulFlag && $data['is_required']) {
$data['products'][key($data['products'])]['is_default'] = 1;
}
}
}

View File

@ -60,8 +60,9 @@ class ProductBundleOptionRepository extends Repository
} else {
$productBundleOption = $this->find($bundleOptionId);
if (is_numeric($index = $previousBundleOptionIds->search($bundleOptionId)))
if (is_numeric($index = $previousBundleOptionIds->search($bundleOptionId))) {
$previousBundleOptionIds->forget($index);
}
$this->update($bundleOptionInputs, $bundleOptionId);
}

View File

@ -34,9 +34,9 @@ class ProductDownloadableLinkRepository extends Repository
foreach ($data as $type => $file) {
if (request()->hasFile($type)) {
return [
$type => $path = request()->file($type)->store('product_downloadable_links/' . $productId),
$type => $path = request()->file($type)->store('product_downloadable_links/' . $productId),
$type . '_name' => $file->getClientOriginalName(),
$type . '_url' => Storage::url($path)
$type . '_url' => Storage::url($path)
];
}
}

View File

@ -33,9 +33,9 @@ class ProductDownloadableSampleRepository extends Repository
{
if (request()->hasFile('file')) {
return [
'file' => $path = request()->file('file')->store('product_downloadable_links/' . $productId),
'file' => $path = request()->file('file')->store('product_downloadable_links/' . $productId),
'file_name' => request()->file('file')->getClientOriginalName(),
'file_url' => Storage::url($path)
'file_url' => Storage::url($path)
];
}

View File

@ -25,8 +25,9 @@ class ProductFlatRepository extends Repository
*/
public function getCategoryProductMaximumPrice($category = null)
{
if (! $category)
if (! $category) {
return $this->model->max('max_price');
}
return $this->model
->leftJoin('product_categories', 'product_flat.product_id', 'product_categories.product_id')

View File

@ -35,8 +35,9 @@ class ProductGroupedProductRepository extends Repository
'product_id' => $product->id,
], $linkInputs));
} else {
if (is_numeric($index = $previousGroupedProductIds->search($linkId)))
if (is_numeric($index = $previousGroupedProductIds->search($linkId))) {
$previousGroupedProductIds->forget($index);
}
$this->update($linkInputs, $linkId);
}

View File

@ -41,7 +41,7 @@ class ProductImageRepository extends Repository
if (Str::contains($imageId, 'image_')) {
if (request()->hasFile($file)) {
$this->create([
'path' => request()->file($file)->store($dir),
'path' => request()->file($file)->store($dir),
'product_id' => $product->id
]);
}

View File

@ -35,9 +35,9 @@ class ProductInventoryRepository extends Repository
$qty = is_null($qty) ? 0 : $qty;
$productInventory = $this->findOneWhere([
'product_id' => $product->id,
'product_id' => $product->id,
'inventory_source_id' => $inventorySourceId,
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0
]);
if ($productInventory) {
@ -46,10 +46,10 @@ class ProductInventoryRepository extends Repository
$productInventory->save();
} else {
$this->create([
'qty' => $qty,
'product_id' => $product->id,
'qty' => $qty,
'product_id' => $product->id,
'inventory_source_id' => $inventorySourceId,
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0
'vendor_id' => isset($data['vendor_id']) ? $data['vendor_id'] : 0
]);
}
}

View File

@ -83,8 +83,9 @@ class ProductRepository extends Repository
$product = $product->getTypeInstance()->update($data, $id, $attribute);
if (isset($data['channels']))
if (isset($data['channels'])) {
$product['channels'] = $data['channels'];
}
Event::dispatch('catalog.product.update.after', $product);
@ -125,14 +126,17 @@ class ProductRepository extends Repository
->where('product_flat.locale', $locale)
->whereNotNull('product_flat.url_key');
if ($categoryId)
if ($categoryId) {
$qb->where('product_categories.category_id', $categoryId);
}
if (is_null(request()->input('status')))
if (is_null(request()->input('status'))) {
$qb->where('product_flat.status', 1);
}
if (is_null(request()->input('visible_individually')))
if (is_null(request()->input('visible_individually'))) {
$qb->where('product_flat.visible_individually', 1);
}
$queryBuilder = $qb->leftJoin('product_flat as flat_variants', function($qb) use($channel, $locale) {
$qb->on('product_flat.id', '=', 'flat_variants.parent_id')
@ -182,8 +186,9 @@ class ProductRepository extends Repository
$query2 = $query2->where(function($query3) use($aliasTemp, $column, $temp) {
foreach($temp as $code => $filterValue) {
if (! is_numeric($filterValue))
if (! is_numeric($filterValue)) {
continue;
}
$columns = $aliasTemp . '.' . $column;
$query3 = $query3->orwhereRaw("find_in_set($filterValue, $columns)");
@ -214,7 +219,7 @@ class ProductRepository extends Repository
{
$product = app(ProductFlatRepository::class)->findOneWhere([
'url_key' => $slug,
'locale' => app()->getLocale(),
'locale' => app()->getLocale(),
'channel' => core()->getCurrentChannelCode(),
]);
@ -238,7 +243,7 @@ class ProductRepository extends Repository
{
return app(ProductFlatRepository::class)->findOneWhere([
'url_key' => $slug,
'locale' => app()->getLocale(),
'locale' => app()->getLocale(),
'channel' => core()->getCurrentChannelCode(),
]);
}
@ -334,9 +339,9 @@ class ProductRepository extends Repository
foreach ($attribute->options as $option) {
$superAttrbutes[$key]['options'][] = [
'id' => $option->id,
'admin_name' => $option->admin_name,
'sort_order' => $option->sort_order,
'id' => $option->id,
'admin_name' => $option->admin_name,
'sort_order' => $option->sort_order,
'swatch_value' => $option->swatch_value,
];
}

View File

@ -203,10 +203,10 @@ abstract class AbstractType
}
$attributeValue = $this->attributeValueRepository->findOneWhere([
'product_id' => $product->id,
'product_id' => $product->id,
'attribute_id' => $attribute->id,
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
'locale' => $attribute->value_per_locale ? $data['locale'] : null
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
'locale' => $attribute->value_per_locale ? $data['locale'] : null
]);
if (! $attributeValue) {
@ -495,8 +495,9 @@ abstract class AbstractType
{
$rulePrice = app('Webkul\CatalogRule\Helpers\CatalogRuleProductPrice')->getRulePrice($this->product);
if ((is_null($this->product->special_price) || ! (float) $this->product->special_price) && ! $rulePrice)
if ((is_null($this->product->special_price) || ! (float) $this->product->special_price) && ! $rulePrice) {
return false;
}
if (! (float) $this->product->special_price) {
if ($rulePrice) {
@ -532,11 +533,11 @@ abstract class AbstractType
{
return [
'regular_price' => [
'price' => core()->convertPrice($this->product->price),
'price' => core()->convertPrice($this->product->price),
'formated_price' => core()->currency($this->product->price)
],
'final_price' => [
'price' => core()->convertPrice($this->getMinimalPrice()),
'final_price' => [
'price' => core()->convertPrice($this->getMinimalPrice()),
'formated_price' => core()->currency($this->getMinimalPrice())
]
];
@ -580,19 +581,19 @@ abstract class AbstractType
$products = [
[
'product_id' => $this->product->id,
'sku' => $this->product->sku,
'quantity' => $data['quantity'],
'name' => $this->product->name,
'price' => $convertedPrice = core()->convertPrice($price),
'base_price' => $price,
'total' => $convertedPrice * $data['quantity'],
'base_total' => $price * $data['quantity'],
'weight' => $this->product->weight ?? 0,
'total_weight' => ($this->product->weight ?? 0) * $data['quantity'],
'product_id' => $this->product->id,
'sku' => $this->product->sku,
'quantity' => $data['quantity'],
'name' => $this->product->name,
'price' => $convertedPrice = core()->convertPrice($price),
'base_price' => $price,
'total' => $convertedPrice * $data['quantity'],
'base_total' => $price * $data['quantity'],
'weight' => $this->product->weight ?? 0,
'total_weight' => ($this->product->weight ?? 0) * $data['quantity'],
'base_total_weight' => ($this->product->weight ?? 0) * $data['quantity'],
'type' => $this->product->type,
'additional' => $this->getAdditionalOptions($data)
'type' => $this->product->type,
'additional' => $this->getAdditionalOptions($data)
]
];

View File

@ -127,8 +127,9 @@ class Bundle extends AbstractType
{
$product = parent::update($data, $id, $attribute);
if (request()->route()->getName() != 'admin.catalog.products.massupdate')
if (request()->route()->getName() != 'admin.catalog.products.massupdate') {
$this->productBundleOptionRepository->saveBundleOptons($data, $product);
}
return $product;
}
@ -180,8 +181,9 @@ class Bundle extends AbstractType
}
}
if (! $haveRequiredOptions)
if (! $haveRequiredOptions) {
$minPrice = count($minPrices) ? min($minPrices) : 0;
}
return $minPrice;
}
@ -213,8 +215,9 @@ class Bundle extends AbstractType
}
}
if (! $haveRequiredOptions && count($minPrices))
if (! $haveRequiredOptions && count($minPrices)) {
$minPrice = min($minPrices);
}
return $minPrice;
}
@ -248,8 +251,9 @@ class Bundle extends AbstractType
protected function haveRequiredOptions()
{
foreach ($this->product->bundle_options as $option) {
if ($option->is_required)
if ($option->is_required) {
return true;
}
}
return false;
@ -267,8 +271,9 @@ class Bundle extends AbstractType
foreach ($this->product->bundle_options as $option) {
foreach ($option->bundle_option_products as $index => $bundleOptionProduct) {
if (in_array($option->type, ['multiselect', 'checkbox'])) {
if (! isset($optionPrices[$option->id][0]))
if (! isset($optionPrices[$option->id][0])) {
$optionPrices[$option->id][0] = 0;
}
$optionPrices[$option->id][0] += $bundleOptionProduct->qty * $bundleOptionProduct->product->getTypeInstance()->getMinimalPrice();
} else {
@ -299,8 +304,9 @@ class Bundle extends AbstractType
foreach ($this->product->bundle_options as $option) {
foreach ($option->bundle_option_products as $index => $bundleOptionProduct) {
if (in_array($option->type, ['multiselect', 'checkbox'])) {
if (! isset($optionPrices[$option->id][0]))
if (! isset($optionPrices[$option->id][0])) {
$optionPrices[$option->id][0] = 0;
}
$optionPrices[$option->id][0] += $bundleOptionProduct->qty * $bundleOptionProduct->product->price;
} else {
@ -339,21 +345,22 @@ class Bundle extends AbstractType
return [
'from' => [
'regular_price' => [
'price' => core()->convertPrice($this->getRegularMinimalPrice()),
'price' => core()->convertPrice($this->getRegularMinimalPrice()),
'formated_price' => core()->currency($this->getRegularMinimalPrice())
],
'final_price' => [
'price' => core()->convertPrice($this->getMinimalPrice()),
'final_price' => [
'price' => core()->convertPrice($this->getMinimalPrice()),
'formated_price' => core()->currency($this->getMinimalPrice())
]
],
'to' => [
'to' => [
'regular_price' => [
'price' => core()->convertPrice($this->getRegularMaximamPrice()),
'price' => core()->convertPrice($this->getRegularMaximamPrice()),
'formated_price' => core()->currency($this->getRegularMaximamPrice())
],
'final_price' => [
'price' => core()->convertPrice($this->getMaximamPrice()),
'final_price' => [
'price' => core()->convertPrice($this->getMaximamPrice()),
'formated_price' => core()->currency($this->getMaximamPrice())
]
]
@ -405,11 +412,13 @@ class Bundle extends AbstractType
*/
public function prepareForCart($data)
{
if (isset($data['bundle_options']))
if (isset($data['bundle_options'])) {
$data['bundle_options'] = array_filter($this->validateBundleOptionForCart($data['bundle_options']));
}
if (! isset($data['bundle_options']) || ! count($data['bundle_options']))
if (! isset($data['bundle_options']) || ! count($data['bundle_options'])) {
return trans('shop::app.checkout.cart.integrity.missing_options');
}
$products = parent::prepareForCart($data);
@ -418,8 +427,9 @@ class Bundle extends AbstractType
$cartProduct = $product->getTypeInstance()->prepareForCart(array_merge($data, ['parent_id' => $this->product->id]));
if (is_string($cartProduct))
if (is_string($cartProduct)) {
return $cartProduct;
}
$cartProduct[0]['parent_id'] = $this->product->id;
$cartProduct[0]['quantity'] = $data['quantity'];
@ -452,11 +462,12 @@ class Bundle extends AbstractType
foreach ($data['bundle_options'] as $optionId => $optionProductIds) {
foreach ($optionProductIds as $optionProductId) {
if (! $optionProductId)
if (! $optionProductId) {
continue;
}
$optionProduct = $this->productBundleOptionProductRepository->findOneWhere([
'id' => $optionProductId,
'id' => $optionProductId,
'product_bundle_option_id' => $optionId
]);
@ -465,7 +476,7 @@ class Bundle extends AbstractType
if (! isset($products[$optionProduct->product_id])) {
$products[$optionProduct->product_id] = [
'product_id' => $optionProduct->product_id,
'quantity' => $qty,
'quantity' => $qty,
];
} else {
$products[$optionProduct->product_id] = array_merge($products[$optionProduct->product_id], [
@ -486,8 +497,9 @@ class Bundle extends AbstractType
*/
public function compareOptions($options1, $options2)
{
if ($this->product->id != $options2['product_id'])
if ($this->product->id != $options2['product_id']) {
return false;
}
return $options1['bundle_options'] == $options2['bundle_options']
&& $options1['bundle_option_qty'] == $this->getOptionQuantities($options2);
@ -530,15 +542,17 @@ class Bundle extends AbstractType
$labels = [];
foreach ($optionProductIds as $optionProductId) {
if (! $optionProductId)
if (! $optionProductId) {
continue;
}
$optionProduct = $this->productBundleOptionProductRepository->find($optionProductId);
$qty = $data['bundle_option_qty'][$optionId] ?? $optionProduct->qty;
if (! isset($data['bundle_option_qty'][$optionId]))
if (! isset($data['bundle_option_qty'][$optionId])) {
$bundleOptionQuantities[$optionId] = $qty;
}
$labels[] = $qty . ' x ' . $optionProduct->product->name . ' ' . core()->currency($optionProduct->product->getTypeInstance()->getMinimalPrice());
}
@ -546,8 +560,8 @@ class Bundle extends AbstractType
if (count($labels)) {
$data['attributes'][$option->id] = [
'attribute_name' => $option->label,
'option_id' => $option->id,
'option_label' => implode(', ', $labels),
'option_id' => $option->id,
'option_label' => implode(', ', $labels),
];
}
}
@ -569,8 +583,9 @@ class Bundle extends AbstractType
foreach ($data['bundle_options'] as $optionId => $optionProductIds) {
foreach ($optionProductIds as $optionProductId) {
if (! $optionProductId)
if (! $optionProductId) {
continue;
}
if (isset($data['bundle_option_qty'][$optionId])) {
$optionQuantities[$optionId] = $data['bundle_option_qty'][$optionId];
@ -603,8 +618,9 @@ class Bundle extends AbstractType
$price += $childItem->base_price * $childItem->quantity;
}
if ($price == $item->base_price)
if ($price == $item->base_price) {
return;
}
$item->base_price = $price;
$item->price = core()->convertPrice($price);

View File

@ -106,8 +106,9 @@ class Configurable extends AbstractType
$this->createVariant($product, $permutation, $variantData);
} else {
if (is_numeric($index = $previousVariantIds->search($variantId)))
if (is_numeric($index = $previousVariantIds->search($variantId))) {
$previousVariantIds->forget($index);
}
$variantData['channel'] = $data['channel'];
$variantData['locale'] = $data['locale'];
@ -135,12 +136,12 @@ class Configurable extends AbstractType
{
if (! count($data)) {
$data = [
"sku" => $product->sku . '-variant-' . implode('-', $permutation),
"name" => "",
"inventories" => [],
"price" => 0,
"weight" => 0,
"status" => 1
'sku' => $product->sku . '-variant-' . implode('-', $permutation),
'name' => '',
'inventories' => [],
'price' => 0,
'weight' => 0,
'status' => 1
];
}
@ -165,21 +166,21 @@ class Configurable extends AbstractType
foreach (core()->getAllChannels() as $channel) {
foreach (core()->getAllLocales() as $locale) {
$this->attributeValueRepository->create([
'product_id' => $variant->id,
'product_id' => $variant->id,
'attribute_id' => $attribute->id,
'channel' => $channel->code,
'locale' => $locale->code,
'value' => $data[$attributeCode]
'channel' => $channel->code,
'locale' => $locale->code,
'value' => $data[$attributeCode]
]);
}
}
} else {
foreach (core()->getAllChannels() as $channel) {
$this->attributeValueRepository->create([
'product_id' => $variant->id,
'product_id' => $variant->id,
'attribute_id' => $attribute->id,
'channel' => $channel->code,
'value' => $data[$attributeCode]
'channel' => $channel->code,
'value' => $data[$attributeCode]
]);
}
}
@ -187,17 +188,17 @@ class Configurable extends AbstractType
if ($attribute->value_per_locale) {
foreach (core()->getAllLocales() as $locale) {
$this->attributeValueRepository->create([
'product_id' => $variant->id,
'product_id' => $variant->id,
'attribute_id' => $attribute->id,
'locale' => $locale->code,
'value' => $data[$attributeCode]
'locale' => $locale->code,
'value' => $data[$attributeCode]
]);
}
} else {
$this->attributeValueRepository->create([
'product_id' => $variant->id,
'product_id' => $variant->id,
'attribute_id' => $attribute->id,
'value' => $data[$attributeCode]
'value' => $data[$attributeCode]
]);
}
}
@ -205,9 +206,9 @@ class Configurable extends AbstractType
foreach ($permutation as $attributeId => $optionId) {
$this->attributeValueRepository->create([
'product_id' => $variant->id,
'product_id' => $variant->id,
'attribute_id' => $attributeId,
'value' => $optionId
'value' => $optionId
]);
}
@ -231,19 +232,19 @@ class Configurable extends AbstractType
$attribute = $this->attributeRepository->findOneByField('code', $attributeCode);
$attributeValue = $this->attributeValueRepository->findOneWhere([
'product_id' => $id,
'product_id' => $id,
'attribute_id' => $attribute->id,
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
'locale' => $attribute->value_per_locale ? $data['locale'] : null
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
'locale' => $attribute->value_per_locale ? $data['locale'] : null
]);
if (! $attributeValue) {
$this->attributeValueRepository->create([
'product_id' => $id,
'product_id' => $id,
'attribute_id' => $attribute->id,
'value' => $data[$attribute->code],
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
'locale' => $attribute->value_per_locale ? $data['locale'] : null
'value' => $data[$attribute->code],
'channel' => $attribute->value_per_channel ? $data['channel'] : null,
'locale' => $attribute->value_per_locale ? $data['locale'] : null
]);
} else {
$this->attributeValueRepository->update([
@ -267,21 +268,25 @@ class Configurable extends AbstractType
$superAttributeCodes = $product->parent->super_attributes->pluck('code');
foreach ($product->parent->variants as $variant) {
if ($variant->id == $product->id)
if ($variant->id == $product->id) {
continue;
}
$matchCount = 0;
foreach ($superAttributeCodes as $attributeCode) {
if (! isset($data[$attributeCode]))
if (! isset($data[$attributeCode])) {
return false;
}
if ($data[$attributeCode] == $variant->{$attributeCode})
if ($data[$attributeCode] == $variant->{$attributeCode}) {
$matchCount++;
}
}
if ($matchCount == $superAttributeCodes->count())
if ($matchCount == $superAttributeCodes->count()) {
return true;
}
}
return false;
@ -314,9 +319,9 @@ class Configurable extends AbstractType
public function getTypeValidationRules()
{
return [
'variants.*.name' => 'required',
'variants.*.sku' => 'required',
'variants.*.price' => 'required',
'variants.*.name' => 'required',
'variants.*.sku' => 'required',
'variants.*.price' => 'required',
'variants.*.weight' => 'required',
];
}
@ -329,8 +334,9 @@ class Configurable extends AbstractType
*/
public function canBeMovedFromWishlistToCart($item)
{
if (isset($item->additional['selected_configurable_option']))
if (isset($item->additional['selected_configurable_option'])) {
return true;
}
return false;
}
@ -358,8 +364,9 @@ class Configurable extends AbstractType
$minPrices[] = $price->min_price;
}
if (empty($minPrices))
if (empty($minPrices)) {
return 0;
}
return min($minPrices);
}
@ -401,39 +408,41 @@ class Configurable extends AbstractType
*/
public function prepareForCart($data)
{
if (! isset($data['selected_configurable_option']) || ! $data['selected_configurable_option'])
if (! isset($data['selected_configurable_option']) || ! $data['selected_configurable_option']) {
return trans('shop::app.checkout.cart.integrity.missing_options');
}
$data = $this->getQtyRequest($data);
$childProduct = $this->productRepository->find($data['selected_configurable_option']);
if (! $childProduct->haveSufficientQuantity($data['quantity']))
if (! $childProduct->haveSufficientQuantity($data['quantity'])) {
return trans('shop::app.checkout.cart.quantity.inventory_warning');
}
$price = $childProduct->getTypeInstance()->getFinalPrice();
$products = [
[
'product_id' => $this->product->id,
'sku' => $this->product->sku,
'quantity' => $data['quantity'],
'name' => $this->product->name,
'price' => $convertedPrice = core()->convertPrice($price),
'base_price' => $price,
'total' => $convertedPrice * $data['quantity'],
'base_total' => $price * $data['quantity'],
'weight' => $childProduct->weight,
'total_weight' => $childProduct->weight * $data['quantity'],
'product_id' => $this->product->id,
'sku' => $this->product->sku,
'quantity' => $data['quantity'],
'name' => $this->product->name,
'price' => $convertedPrice = core()->convertPrice($price),
'base_price' => $price,
'total' => $convertedPrice * $data['quantity'],
'base_total' => $price * $data['quantity'],
'weight' => $childProduct->weight,
'total_weight' => $childProduct->weight * $data['quantity'],
'base_total_weight' => $childProduct->weight * $data['quantity'],
'type' => $this->product->type,
'additional' => $this->getAdditionalOptions($data)
'type' => $this->product->type,
'additional' => $this->getAdditionalOptions($data)
], [
'parent_id' => $this->product->id,
'parent_id' => $this->product->id,
'product_id' => (int) $data['selected_configurable_option'],
'sku' => $childProduct->sku,
'name' => $childProduct->name,
'type' => 'simple',
'sku' => $childProduct->sku,
'name' => $childProduct->name,
'type' => 'simple',
'additional' => ['product_id' => (int) $data['selected_configurable_option'], 'parent_id' => $this->product->id]
]
];
@ -449,8 +458,9 @@ class Configurable extends AbstractType
*/
public function compareOptions($options1, $options2)
{
if ($this->product->id != $options2['product_id'])
if ($this->product->id != $options2['product_id']) {
return false;
}
return $options1['selected_configurable_option'] === $options2['selected_configurable_option'];
}
@ -470,8 +480,8 @@ class Configurable extends AbstractType
$data['attributes'][$attribute->code] = [
'attribute_name' => $attribute->name ? $attribute->name : $attribute->admin_name,
'option_id' => $option->id,
'option_label' => $option->label ? $option->label : $option->admin_name,
'option_id' => $option->id,
'option_label' => $option->label ? $option->label : $option->admin_name,
];
}
@ -520,8 +530,9 @@ class Configurable extends AbstractType
{
$price = $item->child->product->getTypeInstance()->getFinalPrice();
if ($price == $item->base_price)
if ($price == $item->base_price) {
return;
}
$item->base_price = $price;
$item->price = core()->convertPrice($price);

View File

@ -125,11 +125,13 @@ class Downloadable extends AbstractType
*/
public function isSaleable()
{
if (! $this->product->status)
if (! $this->product->status) {
return false;
}
if ($this->product->downloadable_links()->count())
if ($this->product->downloadable_links()->count()) {
return true;
}
return false;
}
@ -143,11 +145,11 @@ class Downloadable extends AbstractType
{
return [
// 'downloadable_links.*.title' => 'required',
'downloadable_links.*.type' => 'required',
'downloadable_links.*.file' => 'required_if:type,==,file',
'downloadable_links.*.file_name' => 'required_if:type,==,file',
'downloadable_links.*.url' => 'required_if:type,==,url',
'downloadable_links.*.downloads' => 'required',
'downloadable_links.*.type' => 'required',
'downloadable_links.*.file' => 'required_if:type,==,file',
'downloadable_links.*.file_name' => 'required_if:type,==,file',
'downloadable_links.*.url' => 'required_if:type,==,url',
'downloadable_links.*.downloads' => 'required',
'downloadable_links.*.sort_order' => 'required',
];
}
@ -160,14 +162,16 @@ class Downloadable extends AbstractType
*/
public function prepareForCart($data)
{
if (! isset($data['links']) || ! count($data['links']))
if (! isset($data['links']) || ! count($data['links'])) {
return trans('shop::app.checkout.cart.integrity.missing_links');
}
$products = parent::prepareForCart($data);
foreach ($this->product->downloadable_links as $link) {
if (! in_array($link->id, $data['links']))
if (! in_array($link->id, $data['links'])) {
continue;
}
$products[0]['price'] += core()->convertPrice($link->price);
$products[0]['base_price'] += $link->price;
@ -186,8 +190,9 @@ class Downloadable extends AbstractType
*/
public function compareOptions($options1, $options2)
{
if ($this->product->id != $options2['product_id'])
if ($this->product->id != $options2['product_id']) {
return false;
}
return $options1['links'] == $options2['links'];
}
@ -203,14 +208,15 @@ class Downloadable extends AbstractType
$labels = [];
foreach ($this->product->downloadable_links as $link) {
if (in_array($link->id, $data['links']))
if (in_array($link->id, $data['links'])) {
$labels[] = $link->title;
}
}
$data['attributes'][0] = [
'attribute_name' => 'Downloads',
'option_id' => 0,
'option_label' => implode(', ', $labels),
'option_id' => 0,
'option_label' => implode(', ', $labels),
];
return $data;
@ -227,14 +233,16 @@ class Downloadable extends AbstractType
$price = $item->product->getTypeInstance()->getFinalPrice();
foreach ($item->product->downloadable_links as $link) {
if (! in_array($link->id, $item->additional['links']))
if (! in_array($link->id, $item->additional['links'])) {
continue;
}
$price += $link->price;
}
if ($price == $item->base_price)
if ($price == $item->base_price) {
return;
}
$item->base_price = $price;
$item->price = core()->convertPrice($price);

View File

@ -98,8 +98,9 @@ class Grouped extends AbstractType
{
$product = parent::update($data, $id, $attribute);
if (request()->route()->getName() != 'admin.catalog.products.massupdate')
if (request()->route()->getName() != 'admin.catalog.products.massupdate') {
$this->productGroupedProductRepository->saveGroupedProducts($data, $product);
}
return $product;
}
@ -137,8 +138,9 @@ class Grouped extends AbstractType
$minPrices[] = $groupOptionProduct->associated_product->getTypeInstance()->getMinimalPrice();
}
if (empty($minPrices))
if (empty($minPrices)) {
return 0;
}
return min($minPrices);
}
@ -162,14 +164,16 @@ class Grouped extends AbstractType
*/
public function prepareForCart($data)
{
if (! isset($data['qty']) || ! is_array($data['qty']))
if (! isset($data['qty']) || ! is_array($data['qty'])) {
return trans('shop::app.checkout.cart.integrity.missing_options');
}
$products = [];
foreach ($data['qty'] as $productId => $qty) {
if (! $qty)
if (! $qty) {
continue;
}
$product = $this->productRepository->find($productId);
@ -178,14 +182,16 @@ class Grouped extends AbstractType
'quantity' => $qty,
]);
if (is_string($cartProducts))
if (is_string($cartProducts)) {
return $cartProducts;
}
$products = array_merge($products, $cartProducts);
}
if (! count($products))
if (! count($products)) {
return trans('shop::app.checkout.cart.integrity.qty_missing');
}
return $products;
}

View File

@ -44,11 +44,13 @@ class Simple extends AbstractType
*/
public function isSaleable()
{
if (! $this->product->status)
if (! $this->product->status) {
return false;
}
if ($this->haveSufficientQuantity(1))
if ($this->haveSufficientQuantity(1)) {
return true;
}
return false;
}
@ -61,6 +63,7 @@ class Simple extends AbstractType
public function haveSufficientQuantity($qty)
{
$backorders = core()->getConfigData('catalog.inventory.stock_options.backorders');
return $qty <= $this->totalQuantity() ? true : $backorders;
}
}

View File

@ -51,11 +51,13 @@ class Virtual extends AbstractType
*/
public function isSaleable()
{
if (! $this->product->status)
if (! $this->product->status) {
return false;
}
if ($this->haveSufficientQuantity(1))
if ($this->haveSufficientQuantity(1)) {
return true;
}
return false;
}