This commit is contained in:
Shubham Mehrotra 2020-04-24 15:26:35 +05:30
commit 6fc769bfaf
32 changed files with 968 additions and 351 deletions

2
app/Console/Kernel.php Executable file → Normal file
View File

@ -39,4 +39,4 @@ class Kernel extends ConsoleKernel
require base_path('routes/console.php');
}
}
}

434
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "027ac2836216da68226e72e0ca7e4211",
"content-hash": "89956b3147bad29980a3486770493059",
"packages": [
{
"name": "astrotomic/laravel-translatable",
@ -71,6 +71,74 @@
],
"time": "2020-03-03T10:43:26+00:00"
},
{
"name": "barryvdh/laravel-debugbar",
"version": "v3.2.9",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-debugbar.git",
"reference": "42d5da5379a7860093f8e4032167e4cb5ebec180"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/42d5da5379a7860093f8e4032167e4cb5ebec180",
"reference": "42d5da5379a7860093f8e4032167e4cb5ebec180",
"shasum": ""
},
"require": {
"illuminate/routing": "^5.5|^6|^7",
"illuminate/session": "^5.5|^6|^7",
"illuminate/support": "^5.5|^6|^7",
"maximebf/debugbar": "^1.15.1",
"php": ">=7.0",
"symfony/debug": "^3|^4|^5",
"symfony/finder": "^3|^4|^5"
},
"require-dev": {
"laravel/framework": "5.5.x"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
},
"laravel": {
"providers": [
"Barryvdh\\Debugbar\\ServiceProvider"
],
"aliases": {
"Debugbar": "Barryvdh\\Debugbar\\Facade"
}
}
},
"autoload": {
"psr-4": {
"Barryvdh\\Debugbar\\": "src/"
},
"files": [
"src/helpers.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "PHP Debugbar integration for Laravel",
"keywords": [
"debug",
"debugbar",
"laravel",
"profiler",
"webprofiler"
],
"time": "2020-02-25T20:42:23+00:00"
},
{
"name": "barryvdh/laravel-dompdf",
"version": "v0.8.5",
@ -819,6 +887,56 @@
],
"time": "2019-07-28T22:19:29+00:00"
},
{
"name": "fzaninotto/faker",
"version": "v1.9.1",
"source": {
"type": "git",
"url": "https://github.com/fzaninotto/Faker.git",
"reference": "fc10d778e4b84d5bd315dad194661e091d307c6f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/fc10d778e4b84d5bd315dad194661e091d307c6f",
"reference": "fc10d778e4b84d5bd315dad194661e091d307c6f",
"shasum": ""
},
"require": {
"php": "^5.3.3 || ^7.0"
},
"require-dev": {
"ext-intl": "*",
"phpunit/phpunit": "^4.8.35 || ^5.7",
"squizlabs/php_codesniffer": "^2.9.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.9-dev"
}
},
"autoload": {
"psr-4": {
"Faker\\": "src/Faker/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "François Zaninotto"
}
],
"description": "Faker is a PHP library that generates fake data for you.",
"keywords": [
"data",
"faker",
"fixtures"
],
"time": "2019-12-12T13:22:17+00:00"
},
{
"name": "guzzlehttp/guzzle",
"version": "6.5.2",
@ -1172,6 +1290,7 @@
"email": "jakub.onderka@gmail.com"
}
],
"abandoned": "php-parallel-lint/php-console-color",
"time": "2018-09-29T17:23:10+00:00"
},
{
@ -1218,6 +1337,7 @@
}
],
"description": "Highlight PHP code in terminal",
"abandoned": "php-parallel-lint/php-console-highlighter",
"time": "2018-09-29T18:48:56+00:00"
},
{
@ -1276,6 +1396,7 @@
"serialize",
"tokenizer"
],
"abandoned": "opis/closure",
"time": "2018-03-21T22:21:57+00:00"
},
{
@ -2216,6 +2337,67 @@
],
"time": "2019-10-06T11:29:25+00:00"
},
{
"name": "maximebf/debugbar",
"version": "v1.16.1",
"source": {
"type": "git",
"url": "https://github.com/maximebf/php-debugbar.git",
"reference": "58998b818c6567fac01e35b8a4b70c1a64530556"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/58998b818c6567fac01e35b8a4b70c1a64530556",
"reference": "58998b818c6567fac01e35b8a4b70c1a64530556",
"shasum": ""
},
"require": {
"php": "^7.1",
"psr/log": "^1.0",
"symfony/var-dumper": "^2.6|^3|^4|^5"
},
"require-dev": {
"phpunit/phpunit": "^5"
},
"suggest": {
"kriswallsmith/assetic": "The best way to manage assets",
"monolog/monolog": "Log using Monolog",
"predis/predis": "Redis storage"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.16-dev"
}
},
"autoload": {
"psr-4": {
"DebugBar\\": "src/DebugBar/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Maxime Bouroumeau-Fuseau",
"email": "maxime.bouroumeau@gmail.com",
"homepage": "http://maximebf.com"
},
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "Debug bar in the browser for php application",
"homepage": "https://github.com/maximebf/php-debugbar",
"keywords": [
"debug",
"debugbar"
],
"time": "2019-11-24T09:46:11+00:00"
},
{
"name": "monolog/monolog",
"version": "2.0.2",
@ -3914,16 +4096,16 @@
},
{
"name": "symfony/http-foundation",
"version": "v4.4.7",
"version": "v4.4.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/http-foundation.git",
"reference": "62f92509c9abfd1f73e17b8cf1b72c0bdac6611b"
"reference": "7e41b4fcad4619535f45f8bfa7744c4f384e1648"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/62f92509c9abfd1f73e17b8cf1b72c0bdac6611b",
"reference": "62f92509c9abfd1f73e17b8cf1b72c0bdac6611b",
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/7e41b4fcad4619535f45f8bfa7744c4f384e1648",
"reference": "7e41b4fcad4619535f45f8bfa7744c4f384e1648",
"shasum": ""
},
"require": {
@ -3965,7 +4147,7 @@
],
"description": "Symfony HttpFoundation Component",
"homepage": "https://symfony.com",
"time": "2020-03-30T14:07:33+00:00"
"time": "2020-02-13T19:40:01+00:00"
},
{
"name": "symfony/http-kernel",
@ -4059,16 +4241,16 @@
},
{
"name": "symfony/mime",
"version": "v5.0.7",
"version": "v5.0.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/mime.git",
"reference": "481b7d6da88922fb1e0d86a943987722b08f3955"
"reference": "9b3e5b5e58c56bbd76628c952d2b78556d305f3c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/mime/zipball/481b7d6da88922fb1e0d86a943987722b08f3955",
"reference": "481b7d6da88922fb1e0d86a943987722b08f3955",
"url": "https://api.github.com/repos/symfony/mime/zipball/9b3e5b5e58c56bbd76628c952d2b78556d305f3c",
"reference": "9b3e5b5e58c56bbd76628c952d2b78556d305f3c",
"shasum": ""
},
"require": {
@ -4117,7 +4299,7 @@
"mime",
"mime-type"
],
"time": "2020-03-27T16:56:45+00:00"
"time": "2020-02-04T09:41:09+00:00"
},
{
"name": "symfony/polyfill-ctype",
@ -4238,16 +4420,16 @@
},
{
"name": "symfony/polyfill-intl-idn",
"version": "v1.15.0",
"version": "v1.14.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-idn.git",
"reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf"
"reference": "6842f1a39cf7d580655688069a03dd7cd83d244a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf",
"reference": "47bd6aa45beb1cd7c6a16b7d1810133b728bdfcf",
"url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/6842f1a39cf7d580655688069a03dd7cd83d244a",
"reference": "6842f1a39cf7d580655688069a03dd7cd83d244a",
"shasum": ""
},
"require": {
@ -4261,7 +4443,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.15-dev"
"dev-master": "1.14-dev"
}
},
"autoload": {
@ -4296,20 +4478,20 @@
"portable",
"shim"
],
"time": "2020-03-09T19:04:49+00:00"
"time": "2020-01-17T12:01:36+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.15.0",
"version": "v1.14.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac"
"reference": "34094cfa9abe1f0f14f48f490772db7a775559f2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/81ffd3a9c6d707be22e3012b827de1c9775fc5ac",
"reference": "81ffd3a9c6d707be22e3012b827de1c9775fc5ac",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/34094cfa9abe1f0f14f48f490772db7a775559f2",
"reference": "34094cfa9abe1f0f14f48f490772db7a775559f2",
"shasum": ""
},
"require": {
@ -4321,7 +4503,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.15-dev"
"dev-master": "1.14-dev"
}
},
"autoload": {
@ -4355,7 +4537,7 @@
"portable",
"shim"
],
"time": "2020-03-09T19:04:49+00:00"
"time": "2020-01-13T11:15:53+00:00"
},
{
"name": "symfony/polyfill-php56",
@ -4415,16 +4597,16 @@
},
{
"name": "symfony/polyfill-php72",
"version": "v1.15.0",
"version": "v1.14.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php72.git",
"reference": "37b0976c78b94856543260ce09b460a7bc852747"
"reference": "46ecacf4751dd0dc81e4f6bf01dbf9da1dc1dadf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/37b0976c78b94856543260ce09b460a7bc852747",
"reference": "37b0976c78b94856543260ce09b460a7bc852747",
"url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/46ecacf4751dd0dc81e4f6bf01dbf9da1dc1dadf",
"reference": "46ecacf4751dd0dc81e4f6bf01dbf9da1dc1dadf",
"shasum": ""
},
"require": {
@ -4433,7 +4615,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.15-dev"
"dev-master": "1.14-dev"
}
},
"autoload": {
@ -4466,7 +4648,7 @@
"portable",
"shim"
],
"time": "2020-02-27T09:26:54+00:00"
"time": "2020-01-13T11:15:53+00:00"
},
{
"name": "symfony/polyfill-php73",
@ -5156,74 +5338,6 @@
}
],
"packages-dev": [
{
"name": "barryvdh/laravel-debugbar",
"version": "v3.2.9",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-debugbar.git",
"reference": "42d5da5379a7860093f8e4032167e4cb5ebec180"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/42d5da5379a7860093f8e4032167e4cb5ebec180",
"reference": "42d5da5379a7860093f8e4032167e4cb5ebec180",
"shasum": ""
},
"require": {
"illuminate/routing": "^5.5|^6|^7",
"illuminate/session": "^5.5|^6|^7",
"illuminate/support": "^5.5|^6|^7",
"maximebf/debugbar": "^1.15.1",
"php": ">=7.0",
"symfony/debug": "^3|^4|^5",
"symfony/finder": "^3|^4|^5"
},
"require-dev": {
"laravel/framework": "5.5.x"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.2-dev"
},
"laravel": {
"providers": [
"Barryvdh\\Debugbar\\ServiceProvider"
],
"aliases": {
"Debugbar": "Barryvdh\\Debugbar\\Facade"
}
}
},
"autoload": {
"psr-4": {
"Barryvdh\\Debugbar\\": "src/"
},
"files": [
"src/helpers.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "PHP Debugbar integration for Laravel",
"keywords": [
"debug",
"debugbar",
"laravel",
"profiler",
"webprofiler"
],
"time": "2020-02-25T20:42:23+00:00"
},
{
"name": "behat/gherkin",
"version": "v4.6.1",
@ -5621,20 +5735,20 @@
},
{
"name": "codeception/module-webdriver",
"version": "1.0.5",
"version": "1.0.7",
"source": {
"type": "git",
"url": "https://github.com/Codeception/module-webdriver.git",
"reference": "cfeadb39170aa80e6fe244de6a130453edd79fe9"
"reference": "f05c5c25e39d10fbfb2d508779e1537df019ff9b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Codeception/module-webdriver/zipball/cfeadb39170aa80e6fe244de6a130453edd79fe9",
"reference": "cfeadb39170aa80e6fe244de6a130453edd79fe9",
"url": "https://api.github.com/repos/Codeception/module-webdriver/zipball/f05c5c25e39d10fbfb2d508779e1537df019ff9b",
"reference": "f05c5c25e39d10fbfb2d508779e1537df019ff9b",
"shasum": ""
},
"require": {
"codeception/codeception": "4.0.x-dev | ^4.0",
"codeception/codeception": "^4.0",
"php": ">=5.6.0 <8.0",
"php-webdriver/webdriver": "^1.6.0"
},
@ -5672,7 +5786,7 @@
"browser-testing",
"codeception"
],
"time": "2020-03-06T08:39:02+00:00"
"time": "2020-04-01T10:18:18+00:00"
},
{
"name": "codeception/phpunit-wrapper",
@ -5865,56 +5979,6 @@
],
"time": "2020-01-15T10:00:00+00:00"
},
{
"name": "fzaninotto/faker",
"version": "v1.9.1",
"source": {
"type": "git",
"url": "https://github.com/fzaninotto/Faker.git",
"reference": "fc10d778e4b84d5bd315dad194661e091d307c6f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fzaninotto/Faker/zipball/fc10d778e4b84d5bd315dad194661e091d307c6f",
"reference": "fc10d778e4b84d5bd315dad194661e091d307c6f",
"shasum": ""
},
"require": {
"php": "^5.3.3 || ^7.0"
},
"require-dev": {
"ext-intl": "*",
"phpunit/phpunit": "^4.8.35 || ^5.7",
"squizlabs/php_codesniffer": "^2.9.2"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.9-dev"
}
},
"autoload": {
"psr-4": {
"Faker\\": "src/Faker/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "François Zaninotto"
}
],
"description": "Faker is a PHP library that generates fake data for you.",
"keywords": [
"data",
"faker",
"fixtures"
],
"time": "2019-12-12T13:22:17+00:00"
},
{
"name": "hamcrest/hamcrest-php",
"version": "v2.0.0",
@ -5963,67 +6027,6 @@
],
"time": "2016-01-20T08:20:44+00:00"
},
{
"name": "maximebf/debugbar",
"version": "v1.16.1",
"source": {
"type": "git",
"url": "https://github.com/maximebf/php-debugbar.git",
"reference": "58998b818c6567fac01e35b8a4b70c1a64530556"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/58998b818c6567fac01e35b8a4b70c1a64530556",
"reference": "58998b818c6567fac01e35b8a4b70c1a64530556",
"shasum": ""
},
"require": {
"php": "^7.1",
"psr/log": "^1.0",
"symfony/var-dumper": "^2.6|^3|^4|^5"
},
"require-dev": {
"phpunit/phpunit": "^5"
},
"suggest": {
"kriswallsmith/assetic": "The best way to manage assets",
"monolog/monolog": "Log using Monolog",
"predis/predis": "Redis storage"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.16-dev"
}
},
"autoload": {
"psr-4": {
"DebugBar\\": "src/DebugBar/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Maxime Bouroumeau-Fuseau",
"email": "maxime.bouroumeau@gmail.com",
"homepage": "http://maximebf.com"
},
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "Debug bar in the browser for php application",
"homepage": "https://github.com/maximebf/php-debugbar",
"keywords": [
"debug",
"debugbar"
],
"time": "2019-11-24T09:46:11+00:00"
},
{
"name": "mockery/mockery",
"version": "1.3.1",
@ -7767,5 +7770,6 @@
"ext-pdo_mysql": "*",
"ext-tokenizer": "*"
},
"platform-dev": []
"platform-dev": [],
"plugin-api-version": "1.1.0"
}

View File

@ -3,6 +3,7 @@
namespace Webkul\Admin\DataGrids;
use Illuminate\Support\Facades\DB;
use Webkul\Customer\Models\CustomerAddress;
use Webkul\Ui\DataGrid\DataGrid;
use Webkul\Customer\Repositories\CustomerRepository;
@ -43,10 +44,11 @@ class AddressDataGrid extends DataGrid
{
$customer = $this->customerRepository->find(request('id'));
$queryBuilder = DB::table('customer_addresses as ca')
$queryBuilder = DB::table('addresses as ca')
->leftJoin('countries', 'ca.country', '=', 'countries.code')
->leftJoin('customers as c', 'ca.customer_id', '=', 'c.id')
->addSelect('ca.id as address_id', 'ca.company_name', 'ca.address1', 'ca.country', DB::raw('' . DB::getTablePrefix() . 'countries.name as country_name'), 'ca.state', 'ca.city', 'ca.postcode', 'ca.phone', 'ca.default_address')
->where('ca.address_type', CustomerAddress::ADDRESS_TYPE)
->where('c.id', $customer->id);
$queryBuilder = $queryBuilder->leftJoin('country_states', function($qb) {

View File

@ -3,6 +3,7 @@
namespace Webkul\Admin\DataGrids;
use Illuminate\Support\Facades\DB;
use Webkul\Sales\Models\OrderAddress;
use Webkul\Ui\DataGrid\DataGrid;
class OrderDataGrid extends DataGrid
@ -14,13 +15,13 @@ class OrderDataGrid extends DataGrid
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('orders')
->leftJoin('order_address as order_address_shipping', function($leftJoin) {
->leftJoin('addresses as order_address_shipping', function($leftJoin) {
$leftJoin->on('order_address_shipping.order_id', '=', 'orders.id')
->where('order_address_shipping.address_type', 'shipping');
->where('order_address_shipping.address_type', OrderAddress::ADDRESS_TYPE_SHIPPING);
})
->leftJoin('order_address as order_address_billing', function($leftJoin) {
->leftJoin('addresses as order_address_billing', function($leftJoin) {
$leftJoin->on('order_address_billing.order_id', '=', 'orders.id')
->where('order_address_billing.address_type', 'billing');
->where('order_address_billing.address_type', OrderAddress::ADDRESS_TYPE_BILLING);
})
->addSelect('orders.id','orders.increment_id', 'orders.base_sub_total', 'orders.base_grand_total', 'orders.created_at', 'channel_name', 'status')
->addSelect(DB::raw('CONCAT(' . DB::getTablePrefix() . 'order_address_billing.first_name, " ", ' . DB::getTablePrefix() . 'order_address_billing.last_name) as billed_to'))

View File

@ -3,6 +3,7 @@
namespace Webkul\Admin\DataGrids;
use Illuminate\Support\Facades\DB;
use Webkul\Sales\Models\OrderAddress;
use Webkul\Ui\DataGrid\DataGrid;
class OrderRefundDataGrid extends DataGrid
@ -16,9 +17,9 @@ class OrderRefundDataGrid extends DataGrid
$queryBuilder = DB::table('refunds')
->select('refunds.id', 'orders.increment_id', 'refunds.state', 'refunds.base_grand_total', 'refunds.created_at')
->leftJoin('orders', 'refunds.order_id', '=', 'orders.id')
->leftJoin('order_address as order_address_billing', function($leftJoin) {
->leftJoin('addresses as order_address_billing', function($leftJoin) {
$leftJoin->on('order_address_billing.order_id', '=', 'orders.id')
->where('order_address_billing.address_type', 'billing');
->where('order_address_billing.address_type', OrderAddress::ADDRESS_TYPE_BILLING);
})
->addSelect(DB::raw('CONCAT(' . DB::getTablePrefix() . 'order_address_billing.first_name, " ", ' . DB::getTablePrefix() . 'order_address_billing.last_name) as billed_to'));

View File

@ -3,6 +3,7 @@
namespace Webkul\Admin\DataGrids;
use Illuminate\Support\Facades\DB;
use Webkul\Sales\Models\OrderAddress;
use Webkul\Ui\DataGrid\DataGrid;
class OrderShipmentsDataGrid extends DataGrid
@ -14,9 +15,9 @@ class OrderShipmentsDataGrid extends DataGrid
public function prepareQueryBuilder()
{
$queryBuilder = DB::table('shipments')
->leftJoin('order_address as order_address_shipping', function($leftJoin) {
->leftJoin('addresses as order_address_shipping', function($leftJoin) {
$leftJoin->on('order_address_shipping.order_id', '=', 'shipments.order_id')
->where('order_address_shipping.address_type', 'shipping');
->where('order_address_shipping.address_type', OrderAddress::ADDRESS_TYPE_SHIPPING);
})
->leftJoin('orders as ors', 'shipments.order_id', '=', 'ors.id')
->leftJoin('inventory_sources as is', 'shipments.inventory_source_id', '=', 'is.id')

View File

@ -658,7 +658,7 @@ class Cart
if (! $cart = $this->getCart()) {
return;
}
Event::dispatch('checkout.cart.calculate.items.tax.before', $cart);
foreach ($cart->items()->get() as $item) {
@ -1199,21 +1199,21 @@ class Cart
} else {
if (isset($billingAddressData['use_for_shipping']) && $billingAddressData['use_for_shipping']) {
$this->cartAddressRepository->create(array_merge($billingAddressData,
['address_type' => 'shipping']));
['address_type' => CartAddress::ADDRESS_TYPE_SHIPPING]));
} else {
$this->cartAddressRepository->create(array_merge($shippingAddressData,
['address_type' => 'shipping']));
['address_type' => CartAddress::ADDRESS_TYPE_SHIPPING]));
}
}
}
} else {
$this->cartAddressRepository->create(array_merge($billingAddressData, ['address_type' => 'billing']));
$this->cartAddressRepository->create(array_merge($billingAddressData, ['address_type' => CartAddress::ADDRESS_TYPE_BILLING]));
if ($cart->haveStockableItems()) {
if (isset($billingAddressData['use_for_shipping']) && $billingAddressData['use_for_shipping']) {
$this->cartAddressRepository->create(array_merge($billingAddressData, ['address_type' => 'shipping']));
$this->cartAddressRepository->create(array_merge($billingAddressData, ['address_type' => CartAddress::ADDRESS_TYPE_SHIPPING]));
} else {
$this->cartAddressRepository->create(array_merge($shippingAddressData, ['address_type' => 'shipping']));
$this->cartAddressRepository->create(array_merge($shippingAddressData, ['address_type' => CartAddress::ADDRESS_TYPE_SHIPPING]));
}
}
}

View File

@ -6,14 +6,10 @@ use Faker\Generator as Faker;
use Webkul\Checkout\Models\CartAddress;
$factory->define(CartAddress::class, function (Faker $faker) {
$now = date("Y-m-d H:i:s");
return [
'first_name' => $faker->firstName(),
'last_name' => $faker->lastName,
'email' => $faker->email,
'created_at' => $now,
'updated_at' => $now,
'address_type' => 'billing',
'address_type' => CartAddress::ADDRESS_TYPE_BILLING,
];
});

View File

@ -48,7 +48,7 @@ class Cart extends Model implements CartContract
*/
public function billing_address()
{
return $this->addresses()->where('address_type', 'billing');
return $this->addresses()->where('address_type', CartAddress::ADDRESS_TYPE_BILLING);
}
/**
@ -64,7 +64,7 @@ class Cart extends Model implements CartContract
*/
public function shipping_address()
{
return $this->addresses()->where('address_type', 'shipping');
return $this->addresses()->where('address_type', CartAddress::ADDRESS_TYPE_SHIPPING);
}
/**

View File

@ -2,30 +2,47 @@
namespace Webkul\Checkout\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Webkul\Checkout\Contracts\CartAddress as CartAddressContract;
use Webkul\Core\Models\Address;
class CartAddress extends Model implements CartAddressContract
/**
* Class CartAddress
* @package Webkul\Checkout\Models
*
* @property integer $cart_id
* @property Cart $cart
*
*/
class CartAddress extends Address implements CartAddressContract
{
protected $table = 'cart_address';
public const ADDRESS_TYPE_SHIPPING = 'cart_shipping';
public const ADDRESS_TYPE_BILLING = 'cart_billing';
protected $fillable = [
'first_name',
'last_name',
'email',
'company_name',
'vat_id',
'address1',
'city',
'state',
'postcode',
'country',
'phone',
'address_type',
'cart_id',
'customer_id',
/**
* @var array default values
*/
protected $attributes = [
'address_type' => self::ADDRESS_TYPE_BILLING,
];
/**
* The "booted" method of the model.
*
* @return void
*/
protected static function boot()
{
static::addGlobalScope('address_type', static function (Builder $builder) {
$builder->whereIn('address_type', [
self::ADDRESS_TYPE_BILLING,
self::ADDRESS_TYPE_SHIPPING
]);
});
parent::boot();
}
/**
* Get the shipping rates for the cart address.
*/
@ -35,10 +52,10 @@ class CartAddress extends Model implements CartAddressContract
}
/**
* Get all of the attributes for the attribute groups.
* Get the cart record associated with the address.
*/
public function getNameAttribute()
public function cart()
{
return $this->first_name . ' ' . $this->last_name;
return $this->belongsTo(Cart::class);
}
}

View File

@ -24,6 +24,7 @@ class CartShippingRate extends Model implements CartShippingRateContract
*/
public function shipping_address()
{
return $this->belongsTo(CartAddressProxy::modelClass());
return $this->belongsTo(CartAddressProxy::modelClass(), 'cart_address_id')
->where('address_type', CartAddress::ADDRESS_TYPE_SHIPPING);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace App\Console\Commands;
namespace Webkul\Core\Console\Commands;
use Illuminate\Console\Command;

View File

@ -1,12 +1,12 @@
<?php
namespace App\Console\Commands;
namespace Webkul\Core\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Artisan;
class install extends Command
class Install extends Command
{
/**
* The name and signature of the console command.

View File

@ -0,0 +1,39 @@
<?php
use Faker\Generator as Faker;
use Webkul\Category\Models\Category;
use Webkul\Core\Models\Channel;
use Webkul\Core\Models\Currency;
use Webkul\Core\Models\Locale;
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(Channel::class, function (Faker $faker, array $attributes) {
$seoTitle = $attributes['seo_title'] ?? $faker->word;
$seoDescription = $attributes['seo_description'] ?? $faker->words(10, true);
$seoKeywords = $attributes['seo_keywords'] ?? $faker->words(3, true);
$seoData = [
'meta_title' => $seoTitle,
'meta_description' => $seoDescription,
'meta_keywords' => $seoKeywords,
];
unset($attributes['seo_title'], $attributes['seo_description'], $attributes['seo_keywords']);
return [
'code' => $faker->unique()->word,
'name' => $faker->word,
'default_locale_id' => function () {
return factory(Locale::class)->create()->id;
},
'base_currency_id' => function () {
return factory(Currency::class)->create()->id;
},
'root_category_id' => function () {
return factory(Category::class)->create()->id;
},
'home_seo' => json_encode($seoData),
];
});

View File

@ -0,0 +1,10 @@
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define('channel_inventory_sources', function () {
return [
'channel_id' => core()->getCurrentChannel()->id,
'inventory_source_id' => 1,
];
});

View File

@ -0,0 +1,294 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Webkul\Checkout\Models\CartAddress;
use Webkul\Checkout\Models\CartShippingRate;
use Webkul\Sales\Models\Invoice;
use Webkul\Sales\Models\OrderAddress;
use Webkul\Sales\Models\Shipment;
class AddTableAddresses extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
try {
// transaction is important to prevent loosing data on failure
DB::beginTransaction();
Schema::create('addresses', function (Blueprint $table) {
$table->increments('id');
$table->string('address_type');
$table->unsignedInteger('customer_id')->nullable()->comment('null if guest checkout');
$table->unsignedInteger('cart_id')->nullable()->comment('only for cart_addresses');
$table->unsignedInteger('order_id')->nullable()->comment('only for order_addresses');
$table->string('first_name');
$table->string('last_name');
$table->string('gender')->nullable();
$table->string('company_name')->nullable();
$table->string('address1');
$table->string('address2')->nullable();
$table->string('postcode');
$table->string('city');
$table->string('state');
$table->string('country');
$table->string('email')->nullable();
$table->string('phone')->nullable();
$table->string('vat_id')->nullable();
$table->boolean('default_address')
->default(false)
->comment('only for customer_addresses');
$table->json('additional')->nullable();
$table->timestamps();
$table->foreign(['customer_id'])->references('id')->on('customers')->onDelete('cascade');
$table->foreign(['cart_id'])->references('id')->on('cart')->onDelete('cascade');
$table->foreign(['order_id'])->references('id')->on('orders')->onDelete('cascade');
});
Schema::disableForeignKeyConstraints();
$this->migrateCustomerAddresses();
$this->migrateCartAddresses();
$this->migrateOrderAddresses();
$this->migrateForeignKeys();
Schema::drop('customer_addresses');
Schema::drop('cart_address');
Schema::drop('order_address');
Schema::enableForeignKeyConstraints();
DB::commit();
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
throw new Exception('you cannot revert this migration: data would be lost');
}
private function migrateCustomerAddresses(): void
{
$dbPrefix = DB::getTablePrefix();
$insertCustomerAddresses = <<< SQL
INSERT INTO ${dbPrefix}addresses(
address_type,
customer_id,
first_name,
last_name,
gender,
company_name,
address1,
address2,
postcode,
city,
state,
country,
email,
phone,
default_address,
additional,
created_at,
updated_at
)
SELECT
"customer",
customer_id,
first_name,
last_name,
(SELECT gender FROM customers c WHERE c.id=ca.customer_id),
company_name,
address1,
address2,
postcode,
city,
state,
country,
null,
phone,
default_address,
JSON_INSERT('{}', '$.old_customer_address_id', id),
created_at,
updated_at
FROM customer_addresses ca;
SQL;
DB::unprepared($insertCustomerAddresses);
}
private function migrateCartAddresses(): void
{
$dbPrefix = DB::getTablePrefix();
$insertCustomerAddresses = <<< SQL
INSERT INTO ${dbPrefix}addresses(
address_type,
customer_id,
cart_id,
first_name,
last_name,
gender,
company_name,
address1,
address2,
postcode,
city,
state,
country,
email,
phone,
additional,
created_at,
updated_at
)
SELECT
(CASE WHEN ca.address_type='billing' THEN "cart_billing" ELSE "cart_shipping" END),
customer_id,
cart_id,
first_name,
last_name,
(SELECT gender FROM customers c WHERE c.id=ca.customer_id),
company_name,
address1,
address2,
postcode,
city,
state,
country,
email,
phone,
JSON_INSERT('{}', '$.old_cart_address_id', id),
created_at,
updated_at
FROM cart_address ca;
SQL;
DB::unprepared($insertCustomerAddresses);
}
private function migrateOrderAddresses(): void
{
$dbPrefix = DB::getTablePrefix();
$insertCustomerAddresses = <<< SQL
INSERT INTO ${dbPrefix}addresses(
address_type,
customer_id,
order_id,
first_name,
last_name,
gender,
company_name,
address1,
address2,
postcode,
city,
state,
country,
email,
phone,
additional,
created_at,
updated_at
)
SELECT
(CASE WHEN oa.address_type='billing' THEN "order_billing" ELSE "order_shipping" END),
customer_id,
order_id,
first_name,
last_name,
(SELECT gender FROM customers c WHERE c.id=oa.customer_id),
company_name,
address1,
address2,
postcode,
city,
state,
country,
email,
phone,
JSON_INSERT('{}', '$.old_order_address_id', id),
created_at,
updated_at
FROM order_address oa;
SQL;
DB::unprepared($insertCustomerAddresses);
}
private function migrateForeignKeys(): void
{
Schema::table('cart_shipping_rates', static function (Blueprint $table) {
$table->dropForeign(['cart_address_id']);
CartAddress::query()
->orderBy('id', 'asc') // for some reason each() needs an orderBy in before
->each(static function ($row) {
CartShippingRate::query()
->where('cart_address_id', $row->additional['old_cart_address_id'])
->update(['cart_address_id' => $row->id]);
});
$table->foreign(['cart_address_id'])
->references('id')
->on('addresses')
->onDelete('cascade');
});
Schema::table('invoices', static function (Blueprint $table) {
$table->dropForeign(['order_address_id']);
OrderAddress::query()
->orderBy('id', 'asc') // for some reason each() needs an orderBy in before
->each(static function ($row) {
Invoice::query()
->where('order_address_id', $row->additional['old_order_address_id'])
->update(['order_address_id' => $row->id]);
});
$table->foreign(['order_address_id'])
->references('id')
->on('addresses')
->onDelete('cascade');
});
Schema::table('shipments', static function (Blueprint $table) {
$table->dropForeign(['order_address_id']);
OrderAddress::query()
->orderBy('id', 'asc') // for some reason each() needs an orderBy in before
->each(static function ($row) {
Shipment::query()
->where('order_address_id', $row->additional['old_order_address_id'])
->update(['order_address_id' => $row->id]);
});
$table->foreign(['order_address_id'])
->references('id')
->on('addresses')
->onDelete('cascade');
});
}
}

View File

@ -0,0 +1,91 @@
<?php
namespace Webkul\Core\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Webkul\Customer\Models\Customer;
/**
* Class Address
* @package Webkul\Core\Models
*
* @property string $address_type
* @property integer $customer_id
* @property Customer $customer
* @property string $first_name
* @property string $last_name
* @property string $gender
* @property string $company_name
* @property string $address1
* @property string $address2
* @property string $postcode
* @property string $city
* @property string $state
* @property string $country
* @property string $email
* @property string $phone
* @property boolean $default_address
* @property array $additional
*
* @property-read integer $id
* @property-read string $name
* @property-read Carbon $created_at
* @property-read Carbon $updated_at
*
*/
abstract class Address extends Model
{
protected $table = 'addresses';
protected $guarded = [
'id',
'created_at',
'updated_at',
];
protected $fillable = [
'address_type',
'customer_id',
'cart_id',
'order_id',
'first_name',
'last_name',
'gender',
'company_name',
'address1',
'address2',
'postcode',
'city',
'state',
'country',
'email',
'phone',
'default_address',
'vat_id',
'additional',
];
protected $casts = [
'additional' => 'array',
];
/**
* Get all of the attributes for the attribute groups.
*/
public function getNameAttribute(): string
{
return $this->first_name . ' ' . $this->last_name;
}
/**
* Get the customer record associated with the address.
*/
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
}
}

View File

@ -10,6 +10,8 @@ use Webkul\Core\Core;
use Webkul\Core\Facades\Core as CoreFacade;
use Webkul\Core\Models\SliderProxy;
use Webkul\Core\Observers\SliderObserver;
use Webkul\Core\Console\Commands\BagistoVersion;
use Webkul\Core\Console\Commands\Install;
class CoreServiceProvider extends ServiceProvider
{
@ -49,6 +51,8 @@ class CoreServiceProvider extends ServiceProvider
public function register()
{
$this->registerFacades();
$this->registerCommands();
}
/**
@ -66,6 +70,18 @@ class CoreServiceProvider extends ServiceProvider
});
}
/**
* Register the console commands of this package
*
* @return void
*/
protected function registerCommands(): void
{
if ($this->app->runningInConsole()) {
$this->commands([BagistoVersion::class, Install::class,]);
}
}
/**
* Register factories.
*

View File

@ -7,8 +7,6 @@ use Webkul\Customer\Models\Customer;
use Webkul\Customer\Models\CustomerAddress;
$factory->define(CustomerAddress::class, function (Faker $faker) {
$now = date("Y-m-d H:i:s");
// use an locale from a country in europe so the vat id can be generated
$fakerIt = \Faker\Factory::create('it_IT');
@ -27,8 +25,7 @@ $factory->define(CustomerAddress::class, function (Faker $faker) {
'postcode' => $faker->postcode,
'phone' => $faker->e164PhoneNumber,
'default_address' => array_random([0, 1]),
'created_at' => $now,
'updated_at' => $now,
'address_type' => CustomerAddress::ADDRESS_TYPE,
];
});

View File

@ -2,34 +2,32 @@
namespace Webkul\Customer\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Webkul\Core\Models\Address;
use Webkul\Customer\Contracts\CustomerAddress as CustomerAddressContract;
class CustomerAddress extends Model implements CustomerAddressContract
class CustomerAddress extends Address implements CustomerAddressContract
{
protected $table = 'customer_addresses';
public const ADDRESS_TYPE = 'customer';
protected $fillable = [
'customer_id',
'company_name',
'vat_id',
'address1',
'address2',
'country',
'state',
'city',
'postcode',
'phone',
'default_address',
'first_name',
'last_name',
/**
* @var array default values
*/
protected $attributes = [
'address_type' => self::ADDRESS_TYPE,
];
/**
* Get the customer address full name.
* The "booted" method of the model.
*
* @return void
*/
public function getNameAttribute()
protected static function boot()
{
return $this->first_name . ' ' . $this->last_name;
static::addGlobalScope('address_type', static function (Builder $builder) {
$builder->where('address_type', self::ADDRESS_TYPE);
});
parent::boot();
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace App\Console\Commands;
namespace Webkul\Product\Console\Commands;
use Illuminate\Console\Command;
use Webkul\Product\Helpers\GenerateProduct;

View File

@ -7,6 +7,7 @@ use Illuminate\Support\ServiceProvider;
use Webkul\Product\Models\ProductProxy;
use Webkul\Product\Observers\ProductObserver;
use Webkul\Product\Console\Commands\PriceUpdate;
use Webkul\Product\Console\Commands\GenerateProducts;
class ProductServiceProvider extends ServiceProvider
{
@ -64,7 +65,7 @@ class ProductServiceProvider extends ServiceProvider
protected function registerCommands(): void
{
if ($this->app->runningInConsole()) {
$this->commands([PriceUpdate::class,]);
$this->commands([PriceUpdate::class, GenerateProducts::class,]);
}
}

View File

@ -10,7 +10,7 @@ use Webkul\Sales\Models\OrderAddress;
$factory->define(OrderAddress::class, function (Faker $faker) {
$customer = factory(Customer::class)->create();
$customerAddress = factory(CustomerAddress::class)->create();
$customerAddress = factory(CustomerAddress::class)->make();
return [
'first_name' => $customer->first_name,
@ -22,7 +22,7 @@ $factory->define(OrderAddress::class, function (Faker $faker) {
'city' => $customerAddress->city,
'postcode' => $customerAddress->postcode,
'phone' => $customerAddress->phone,
'address_type' => 'billing',
'address_type' => OrderAddress::ADDRESS_TYPE_BILLING,
'order_id' => function () {
return factory(Order::class)->create()->id;
},
@ -30,5 +30,5 @@ $factory->define(OrderAddress::class, function (Faker $faker) {
});
$factory->state(OrderAddress::class, 'shipping', [
'address_type' => 'shipping',
'address_type' => OrderAddress::ADDRESS_TYPE_SHIPPING,
]);

View File

@ -7,10 +7,14 @@ use Webkul\Product\Models\Product;
use Webkul\Sales\Models\Order;
use Webkul\Sales\Models\OrderItem;
$factory->define(OrderItem::class, function (Faker $faker) {
$factory->define(OrderItem::class, function (Faker $faker, array $attributes) {
$now = date("Y-m-d H:i:s");
$product = factory(Product::class, 'simple')->create();
if (isset($attributes['product_id'])) {
$product = Product::where('id', $attributes['product_id'])->first();
} else {
$product = factory(Product::class)->create();
}
return [
'sku' => $product->sku,

View File

@ -34,7 +34,8 @@ class Invoice extends Model implements InvoiceContract
/**
* Get the invoice items record associated with the invoice.
*/
public function items() {
public function items()
{
return $this->hasMany(InvoiceItemProxy::modelClass())->whereNull('parent_id');
}
@ -55,10 +56,11 @@ class Invoice extends Model implements InvoiceContract
}
/**
* Get the addresses for the shipment.
* Get the address for the invoice.
*/
public function address()
{
return $this->belongsTo(OrderAddressProxy::modelClass(), 'order_address_id');
return $this->belongsTo(OrderAddressProxy::modelClass(), 'order_address_id')
->where('address_type', OrderAddress::ADDRESS_TYPE_BILLING);
}
}

View File

@ -8,6 +8,14 @@ use Webkul\Sales\Contracts\Order as OrderContract;
class Order extends Model implements OrderContract
{
public const STATUS_PENDING = 'pending';
public const STATUS_PENDING_PAYMENT = 'pending_payment';
public const STATUS_PROCESSING = 'processing';
public const STATUS_COMPLETED = 'completed';
public const STATUS_CANCELED = 'canceled';
public const STATUS_CLOSED = 'closed';
public const STATUS_FRAUD = 'fraud';
protected $guarded = [
'id',
'items',
@ -21,13 +29,13 @@ class Order extends Model implements OrderContract
];
protected $statusLabel = [
'pending' => 'Pending',
'pending_payment' => 'Pending Payment',
'processing' => 'Processing',
'completed' => 'Completed',
'canceled' => 'Canceled',
'closed' => 'Closed',
'fraud' => 'Fraud',
self::STATUS_PENDING => 'Pending',
self::STATUS_PENDING_PAYMENT => 'Pending Payment',
self::STATUS_PROCESSING => 'Processing',
self::STATUS_COMPLETED => 'Completed',
self::STATUS_CANCELED => 'Canceled',
self::STATUS_CLOSED => 'Closed',
self::STATUS_FRAUD => 'Fraud',
];
/**
@ -140,7 +148,7 @@ class Order extends Model implements OrderContract
*/
public function billing_address()
{
return $this->addresses()->where('address_type', 'billing');
return $this->addresses()->where('address_type', OrderAddress::ADDRESS_TYPE_BILLING);
}
/**
@ -156,7 +164,7 @@ class Order extends Model implements OrderContract
*/
public function shipping_address()
{
return $this->addresses()->where('address_type', 'shipping');
return $this->addresses()->where('address_type', OrderAddress::ADDRESS_TYPE_SHIPPING);
}
/**
@ -180,7 +188,7 @@ class Order extends Model implements OrderContract
*
* @return boolean
*/
public function haveStockableItems()
public function haveStockableItems(): bool
{
foreach ($this->items as $item) {
if ($item->getTypeInstance()->isStockable()) {
@ -193,10 +201,12 @@ class Order extends Model implements OrderContract
/**
* Checks if new shipment is allow or not
*
* @return bool
*/
public function canShip()
public function canShip(): bool
{
if ($this->status == 'fraud') {
if ($this->status === self::STATUS_FRAUD) {
return false;
}
@ -211,10 +221,12 @@ class Order extends Model implements OrderContract
/**
* Checks if new invoice is allow or not
*
* @return bool
*/
public function canInvoice()
public function canInvoice(): bool
{
if ($this->status == 'fraud') {
if ($this->status === self::STATUS_FRAUD) {
return false;
}
@ -229,10 +241,12 @@ class Order extends Model implements OrderContract
/**
* Checks if order can be canceled or not
*
* @return bool
*/
public function canCancel()
public function canCancel(): bool
{
if ($this->status == 'fraud') {
if ($this->status === self::STATUS_FRAUD) {
return false;
}
@ -247,10 +261,12 @@ class Order extends Model implements OrderContract
/**
* Checks if order can be refunded or not
*
* @return bool
*/
public function canRefund()
public function canRefund(): bool
{
if ($this->status == 'fraud') {
if ($this->status === self::STATUS_FRAUD) {
return false;
}

View File

@ -2,47 +2,64 @@
namespace Webkul\Sales\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Customer\Models\Customer;
use Webkul\Checkout\Models\CartAddress;
use Webkul\Core\Models\Address;
use Webkul\Sales\Contracts\OrderAddress as OrderAddressContract;
use Illuminate\Database\Eloquent\Builder;
class OrderAddress extends Model implements OrderAddressContract
/**
* Class OrderAddress
* @package Webkul\Sales\Models
*
* @property integer $order_id
* @property Order $order
*
*/
class OrderAddress extends Address implements OrderAddressContract
{
protected $table = 'order_address';
public const ADDRESS_TYPE_SHIPPING = 'order_shipping';
public const ADDRESS_TYPE_BILLING = 'order_billing';
protected $guarded = ['id', 'created_at', 'updated_at'];
protected $fillable = [
'first_name',
'last_name',
'email',
'company_name',
'vat_id',
'address1',
'address2',
'city',
'state',
'postcode',
'country',
'phone',
'address_type',
'cart_id',
'customer_id',
/**
* @var array default values
*/
protected $attributes = [
'address_type' => self::ADDRESS_TYPE_BILLING,
];
/**
* Get of the customer fullname.
* The "booted" method of the model.
*
* @return void
*/
public function getNameAttribute()
protected static function boot()
{
return $this->first_name . ' ' . $this->last_name;
static::addGlobalScope('address_type', function (Builder $builder) {
$builder->whereIn('address_type', [
self::ADDRESS_TYPE_BILLING,
self::ADDRESS_TYPE_SHIPPING
]);
});
static::creating(static function ($address) {
switch ($address->address_type) {
case CartAddress::ADDRESS_TYPE_BILLING:
$address->address_type = self::ADDRESS_TYPE_BILLING;
break;
case CartAddress::ADDRESS_TYPE_SHIPPING:
$address->address_type = self::ADDRESS_TYPE_SHIPPING;
break;
}
});
parent::boot();
}
/**
* Get the customer record associated with the order.
* Get the order record associated with the address.
*/
public function customer()
public function order()
{
return $this->belongsTo(Customer::class);
return $this->belongsTo(Order::class);
}
}

View File

@ -47,10 +47,11 @@ class Shipment extends Model implements ShipmentContract
}
/**
* Get the addresses for the shipment.
* Get the address for the shipment.
*/
public function address()
{
return $this->belongsTo(OrderAddressProxy::modelClass(), 'order_address_id');
return $this->belongsTo(OrderAddressProxy::modelClass(), 'order_address_id')
->where('address_type', OrderAddress::ADDRESS_TYPE_SHIPPING);
}
}

View File

@ -23,7 +23,7 @@ class FlatRate extends AbstractShipping
/**
* Returns rate for flatrate
*
* @return array
* @return CartShippingRate|false
*/
public function calculate()
{

View File

@ -22,7 +22,7 @@ class Free extends AbstractShipping
/**
* Returns rate for flatrate
*
* @return array
* @return CartShippingRate|false
*/
public function calculate()
{

View File

@ -67,13 +67,13 @@ class OrderCest
$I->seeResponseCodeIsSuccessful();
$I->seeRecord(CartAddress::class, array_merge($addressData, [
'address_type' => 'shipping',
'address_type' => CartAddress::ADDRESS_TYPE_SHIPPING,
'cart_id' => $mocks['cart']->id,
'customer_id' => $mocks['customer']->id,
]));
$I->seeRecord(CartAddress::class, array_merge($addressData, [
'address_type' => 'billing',
'address_type' => CartAddress::ADDRESS_TYPE_BILLING,
'cart_id' => $mocks['cart']->id,
'customer_id' => $mocks['customer']->id,
]));
@ -128,13 +128,13 @@ class OrderCest
$I->seeRecord(OrderAddress::class, array_merge($addressData, [
'order_id' => $order->id,
'address_type' => 'shipping',
'address_type' => OrderAddress::ADDRESS_TYPE_SHIPPING,
'customer_id' => $mocks['customer']->id,
]));
$I->seeRecord(OrderAddress::class, array_merge($addressData, [
'order_id' => $order->id,
'address_type' => 'billing',
'address_type' => OrderAddress::ADDRESS_TYPE_BILLING,
'customer_id' => $mocks['customer']->id,
]));

View File

@ -0,0 +1,108 @@
<?php
namespace Tests\Unit\Core;
use UnitTester;
use Webkul\Checkout\Models\Cart;
use Webkul\Checkout\Models\CartAddress;
use Webkul\Checkout\Models\CartShippingRate;
use Webkul\Customer\Models\Customer;
use Webkul\Customer\Models\CustomerAddress;
use Webkul\Sales\Models\Invoice;
use Webkul\Sales\Models\Order;
use Webkul\Sales\Models\OrderAddress;
use Webkul\Sales\Models\Shipment;
use Webkul\Shipping\Carriers\Free;
class AddressCest
{
public function testAddressFilters(UnitTester $I): void
{
$cartAddress = $I->have(CartAddress::class);
$customerAddress = $I->have(CustomerAddress::class);
$orderAddress = $I->have(OrderAddress::class);
$cartAddresses = CartAddress::all();
$I->assertCount(1, $cartAddresses);
$I->assertEquals($cartAddress->id, $cartAddresses[0]->id);
$customerAddresses = CustomerAddress::all();
$I->assertCount(1, $customerAddresses);
$I->assertEquals($customerAddress->id, $customerAddresses[0]->id);
$orderAddresses = OrderAddress::all();
$I->assertCount(1, $orderAddresses);
$I->assertEquals($orderAddress->id, $orderAddresses[0]->id);
}
public function testCustomerAddressRelations(UnitTester $I): void
{
/** @var Customer $customer1 */
$customer1 = $I->have(Customer::class);
CustomerAddress::create(['customer_id' => $customer1->id]);
/** @var Customer $customer2 */
$customer2 = $I->have(Customer::class);
$address1 = CustomerAddress::create(['customer_id' => $customer2->id]);
$customer2->refresh();
$I->assertCount(1, $customer2->addresses);
$I->assertEquals($address1->id, $customer2->addresses[0]->id);
$I->assertNull($customer2->default_address);
$address2 = CustomerAddress::create(['customer_id' => $customer2->id, 'default_address' => true]);
$customer2->refresh();
$I->assertCount(2, $customer2->addresses);
$I->assertEquals($address2->id, $customer2->default_address->id);
}
public function testCartAddressRelations(UnitTester $I): void
{
/** @var Cart $cart */
$cart = $I->have(Cart::class);
$address1 = CartAddress::create(['cart_id' => $cart->id]);
$address2 = CartAddress::create([
'cart_id' => $cart->id,
'address_type' => CartAddress::ADDRESS_TYPE_SHIPPING
]);
$cart->refresh();
$I->assertNotNull($address1->address_type);
$I->assertEquals($address1->id, $cart->billing_address->id);
$I->assertEquals($address2->id, $cart->shipping_address->id);
/** @var CartShippingRate $freeShipping */
$freeShipping = (new Free())->calculate();
$freeShipping->cart_address_id = $address2->id;
$freeShipping->saveOrFail();
$freeShipping->refresh();
$I->assertEquals($address2->id, $freeShipping->shipping_address->id);
}
public function testOrderAddressRelations(UnitTester $I): void
{
/** @var Order $order */
$order = $I->have(Order::class);
$address1 = OrderAddress::create(['order_id' => $order->id]);
$address2 = OrderAddress::create([
'order_id' => $order->id,
'address_type' => OrderAddress::ADDRESS_TYPE_SHIPPING
]);
$order->refresh();
$I->assertNotNull($address1->address_type);
$I->assertEquals($address1->id, $order->billing_address->id);
$I->assertEquals($address2->id, $order->shipping_address->id);
/** @var Shipment $shipment */
$shipment = Shipment::create(['order_address_id' => $address2->id]);
$I->assertEquals($address2->id, $shipment->address->id);
/** @var Invoice $invoice */
$invoice = Invoice::create(['order_id' => $order->id, 'order_address_id' => $address1->id]);
$I->assertEquals($address1->id, $invoice->address->id);
}
}