Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paymentの物理削除対応 #2499

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 41 additions & 21 deletions src/Eccube/Controller/Admin/Setting/Shop/PaymentController.php
Expand Up @@ -24,11 +24,11 @@

namespace Eccube\Controller\Admin\Setting\Shop;

use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\ORM\EntityManager;
use Eccube\Annotation\Component;
use Eccube\Annotation\Inject;
use Eccube\Application;
use Eccube\Common\Constant;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Payment;
use Eccube\Event\EccubeEvents;
Expand Down Expand Up @@ -89,7 +89,7 @@ public function index(Application $app, Request $request)
{
$Payments = $this->paymentRepository
->findBy(
array('del_flg' => 0),
array(),
array('rank' => 'DESC')
);

Expand Down Expand Up @@ -153,6 +153,7 @@ public function edit(Application $app, Request $request, Payment $Payment = null
);
}

$Payment->setVisible(true);
$this->entityManager->persist($Payment);
$this->entityManager->flush();

Expand Down Expand Up @@ -222,31 +223,29 @@ public function delete(Application $app, Request $request, Payment $TargetPaymen
{
$this->isTokenValid($app);

$TargetPayment
->setDelFlg(Constant::ENABLED)
->setRank(0);
$this->entityManager->persist($TargetPayment);

$rank = 1;
$Payments = $this->paymentRepository->findBy(array('del_flg' => Constant::DISABLED), array('rank' => 'ASC'));
$Payments = $this->paymentRepository->findBy(array(), array('rank' => 'ASC'));
foreach ($Payments as $Payment) {
if ($Payment->getId() != $TargetPayment->getId()) {
$Payment->setRank($rank);
$rank++;
}
$Payment->setRank($rank++);
}

$this->entityManager->flush();
try {
$this->paymentRepository->delete($TargetPayment);
$this->entityManager->flush();

$event = new EventArgs(
array(
'Payment' => $TargetPayment,
),
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_DELETE_COMPLETE, $event);
$event = new EventArgs(
array(
'Payment' => $TargetPayment,
),
$request
);
$this->eventDispatcher->dispatch(EccubeEvents::ADMIN_SETTING_SHOP_PAYMENT_DELETE_COMPLETE, $event);

$app->addSuccess('admin.delete.complete', 'admin');
$app->addSuccess('admin.delete.complete', 'admin');
} catch(ForeignKeyConstraintViolationException $e) {
$this->entityManager->rollback();
$app->addError('admin.payment.delete.error', 'admin');
}

return $app->redirect($app->url('admin_setting_shop_payment'));
}
Expand Down Expand Up @@ -296,4 +295,25 @@ public function down(Application $app, Payment $current)

return $app->redirect($app->url('admin_setting_shop_payment'));
}

/**
* @Method("PUT")
* @Route("/{_admin}/setting/shop/payment/{id}/visible", requirements={"id" = "\d+"}, name="admin_setting_shop_payment_visible")
*/
public function visible(Application $app, Payment $Payment)
{
$this->isTokenValid($app);

$Payment->setVisible(!$Payment->isVisible());

$this->entityManager->flush();

if ($Payment->isVisible()) {
$app->addSuccess('admin.payment.visible.complete', 'admin');
} else {
$app->addSuccess('admin.payment.invisible.complete', 'admin');
}

return $app->redirect($app->url('admin_setting_shop_payment'));
}
}
37 changes: 21 additions & 16 deletions src/Eccube/Entity/Payment.php
Expand Up @@ -127,9 +127,9 @@ public function __toString()
/**
* @var int
*
* @ORM\Column(name="del_flg", type="smallint", options={"unsigned":true,"default":0})
* @ORM\Column(name="visible", type="boolean", options={"default":true})
*/
private $del_flg = 0;
private $visible;

/**
* @var \DateTime
Expand Down Expand Up @@ -421,27 +421,21 @@ public function getServiceClass()
}

/**
* Set delFlg.
*
* @param int $delFlg
*
* @return Payment
* @return boolean
*/
public function setDelFlg($delFlg)
public function isVisible()
{
$this->del_flg = $delFlg;

return $this;
return $this->visible;
}

/**
* Get delFlg.
*
* @return int
* @param boolean $visible
* @return Payment
*/
public function getDelFlg()
public function setVisible($visible)
{
return $this->del_flg;
$this->visible = $visible;
return $this;
}

/**
Expand Down Expand Up @@ -551,4 +545,15 @@ public function getCreator()
{
return $this->Creator;
}

/**
* @return string
*/
public function getMethodForAdmin()
{
if ($this->isVisible()) {
return $this->getMethod();
}
return $this->getMethod().'(非表示)';
}
}
4 changes: 1 addition & 3 deletions src/Eccube/Repository/AbstractRepository.php
Expand Up @@ -6,7 +6,6 @@

use Doctrine\ORM\EntityRepository;
use Eccube\Annotation\Inject;
use Eccube\Common\Constant;
use Eccube\Entity\AbstractEntity;

class AbstractRepository extends EntityRepository
Expand All @@ -25,8 +24,7 @@ class AbstractRepository extends EntityRepository
*/
public function delete($entity)
{
$entity->setDelFlg(Constant::ENABLED);
$this->save($entity);
$this->getEntityManager()->remove($entity);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Eccube/Repository/PaymentRepository.php
Expand Up @@ -57,9 +57,9 @@ public function findOrCreate($id)
$Payment = new \Eccube\Entity\Payment();
$Payment
->setRank($rank)
->setDelFlg(0)
->setFixFlg(1)
->setChargeFlg(1);
->setChargeFlg(1)
->setVisible(true);
} else {
$Payment = $this->find($id);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Eccube/Resource/doctrine/import_csv/dtb_payment.csv
@@ -1,5 +1,5 @@
payment_id,creator_id,payment_method,charge,rule_max,rank,fix_flg,del_flg,create_date,update_date,payment_image,charge_flg,rule_min,method_class,service_class,discriminator_type
"1","1","郵便振替","0",,"4","1","0","2017-03-07 10:14:52","2017-03-07 10:14:52",,"1","0","\Eccube\Service\Payment\Method\Cash","\Eccube\Service\PaymentService","payment"
"2","1","現金書留","0",,"3","1","0","2017-03-07 10:14:52","2017-03-07 10:14:52",,"1","0","\Eccube\Service\Payment\Method\Cash","\Eccube\Service\PaymentService","payment"
"3","1","銀行振込","0",,"2","1","0","2017-03-07 10:14:52","2017-03-07 10:14:52",,"1","0","\Eccube\Service\Payment\Method\Cash","\Eccube\Service\PaymentService","payment"
"4","1","代金引換","0",,"1","1","0","2017-03-07 10:14:52","2017-03-07 10:14:52",,"1","0","\Eccube\Service\Payment\Method\Cash","\Eccube\Service\PaymentService","payment"
payment_id,creator_id,payment_method,charge,rule_max,rank,fix_flg,visible,create_date,update_date,payment_image,charge_flg,rule_min,method_class,service_class,discriminator_type
"1","1","郵便振替","0",,"4","1","1","2017-03-07 10:14:52","2017-03-07 10:14:52",,"1","0","\Eccube\Service\Payment\Method\Cash","\Eccube\Service\PaymentService","payment"
"2","1","現金書留","0",,"3","1","1","2017-03-07 10:14:52","2017-03-07 10:14:52",,"1","0","\Eccube\Service\Payment\Method\Cash","\Eccube\Service\PaymentService","payment"
"3","1","銀行振込","0",,"2","1","1","2017-03-07 10:14:52","2017-03-07 10:14:52",,"1","0","\Eccube\Service\Payment\Method\Cash","\Eccube\Service\PaymentService","payment"
"4","1","代金引換","0",,"1","1","1","2017-03-07 10:14:52","2017-03-07 10:14:52",,"1","0","\Eccube\Service\Payment\Method\Cash","\Eccube\Service\PaymentService","payment"
3 changes: 3 additions & 0 deletions src/Eccube/Resource/locale/messages.ja.php
Expand Up @@ -160,6 +160,9 @@
'admin.preview.register.complete' => 'プレビューを登録しました',
'admin.change_password.save.complete' => 'パスワードを変更しました。',
'admin.change_password.save.error' => 'パスワードを変更できませんでした。',
'admin.payment.visible.complete' => '表示に設定しました。',
'admin.payment.invisible.complete' => '非表示に設定しました。',
'admin.payment.delete.error' => 'すでに使用されている支払方法は削除できません。',
'admin.delivery.visible.complete' => '表示に変更しました。',
'admin.delivery.hidden.complete' => '非表示に変更しました。',
'admin_title' => 'EC-CUBE 管理機能',
Expand Down
17 changes: 8 additions & 9 deletions src/Eccube/Resource/template/admin/Setting/Shop/payment.twig
Expand Up @@ -53,7 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
{% for Payment in Payments %}
<tr id="payment_list__item--{{ Payment.id }}">

<td id="payment_list__method--{{ Payment.id }}" class="member_name">{{ Payment.method }}</td>
<td id="payment_list__method--{{ Payment.id }}" class="member_name">{{ Payment.methodForAdmin }}</td>
<td id="payment_list__charge--{{ Payment.id }}" class="member_name">
{{ Payment.charge }}
</td>
Expand All @@ -75,19 +75,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<a class="dropdown-toggle" data-toggle="dropdown"><svg class="cb cb-ellipsis-h"> <use xlink:href="#cb-ellipsis-h" /></svg></a>
<ul id="payment_list__menu--{{ Payment.id }}" class="dropdown-menu dropdown-menu-right">
<li>
{% if Payment.fix_flg == 1 %}
<a href="{{ url('admin_setting_shop_payment_edit', { id: Payment.id}) }}">編集</a>
{% else %}
<a>編集</a>
{% endif %}
<a href="{{ url('admin_setting_shop_payment_edit', { id: Payment.id}) }}">編集</a>
</li>
<li>
{% if Payment.fix_flg == 1 %}
<a href="{{ url('admin_setting_shop_payment_delete', { id: Payment.id}) }}" {{ csrf_token_for_anchor() }} data-method="delete">削除</a>
{% if Payment.visible %}
<a href="{{ url('admin_setting_shop_payment_visible', { id: Payment.id}) }}" {{ csrf_token_for_anchor() }} data-method="put" data-message="非表示にしてもよろしいですか?">非表示にする</a>
{% else %}
<a>削除</a>
<a href="{{ url('admin_setting_shop_payment_visible', { id: Payment.id}) }}" {{ csrf_token_for_anchor() }} data-method="put" data-message="表示にしてもよろしいですか">表示にする</a>
{% endif %}
</li>
<li>
<a href="{{ url('admin_setting_shop_payment_delete', { id: Payment.id}) }}" {{ csrf_token_for_anchor() }} data-method="delete">削除</a>
</li>
<li>
{% if loop.first == false %}
<li><a href="{{ url('admin_setting_shop_payment_up', {id: Payment.id}) }}" {{ csrf_token_for_anchor() }} data-method="put" data-confirm="false">上へ</a></li>
Expand Down
8 changes: 5 additions & 3 deletions src/Eccube/Resource/template/default/Shopping/index.twig
Expand Up @@ -354,9 +354,11 @@ $(function() {
</div>
<div class="ec-blockRadio">
{% for key, child in form.Payment %}
{{ form_widget(child, {'attr': {'class': 'payment' }}) }}
{% if form.Payment.vars.choices[key].data.payment_image is not null %}
<img src="{{ app.config.image_save_urlpath }}/{{ form.Payment.vars.choices[key].data.payment_image }}">
{% if form.Payment.vars.choices[key].data.visible %}
{{ form_widget(child, {'attr': {'class': 'payment' }}) }}
{% if form.Payment.vars.choices[key].data.payment_image is not null %}
<img src="{{ app.config.image_save_urlpath }}/{{ form.Payment.vars.choices[key].data.payment_image }}">
{% endif %}
{% endif %}
{% endfor %}
{{ form_errors(form.Payment) }}
Expand Down
2 changes: 1 addition & 1 deletion tests/Eccube/Tests/Fixture/Generator.php
Expand Up @@ -619,7 +619,7 @@ public function createPayment(Delivery $Delivery, $method, $charge = 0, $rule_mi
->setRuleMin($rule_min)
->setRuleMax($rule_max)
->setCreator($Member)
->setDelFlg(Constant::DISABLED);
->setVisible(true);
$this->app['orm.em']->persist($Payment);
$this->app['orm.em']->flush($Payment);

Expand Down
1 change: 0 additions & 1 deletion tests/Eccube/Tests/Repository/PaymentRepositoryTest.php
Expand Up @@ -24,7 +24,6 @@
namespace Eccube\Tests\Repository;

use Eccube\Tests\EccubeTestCase;
use Eccube\Application;

class PaymentRepositoryTest extends EccubeTestCase
{
Expand Down
7 changes: 0 additions & 7 deletions tests/Eccube/Tests/Service/PaymentServiceTest.php
Expand Up @@ -2,13 +2,6 @@

namespace Eccube\Tests\Service;

use Eccube\Application;
use Eccube\Common\Constant;
use Eccube\Exception\CartException;
use Eccube\Service\CartService;
use Eccube\Util\Str;
use Eccube\Service\Calculator\ShipmentItemCollection;

class PaymentServiceTest extends AbstractServiceTestCase
{
public function testConstructorInjection()
Expand Down
Expand Up @@ -72,7 +72,7 @@ public function setUp()

$Payment = new Payment();
$Payment->setMethod('テスト支払');
$Payment->setDelFlg(0);
$Payment->setVisible(true);
$this->app['orm.em']->persist($Payment);
$this->app['orm.em']->flush($Payment);

Expand Down
Expand Up @@ -24,7 +24,7 @@

namespace Eccube\Tests\Web\Admin\Setting\Shop;

use Eccube\Common\Constant;
use Eccube\Entity\Payment;
use Eccube\Tests\Web\Admin\AbstractAdminWebTestCase;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

Expand Down Expand Up @@ -99,20 +99,31 @@ public function testEdit($isSuccess, $expected)

public function testDeleteSuccess()
{
$pid = 1;

$Member = $this->app['eccube.repository.member']->find(2);
$Payment = new Payment();
$Payment->setMethod('testDeleteSuccess')
->setCharge(0)
->setRuleMin(0)
->setRuleMax(9999)
->setCreator($Member)
->setVisible(true);

$this->app['orm.em']->persist($Payment);
$this->app['orm.em']->flush($Payment);

$pid = $Payment->getId();
$this->client->request('DELETE',
$this->app->url('admin_setting_shop_payment_delete', array('id' => $pid))
);

$this->assertTrue($this->client->getResponse()->isRedirection());

$Payment = $this->app['eccube.repository.payment']->find($pid);
$this->actual = $Payment->getDelFlg();
$this->expected = Constant::ENABLED;
$this->verify();
$this->assertNull($Payment);
}

public function testDeleteFail()
public function testDeleteFail_NotFound()
{
$pid = 9999;
try {
Expand Down
1 change: 0 additions & 1 deletion tests/Eccube/Tests/Web/Mypage/DeliveryControllerTest.php
Expand Up @@ -25,7 +25,6 @@
namespace Eccube\Tests\Web\Mypage;

use Eccube\Tests\Web\AbstractWebTestCase;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class DeliveryControllerTest extends AbstractWebTestCase
{
Expand Down