coming along
This commit is contained in:
parent
59478fab17
commit
7d219d045a
|
|
@ -15,6 +15,9 @@
|
||||||
"phpunit/phpunit": "^10.1",
|
"phpunit/phpunit": "^10.1",
|
||||||
"cakephp/migrations": "^4.0.0"
|
"cakephp/migrations": "^4.0.0"
|
||||||
},
|
},
|
||||||
|
"suggest": {
|
||||||
|
"hi-powered-dev/cake-products": "Manage products and SKUs with a heirarhical category structure, includes attributes and variants"
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"CakeCarts\\": "src/"
|
"CakeCarts\\": "src/"
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ class CartItemsController extends AppController
|
||||||
}
|
}
|
||||||
// Log::debug(print_r('$newCartItem->getErrors()', true));
|
// Log::debug(print_r('$newCartItem->getErrors()', true));
|
||||||
// Log::debug(print_r($newCartItem->getErrors(), true));
|
// Log::debug(print_r($newCartItem->getErrors(), true));
|
||||||
dd(print_r($newCartItem->getErrors(), true));
|
|
||||||
$this->Flash->error('Failed to add to cart.');
|
$this->Flash->error('Failed to add to cart.');
|
||||||
|
|
||||||
return $this->redirect($this->referer([
|
return $this->redirect($this->referer([
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ enum CartTypeId: int implements EnumLabelInterface
|
||||||
return match($this) {
|
return match($this) {
|
||||||
self::Cart => 'Cart',
|
self::Cart => 'Cart',
|
||||||
self::Wishlist => 'Wishlist',
|
self::Wishlist => 'Wishlist',
|
||||||
self::CustomList => 'CustomList'
|
self::CustomList => 'List'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,40 @@ class CartItemsFixture extends TestFixture
|
||||||
'foreign_key' => null,
|
'foreign_key' => null,
|
||||||
'foreign_key_uuid' => 'e5efe749-d6b6-4f72-83c9-32b19936c70c',
|
'foreign_key_uuid' => 'e5efe749-d6b6-4f72-83c9-32b19936c70c',
|
||||||
'model' => 'ProductSkus',
|
'model' => 'ProductSkus',
|
||||||
'cart_id' => '21794607-f68e-424f-91ba-3230e2f92e2b',
|
'cart_id' => '74d1aa54-92a2-4039-bc10-61e1190c51ea',
|
||||||
|
'position' => 1,
|
||||||
|
'qty' => 1,
|
||||||
|
'price' => 1.5,
|
||||||
|
'subtotal' => 1.5,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => '74d1aa54-92a2-4039-ba10-61e1190c51eb',
|
||||||
|
'foreign_key' => null,
|
||||||
|
'foreign_key_uuid' => 'e5efe749-d6b6-4f72-83c9-32b19936c70c',
|
||||||
|
'model' => 'ProductSkus',
|
||||||
|
'cart_id' => '74d1aa54-92a2-4039-bc10-61e1190c51eb',
|
||||||
|
'position' => 1,
|
||||||
|
'qty' => 1,
|
||||||
|
'price' => 1.5,
|
||||||
|
'subtotal' => 1.5,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => '74d1aa54-92a2-4039-bc10-61e4190c51ec',
|
||||||
|
'foreign_key' => null,
|
||||||
|
'foreign_key_uuid' => 'e5efe749-d6b6-4f72-83c9-32b19936c70c',
|
||||||
|
'model' => 'ProductSkus',
|
||||||
|
'cart_id' => '74d1aa54-92a2-4039-bc10-61e1190c51ec',
|
||||||
|
'position' => 1,
|
||||||
|
'qty' => 1,
|
||||||
|
'price' => 1.5,
|
||||||
|
'subtotal' => 1.5,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => '79f66e8d-8d8d-4095-adc4-fd15234a4394',
|
||||||
|
'foreign_key' => null,
|
||||||
|
'foreign_key_uuid' => 'e5efe749-d6b6-4f72-83c9-32b19936c70c',
|
||||||
|
'model' => 'ProductSkus',
|
||||||
|
'cart_id' => '74d1aa54-92a2-4039-bc10-61e1190c51ed',
|
||||||
'position' => 1,
|
'position' => 1,
|
||||||
'qty' => 1,
|
'qty' => 1,
|
||||||
'price' => 1.5,
|
'price' => 1.5,
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,10 @@ class CartsFixture extends TestFixture
|
||||||
'removed_reason_id' => null,
|
'removed_reason_id' => null,
|
||||||
'num_items' => 1,
|
'num_items' => 1,
|
||||||
],
|
],
|
||||||
// normal cart - deleted
|
// wishlist cart - deleted
|
||||||
[
|
[
|
||||||
'id' => '74d1aa54-92a2-4039-bc10-61e1190c51ed',
|
'id' => '74d1aa54-92a2-4039-bc10-61e1190c51ed',
|
||||||
'cart_type_id' => CartTypeId::Cart->value,
|
'cart_type_id' => CartTypeId::Wishlist->value,
|
||||||
'session_id' => 'session_2',
|
'session_id' => 'session_2',
|
||||||
'user_id' => null,
|
'user_id' => null,
|
||||||
'user_id_uuid' => '5a34a6ae-7d3f-4dcf-bac7-57335b51e697',
|
'user_id_uuid' => '5a34a6ae-7d3f-4dcf-bac7-57335b51e697',
|
||||||
|
|
|
||||||
|
|
@ -62,16 +62,19 @@ class CartItemsControllerTest extends TestCase
|
||||||
$beforeCnt = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId])->count();
|
$beforeCnt = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId])->count();
|
||||||
$postData = [
|
$postData = [
|
||||||
'foreign_key' => null,
|
'foreign_key' => null,
|
||||||
'foreign_key_uuid' => '3a477e3e-7977-4813-81f6-f85949613979',
|
'foreign_key_uuid' => $skuId,
|
||||||
'model' => 'ProductSkus',
|
'model' => 'ProductSkus',
|
||||||
'qty' => 10,
|
'qty' => 10,
|
||||||
'price' => 0.75,
|
'price' => 0.75,
|
||||||
|
'subtotal' => 1,
|
||||||
];
|
];
|
||||||
$this->post($url, $postData);
|
$this->post($url, $postData);
|
||||||
$this->assertResponseCode(302);
|
$this->assertResponseCode(302);
|
||||||
$afterCnt = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId])->count();
|
$afterCnt = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId])->count();
|
||||||
|
|
||||||
$this->assertEquals($beforeCnt + 1, $afterCnt);
|
$this->assertEquals($beforeCnt + 1, $afterCnt);
|
||||||
|
|
||||||
|
$new = $this->CartItems->find()->where(['foreign_key_uuid' => $skuId, 'qty' => 10, 'model' => 'ProductSkus'])->firstOrFail();
|
||||||
|
$this->assertEquals(7.5, $new->subtotal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -82,7 +85,28 @@ class CartItemsControllerTest extends TestCase
|
||||||
*/
|
*/
|
||||||
public function testEdit(): void
|
public function testEdit(): void
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete('Not implemented yet.');
|
$id = '79f66e8d-8d8d-4095-adc4-fd15234a4397';
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeCarts',
|
||||||
|
'controller' => 'CartItems',
|
||||||
|
'action' => 'edit',
|
||||||
|
$id
|
||||||
|
];
|
||||||
|
$this->session(['Auth.User.id' => 1]);
|
||||||
|
$this->session(['Auth.id' => 1]);
|
||||||
|
$this->session(['CakeCarts.session_id' => 'session_1']);
|
||||||
|
$before = $this->CartItems->get($id, contain: ['Carts']);
|
||||||
|
// dd($before);
|
||||||
|
$skuId = '3a477e3e-7977-4813-81f6-f85949613979';
|
||||||
|
|
||||||
|
$postData = [
|
||||||
|
'qty' => 100,
|
||||||
|
];
|
||||||
|
$this->post($url, $postData);
|
||||||
|
$this->assertResponseCode(302);
|
||||||
|
|
||||||
|
$new = $this->CartItems->get($id);
|
||||||
|
$this->assertEquals(100, $new->qty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,31 @@ use CakeCarts\Controller\CartsController;
|
||||||
class CartsControllerTest extends TestCase
|
class CartsControllerTest extends TestCase
|
||||||
{
|
{
|
||||||
use IntegrationTestTrait;
|
use IntegrationTestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test subject
|
||||||
|
*
|
||||||
|
* @var \CakeCarts\Model\Table\CartItemsTable
|
||||||
|
*/
|
||||||
|
protected $Carts;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp(); // TODO: Change the autogenerated stub
|
||||||
|
|
||||||
|
$config = $this->getTableLocator()->exists('Carts') ? [] : ['className' => CartsTable::class];
|
||||||
|
$this->Carts = $this->getTableLocator()->get('Carts', $config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndex(): void
|
||||||
|
{
|
||||||
|
$url = [
|
||||||
|
'plugin' => 'CakeCarts',
|
||||||
|
'controller' => 'Carts',
|
||||||
|
'action' => 'index',
|
||||||
|
];
|
||||||
|
$this->get($url);
|
||||||
|
|
||||||
|
$this->assertResponseCode(200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue