diff --git a/composer.json b/composer.json index 48c2fa1f2..6ebf4ccf6 100755 --- a/composer.json +++ b/composer.json @@ -9,12 +9,12 @@ "type": "project", "require": { "php": "^7.1.3", + "ext-curl": "*", + "ext-mbstring": "*", "ext-openssl": "*", "ext-pdo": "*", - "ext-mbstring": "*", - "ext-tokenizer": "*", "ext-pdo_mysql": "*", - "ext-curl": "*", + "ext-tokenizer": "*", "barryvdh/laravel-dompdf": "^0.8.0@dev", "dimsav/laravel-translatable": "^9.0", "doctrine/dbal": "^2.9@dev", diff --git a/config/jwt.php b/config/jwt.php new file mode 100644 index 000000000..8b7843b6b --- /dev/null +++ b/config/jwt.php @@ -0,0 +1,304 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +return [ + + /* + |-------------------------------------------------------------------------- + | JWT Authentication Secret + |-------------------------------------------------------------------------- + | + | Don't forget to set this in your .env file, as it will be used to sign + | your tokens. A helper command is provided for this: + | `php artisan jwt:secret` + | + | Note: This will be used for Symmetric algorithms only (HMAC), + | since RSA and ECDSA use a private/public key combo (See below). + | + */ + + 'secret' => env('JWT_SECRET'), + + /* + |-------------------------------------------------------------------------- + | JWT Authentication Keys + |-------------------------------------------------------------------------- + | + | The algorithm you are using, will determine whether your tokens are + | signed with a random string (defined in `JWT_SECRET`) or using the + | following public & private keys. + | + | Symmetric Algorithms: + | HS256, HS384 & HS512 will use `JWT_SECRET`. + | + | Asymmetric Algorithms: + | RS256, RS384 & RS512 / ES256, ES384 & ES512 will use the keys below. + | + */ + + 'keys' => [ + + /* + |-------------------------------------------------------------------------- + | Public Key + |-------------------------------------------------------------------------- + | + | A path or resource to your public key. + | + | E.g. 'file://path/to/public/key' + | + */ + + 'public' => env('JWT_PUBLIC_KEY'), + + /* + |-------------------------------------------------------------------------- + | Private Key + |-------------------------------------------------------------------------- + | + | A path or resource to your private key. + | + | E.g. 'file://path/to/private/key' + | + */ + + 'private' => env('JWT_PRIVATE_KEY'), + + /* + |-------------------------------------------------------------------------- + | Passphrase + |-------------------------------------------------------------------------- + | + | The passphrase for your private key. Can be null if none set. + | + */ + + 'passphrase' => env('JWT_PASSPHRASE'), + + ], + + /* + |-------------------------------------------------------------------------- + | JWT time to live + |-------------------------------------------------------------------------- + | + | Specify the length of time (in minutes) that the token will be valid for. + | Defaults to 1 hour. + | + | You can also set this to null, to yield a never expiring token. + | Some people may want this behaviour for e.g. a mobile app. + | This is not particularly recommended, so make sure you have appropriate + | systems in place to revoke the token if necessary. + | Notice: If you set this to null you should remove 'exp' element from 'required_claims' list. + | + */ + + 'ttl' => env('JWT_TTL', 60), + + /* + |-------------------------------------------------------------------------- + | Refresh time to live + |-------------------------------------------------------------------------- + | + | Specify the length of time (in minutes) that the token can be refreshed + | within. I.E. The user can refresh their token within a 2 week window of + | the original token being created until they must re-authenticate. + | Defaults to 2 weeks. + | + | You can also set this to null, to yield an infinite refresh time. + | Some may want this instead of never expiring tokens for e.g. a mobile app. + | This is not particularly recommended, so make sure you have appropriate + | systems in place to revoke the token if necessary. + | + */ + + 'refresh_ttl' => env('JWT_REFRESH_TTL', 20160), + + /* + |-------------------------------------------------------------------------- + | JWT hashing algorithm + |-------------------------------------------------------------------------- + | + | Specify the hashing algorithm that will be used to sign the token. + | + | See here: https://github.com/namshi/jose/tree/master/src/Namshi/JOSE/Signer/OpenSSL + | for possible values. + | + */ + + 'algo' => env('JWT_ALGO', 'HS256'), + + /* + |-------------------------------------------------------------------------- + | Required Claims + |-------------------------------------------------------------------------- + | + | Specify the required claims that must exist in any token. + | A TokenInvalidException will be thrown if any of these claims are not + | present in the payload. + | + */ + + 'required_claims' => [ + 'iss', + 'iat', + 'exp', + 'nbf', + 'sub', + 'jti', + ], + + /* + |-------------------------------------------------------------------------- + | Persistent Claims + |-------------------------------------------------------------------------- + | + | Specify the claim keys to be persisted when refreshing a token. + | `sub` and `iat` will automatically be persisted, in + | addition to the these claims. + | + | Note: If a claim does not exist then it will be ignored. + | + */ + + 'persistent_claims' => [ + // 'foo', + // 'bar', + ], + + /* + |-------------------------------------------------------------------------- + | Lock Subject + |-------------------------------------------------------------------------- + | + | This will determine whether a `prv` claim is automatically added to + | the token. The purpose of this is to ensure that if you have multiple + | authentication models e.g. `App\User` & `App\OtherPerson`, then we + | should prevent one authentication request from impersonating another, + | if 2 tokens happen to have the same id across the 2 different models. + | + | Under specific circumstances, you may want to disable this behaviour + | e.g. if you only have one authentication model, then you would save + | a little on token size. + | + */ + + 'lock_subject' => true, + + /* + |-------------------------------------------------------------------------- + | Leeway + |-------------------------------------------------------------------------- + | + | This property gives the jwt timestamp claims some "leeway". + | Meaning that if you have any unavoidable slight clock skew on + | any of your servers then this will afford you some level of cushioning. + | + | This applies to the claims `iat`, `nbf` and `exp`. + | + | Specify in seconds - only if you know you need it. + | + */ + + 'leeway' => env('JWT_LEEWAY', 0), + + /* + |-------------------------------------------------------------------------- + | Blacklist Enabled + |-------------------------------------------------------------------------- + | + | In order to invalidate tokens, you must have the blacklist enabled. + | If you do not want or need this functionality, then set this to false. + | + */ + + 'blacklist_enabled' => env('JWT_BLACKLIST_ENABLED', true), + + /* + | ------------------------------------------------------------------------- + | Blacklist Grace Period + | ------------------------------------------------------------------------- + | + | When multiple concurrent requests are made with the same JWT, + | it is possible that some of them fail, due to token regeneration + | on every request. + | + | Set grace period in seconds to prevent parallel request failure. + | + */ + + 'blacklist_grace_period' => env('JWT_BLACKLIST_GRACE_PERIOD', 0), + + /* + |-------------------------------------------------------------------------- + | Cookies encryption + |-------------------------------------------------------------------------- + | + | By default Laravel encrypt cookies for security reason. + | If you decide to not decrypt cookies, you will have to configure Laravel + | to not encrypt your cookie token by adding its name into the $except + | array available in the middleware "EncryptCookies" provided by Laravel. + | see https://laravel.com/docs/master/responses#cookies-and-encryption + | for details. + | + | Set it to true if you want to decrypt cookies. + | + */ + + 'decrypt_cookies' => false, + + /* + |-------------------------------------------------------------------------- + | Providers + |-------------------------------------------------------------------------- + | + | Specify the various providers used throughout the package. + | + */ + + 'providers' => [ + + /* + |-------------------------------------------------------------------------- + | JWT Provider + |-------------------------------------------------------------------------- + | + | Specify the provider that is used to create and decode the tokens. + | + */ + + 'jwt' => Tymon\JWTAuth\Providers\JWT\Lcobucci::class, + + /* + |-------------------------------------------------------------------------- + | Authentication Provider + |-------------------------------------------------------------------------- + | + | Specify the provider that is used to authenticate users. + | + */ + + 'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class, + + /* + |-------------------------------------------------------------------------- + | Storage Provider + |-------------------------------------------------------------------------- + | + | Specify the provider that is used to store tokens in the blacklist. + | + */ + + 'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class, + + ], + +]; diff --git a/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php b/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php index 26d79cd65..fbec30646 100755 --- a/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php +++ b/packages/Webkul/Attribute/src/Repositories/AttributeRepository.php @@ -144,6 +144,10 @@ class AttributeRepository extends Repository $data['is_filterable'] = 0; } + if (in_array($data['type'], ['select', 'multiselect', 'boolean'])) { + unset($data['value_per_locale']); + } + return $data; } diff --git a/packages/Webkul/Category/src/Repositories/CategoryRepository.php b/packages/Webkul/Category/src/Repositories/CategoryRepository.php index 476d148c9..ec23041e3 100755 --- a/packages/Webkul/Category/src/Repositories/CategoryRepository.php +++ b/packages/Webkul/Category/src/Repositories/CategoryRepository.php @@ -99,9 +99,18 @@ class CategoryRepository extends Repository */ public function getVisibleCategoryTree($id = null) { - return $id - ? Category::orderBy('position', 'ASC')->where('status', 1)->descendantsOf($id)->toTree() - : Category::orderBy('position', 'ASC')->where('status', 1)->get()->toTree(); + static $categories; + + if ($categories[$id]) + return $categories[$id]; + + if ($id) { + $categories[$id] = Category::orderBy('position', 'ASC')->where('status', 1)->descendantsOf($id)->toTree(); + } else { + $categories[$id] = Category::orderBy('position', 'ASC')->where('status', 1)->get()->toTree(); + } + + return $categories[$id]; } /** diff --git a/packages/Webkul/Product/src/Contracts/Criteria/ProductFlat.php b/packages/Webkul/Product/src/Contracts/Criteria/ProductFlat.php deleted file mode 100644 index e69de29bb..000000000 diff --git a/packages/Webkul/Product/src/Helpers/ProductImage.php b/packages/Webkul/Product/src/Helpers/ProductImage.php index c486f725a..b4769d530 100755 --- a/packages/Webkul/Product/src/Helpers/ProductImage.php +++ b/packages/Webkul/Product/src/Helpers/ProductImage.php @@ -33,10 +33,10 @@ class ProductImage extends AbstractProduct if (! $product || (! $product->parent_id && !count($images))) { $images[] = [ - 'small_image_url' => bagisto_asset('images/product/small-product-placeholder.png'), - 'medium_image_url' => bagisto_asset('images/product/meduim-product-placeholder.png'), - 'large_image_url' => bagisto_asset('images/product/large-product-placeholder.png'), - 'original_image_url' => bagisto_asset('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') ]; } @@ -61,10 +61,10 @@ class ProductImage extends AbstractProduct ]; } else { $image = [ - 'small_image_url' => bagisto_asset('images/product/small-product-placeholder.png'), - 'medium_image_url' => bagisto_asset('images/product/meduim-product-placeholder.png'), - 'large_image_url' => bagisto_asset('images/product/large-product-placeholder.png'), - 'original_image_url' => bagisto_asset('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'), ]; } diff --git a/packages/Webkul/Product/src/Helpers/View.php b/packages/Webkul/Product/src/Helpers/View.php index 9fd300625..2c4904d24 100755 --- a/packages/Webkul/Product/src/Helpers/View.php +++ b/packages/Webkul/Product/src/Helpers/View.php @@ -14,58 +14,43 @@ class View extends AbstractProduct { $data = []; - $attributes = $product->attribute_family->custom_attributes; + $attributes = $product->attribute_family->custom_attributes()->where('attributes.is_visible_on_front', 1)->get(); $attributeOptionReposotory = app('Webkul\Attribute\Repositories\AttributeOptionRepository'); foreach ($attributes as $attribute) { if ($attribute->type == 'boolean') { - $value = $product->{$attribute->code}; - if ($attribute->is_visible_on_front ) { - if ($value == 1) { - $value = 'Yes'; - } else { - $value = 'No'; - } + $value = $product->{$attribute->code} ? 'Yes' : 'No'; - $data[] = [ - 'code' => $attribute->code, - 'label' => $attribute->name, - 'value' => $value, - 'admin_name' => $attribute->admin_name, - ]; - } - } else if ($attribute->is_visible_on_front && $product->{$attribute->code}) { + $data[] = [ + 'code' => $attribute->code, + 'label' => $attribute->name, + 'value' => $value, + 'admin_name' => $attribute->admin_name, + ]; + } else if ($product->{$attribute->code}) { $value = $product->{$attribute->code}; if ($attribute->type == 'select') { $attributeOption = $attributeOptionReposotory->find($value); if ($attributeOption) { - $value = $attributeOption->translate(app()->getLocale()); - if ($value) { - $value = $value->label; - } + $value = $attributeOption->label; } - } + } else if ($attribute->type == 'multiselect') { + $optionIds = explode(",", $value); - if ($attribute->type == 'multiselect') { - $values = explode(",", $value); + if (count($optionIds)) { + $attributeOptions = $attributeOptionReposotory->findWhereIn('id', $optionIds); - $result = []; - foreach ($values as $value) { - $attributeOption = $attributeOptionReposotory->find($value); - - if ($attributeOption) { - $value = $attributeOption->translate(app()->getLocale()); - if ($value) { - $value = $value->label; - $result[] = $value; + foreach ($attributeOptions as $attributeOption) { + if ($attributeOption && $attributeOption->label) { + $result[] = $attributeOption->label; } } - } - $value = implode(", ", $result); + $value = implode(", ", $result); + } } $data[] = [ @@ -73,7 +58,7 @@ class View extends AbstractProduct 'label' => $attribute->name, 'value' => $value, 'admin_name' => $attribute->admin_name, - ]; + ]; } } diff --git a/packages/Webkul/Shop/src/Resources/views/products/index.blade.php b/packages/Webkul/Shop/src/Resources/views/products/index.blade.php index b5ccd5c11..a144e1cf6 100755 --- a/packages/Webkul/Shop/src/Resources/views/products/index.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/products/index.blade.php @@ -49,7 +49,7 @@