Skip to content

Commit

Permalink
Merge pull request #17 from k-yamamura/master
Browse files Browse the repository at this point in the history
関連商品プラグインの修正
  • Loading branch information
ryo-endo committed Feb 25, 2016
2 parents bba784e + ab89330 commit e4593f8
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
23 changes: 22 additions & 1 deletion Controller/Admin/RelatedProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,31 @@ public function searchProduct(Application $app, Request $request)
->getQuery()
->getResult();

// 表示されている商品は検索結果に含めない
$productId = $request->get('product_id');
$ProductsData = array();
$count = count($Products);
$i = 0;
for($i = 0; $i < $count; $i++) {
$Product = $Products[$i];
if ($Product->getId() != $productId) {
$ProductsData[] = $Product;
}
if ($i >= 10) {
break;
}
}

$message = '';
if ($count > $i) {
$message = '検索結果の上限を超えています。検索条件を設定してください。';
}

return $app->renderView(
'RelatedProduct/Resource/template/Admin/modal_result.twig',
array(
'Products' => $Products,
'Products' => $ProductsData,
'message' => $message,
)
);

Expand Down
3 changes: 2 additions & 1 deletion Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public function addContentOnProductEdit(FilterResponseEvent $event)
$modal = $app->renderView(
'RelatedProduct/Resource/template/Admin/modal.twig',
array(
'searchForm' => $searchForm->createView()
'searchForm' => $searchForm->createView(),
'Product' => $Product,
)
);
$oldElement = $crawler
Expand Down
5 changes: 3 additions & 2 deletions Resource/template/Admin/modal.twig
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
var formCatIdVal = $("#{{ searchForm.category_id.vars.id }}").val();
var data = {
id: formIdVal,
category_id: formCatIdVal
category_id: formCatIdVal,
product_id: {{ Product.id ? Product.id : 0 }}
};
$("#searchResult")
.children()
Expand Down Expand Up @@ -57,7 +58,7 @@
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><svg class="cb cb-close" aria-hidden="true"><use xlink:href="#cb-close"></svg></button>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span class="modal-close" aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">商品検索</h4>
</div>
<div class="modal-body">
Expand Down
3 changes: 3 additions & 0 deletions Resource/template/Admin/modal_result.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
file that was distributed with this source code.
#}

{% if message is not empty %}
<p class="text-danger">{{ message }}</p>
{% endif %}
<div class="table-responsive">
<table class="table">
<tbody>
Expand Down
17 changes: 17 additions & 0 deletions Resource/template/Admin/related_product.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
file that was distributed with this source code.
#}

{% block javascript %}
<script>
$(function() {
$(document).on('click', '.delete', function() {
var data = $(this).data();
$('#admin_product_related_collection_' + data.id + '_ChildProduct').val('');
$('#view_' + data.id).text('');
$('#admin_product_related_collection_' + data.id + '_content' ).val('');
$('#searchResult').children().remove();
});
});
</script>
{% endblock javascript %}

</div>
<div class="box accordion">

Expand All @@ -33,6 +47,9 @@
</div>
<label id="view_{{ loop.index0 }}" class="control-label"></label>
{{ form_widget(child.ChildProduct, { attr: { style: 'display: none' } }) }}
{% if child.vars.value.id is not null %}
<button type="button" class="btn btn-default text-right delete" data-id="{{ loop.index0 }}">削除</button>
{% endif %}
</div>
<div class="form-group">
{{ form_label(child.content) }}
Expand Down

0 comments on commit e4593f8

Please sign in to comment.