Skip to content

Commit

Permalink
セッションの保存/復元方法を修正
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess authored and kazumi_watanabe committed May 10, 2019
1 parent 91ed7e5 commit 5163d82
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
5 changes: 1 addition & 4 deletions src/Eccube/Controller/ShoppingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1046,10 +1046,7 @@ public function nonmember(Application $app, Request $request)
}

// 非会員用セッションを作成
$nonMember = array();
$nonMember['customer'] = $Customer;
$nonMember['pref'] = $Customer->getPref()->getId();
$app['session']->set($this->sessionKey, $nonMember);
$app['eccube.service.shopping']->setNonMember($this->sessionKey, $Customer);

$customerAddresses = array();
$customerAddresses[] = $CustomerAddress;
Expand Down
18 changes: 17 additions & 1 deletion src/Eccube/Service/ShoppingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,26 @@ public function getNonMember($sesisonKey)
}

$Customer = $nonMember['customer'];
$Customer->setPropertiesFromArray($nonMember, array('customer', 'id', 'pref', 'email', 'password', 'salt'));
$Customer->setPref($this->app['eccube.repository.master.pref']->find($nonMember['pref']));

return $Customer;
}

/**
* 非会員情報をセッションに設定する
*
* @param $sesisonKey
* @param Customer $Customer
* @return ShoppingService
*/
public function setNonMember($sessionKey, Customer $Customer)
{
$nonMember = $Customer->toArray(array('id', 'email', 'password', 'salt'));
$nonMember['pref'] = $Customer->getPref()->getId();
$nonMember['customer'] = $Customer; // Customer::serialize() で対象となっているプロパティのみ保存される
$this->app['session']->set($sessionKey, $nonMember);

return $this;
}

/**
Expand Down
29 changes: 29 additions & 0 deletions tests/Eccube/Tests/Service/ShoppingServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Eccube\Application;
use Eccube\Common\Constant;
use Eccube\Entity\Customer;
use Eccube\Entity\Master\Taxrule;
use Eccube\Entity\Shipping;
use Eccube\Exception\ShoppingException;
Expand Down Expand Up @@ -130,6 +131,34 @@ public function testGetNonMember()
$this->expected = $NonMember->getPref()->getId();
$this->actual = $Customer->getPref()->getId();
$this->verify('都道府県IDが一致するか');

$this->expected = $NonMember->getName01();
$this->actual = $Customer->getName01();
$this->verify('name01 が一致するか');
}

public function testSetNonMember()
{
$NonMember = $this->createNonMember();
$CopyNonMember = new Customer();
$CopyNonMember->copyProperties($NonMember);
$this->app['eccube.service.shopping']->setNonMember('eccube.front.shopping.nonmember', $CopyNonMember);

$Customer = $this->app['eccube.service.shopping']->getNonMember('eccube.front.shopping.nonmember');

$this->expected = $NonMember->getEmail();
$this->actual = $Customer->getEmail();
$this->verify('保存したメールアドレスが一致するか');

$this->expected = $NonMember->getPref()->getId();
$this->actual = $Customer->getPref()->getId();
$this->verify('保存した都道府県IDが一致するか');

$this->expected = $NonMember->getName01();
$this->actual = $Customer->getName01();
$this->verify('保存した name01 が一致するか');

$this->assertNotSame($Customer, $NonMember);
}

public function testGetDeliveries()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,12 @@ public function testNonmemberInputWithPost()
$this->assertNotNull($this->app['session']->get('eccube.front.shopping.nonmember.customeraddress'));

$this->expected = $formData['name']['name01'];
$this->actual = $Nonmember['customer']->getName01();
$this->verify();
$this->actual = $Nonmember['name01'];
$this->verify('name01はセッションに保存されているか');

$this->expected = $formData['email']['first'];
$this->actual = $Nonmember['customer']->getEmail();
$this->verify('Email はセッションから unserialize されているか');

$this->assertTrue($client->getResponse()->isRedirect($this->app->url('shopping')));
}
Expand Down

0 comments on commit 5163d82

Please sign in to comment.