Skip to content

Commit

Permalink
Merge pull request #4168 from kazumiiiiiiiiiii/3.0.18_fix
Browse files Browse the repository at this point in the history
非会員購入時のSessionの扱い方を修正
  • Loading branch information
Kiyotaka Oku authored May 23, 2019
2 parents ccd3bc0 + e59b294 commit 525aaa9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
34 changes: 23 additions & 11 deletions src/Eccube/Controller/ShoppingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1048,9 +1048,14 @@ public function nonmember(Application $app, Request $request)
// 非会員用セッションを作成
$app['eccube.service.shopping']->setNonMember($this->sessionKey, $Customer);

$customerAddresses = array();
$customerAddresses[] = $CustomerAddress;
$app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
$CustomerAddressArray = $CustomerAddress->toArray();
$CustomerAddressArray['Customer'] = $CustomerAddress->getCustomer()->toArray();
$CustomerAddressArray['Pref'] = $CustomerAddress->getPref()->toArray();

$CustomerAddressesArray = array();
$CustomerAddressesArray[] = $CustomerAddressArray;

$app['session']->set($this->sessionCustomerAddressKey, json_encode($CustomerAddressesArray));

$event = new EventArgs(
array(
Expand Down Expand Up @@ -1419,12 +1424,15 @@ private function getCustomerAddress(Application $app, $CustomerAddressData)
return $CustomerAddressData;
} else {
$cusAddId = $CustomerAddressData;

$customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
$customerAddresses = unserialize($customerAddresses);
$customerAddresses = json_decode($customerAddresses, true);

$customerAddressArray = $customerAddresses[$cusAddId];

$CustomerAddress = $customerAddresses[$cusAddId];
$pref = $app['eccube.repository.master.pref']->find($CustomerAddress->getPref()->getId());
$CustomerAddress->setPref($pref);
$CustomerAddress = new CustomerAddress();
$CustomerAddress->setPropertiesFromArray($customerAddressArray);
$CustomerAddress->setPref($app['eccube.repository.master.pref']->find($customerAddressArray['Pref']['id']));

return $CustomerAddress;
}
Expand Down Expand Up @@ -1467,11 +1475,15 @@ public function shippingMultipleEdit(Application $app, Request $request)

log_info('非会員お届け先追加処理開始');

$customerAddressArray = $CustomerAddress->toArray();
$customerAddressArray['Customer'] = $CustomerAddress->getCustomer()->toArray();
$customerAddressArray['Pref'] = $CustomerAddress->getPref()->toArray();

// 非会員用のセッションに追加
$customerAddresses = $app['session']->get($this->sessionCustomerAddressKey);
$customerAddresses = unserialize($customerAddresses);
$customerAddresses[] = $CustomerAddress;
$app['session']->set($this->sessionCustomerAddressKey, serialize($customerAddresses));
$customerAddresses = json_decode($app['session']->get($this->sessionCustomerAddressKey), true);
$customerAddresses[] = $customerAddressArray;

$app['session']->set($this->sessionCustomerAddressKey, json_encode($customerAddresses));

$event = new EventArgs(
array(
Expand Down
20 changes: 14 additions & 6 deletions src/Eccube/Form/Type/ShippingMultipleItemType.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace Eccube\Form\Type;

use Eccube\Entity\CustomerAddress;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
Expand Down Expand Up @@ -86,14 +87,21 @@ public function buildForm(FormBuilderInterface $builder, array $options)
// 非会員の場合、セッションに設定されたCustomerAddressを設定
if ($app['session']->has('eccube.front.shopping.nonmember.customeraddress')) {
$customerAddresses = $app['session']->get('eccube.front.shopping.nonmember.customeraddress');
$customerAddresses = unserialize($customerAddresses);
$customerAddresses = json_decode($customerAddresses, true);

$addresses = array();
$i = 0;
/** @var \Eccube\Entity\CustomerAddress $CustomerAddress */
foreach ($customerAddresses as $CustomerAddress) {
$addresses[$i] = $CustomerAddress->getShippingMultipleDefaultName();
$i++;
/** @var \Eccube\Entity\CustomerAddress $value */
foreach ($customerAddresses as $value) {

$customerAddressArray = (array) $value;
$customerAddressArray['Pref'] = (array) $customerAddressArray['Pref'];

$CustomerAddress = new CustomerAddress();
$CustomerAddress->setPropertiesFromArray($customerAddressArray);
$CustomerAddress->setCustomer($app['eccube.service.shopping']->getNonMember('eccube.front.shopping.nonmember'));
$CustomerAddress->setPref($app['eccube.repository.master.pref']->find($customerAddressArray['Pref']['id']));

$addresses[] = $CustomerAddress->getShippingMultipleDefaultName();
}
$form->add('customer_address', 'choice', array(
'choices' => $addresses,
Expand Down

0 comments on commit 525aaa9

Please sign in to comment.