EC-CUBE3.0.16
独自のデザインテンプレートを使用してサイト全体のカスタマイズを行っています。
カートページにおいて、「+」「-」「x」をクリックするとエラーになってしまいます。
■「x」にて削除しようとしたときのエラーメッセージ
MethodNotAllowedHttpException in RouterListener.php line 163:
No route found for "GET /cart/remove/10": Method Not Allowed (Allow: PUT)
エラーメッセージから察するにPUT送信しなければならないのにGET送信してしまっているようです。
jsをデバッグしてみたところ、function.js ファイル自体の読み込みは行われているようですが、function.js 内で定義されているクリックイベントが呼ばれていないようです。
原因わかりますでしょうか?
app/template/test/Cart/index.twig
<a href="{{ url('cart_remove', {'productClassId': ProductClass.id }) }}" {{ csrf_token_for_anchor() }} data-method="put" data-message="カートから商品を削除してもよろしいですか?">
<img src="{{ app.config.front_urlpath }}/project/img/common/ico_x.png" alt="x">
</a>
生成されたHTML
<a href="http://localhost/EC-CUBE/toebisu/html/index_dev.php/cart/remove/10" token-for-anchor="3qDPUZEKYop6-B5fWDKY9rL7FSg4IA35-xyPb12uSHU" data-method="put" data-message="カートから商品を削除してもよろしいですか?">
<img src="/EC-CUBE/toebisu/html/template/test/project/img/common/ico_x.png" alt="x">
</a>
html/template/test/js/function.js
$(function () {
var createForm = function (action, data) {
var $form = $('<form action="' + action + '" method="post"></form>');
for (input in data) {
if (data.hasOwnProperty(input)) {
$form.append('<input name="' + input + '" value="' + data[input] + '">');
}
}
return $form;
};
$('a[token-for-anchor]').click(function (e) { // ★ここが呼ばれていない
e.preventDefault();
var $this = $(this);
var data = $this.data();
if (data.confirm != false) {
if (!confirm(data.message ? data.message : '削除してもよろしいですか?')) {
return false;
}
}
var $form = createForm($this.attr('href'), {
_token: $this.attr('token-for-anchor'),
_method: data.method
}).hide();
$('body').append($form); // Firefox requires form to be on the page to allow submission
$form.submit();
});
});