結局、(v2.13.2で)やってみました。
(1)不具合の対応
data/Smarty/templates/admin/order/edit.tpl
<!--{assign var=key1 value="shipping_country_id"}-->
<!--{assign var=key2 value="shipping_zipcode"}-->
<!--{if !$smarty.const.FORM_COUNTRY_ENABLE}-->
<input type="hidden" name="<!--{$key1}-->[<!--{$shipping_index}-->]" value="<!--{$smarty.const.DEFAULT_COUNTRY_ID}-->" />
<!--{* added *}-->
<input type="hidden" name="<!--{$key2}-->[<!--{$shipping_index}-->]" value="<!--{$arrShipping[$key2]|h}-->" />
<!--{* added *}-->
<!--{else}-->
(2)「登録する」ボタン
削除された部分を、まずDBから削除しておく。
data/class/helper/SC_Helper_Purchase.php
// added
/**
* 配送情報の削除を行う.
* @param integer $order_id 受注ID
* @param integer $shipping_id 配送先ID
* @return void
*/
public function deleteShipping($order_id, $shipping_id = '')
{
$objQuery =& SC_Query_Ex::getSingletonInstance();
$table = 'dtb_shipping';
if ($shipping_id == '') {
$where = 'order_id = ?';
$objQuery->delete($table, $where, array($order_id));
} else {
$where = 'order_id = ? AND shipping_id = ?';
$objQuery->delete($table, $where, array($order_id, $shipping_id));
}
}
/**
* 配送商品を削除する.
*
* @param integer $order_id 受注ID
* @param integer $shipping_id 配送先ID
* @return void
*/
public function deleteShipmentItem($order_id, $shipping_id)
{
$objQuery =& SC_Query_Ex::getSingletonInstance();
$table = 'dtb_shipment_item';
$where = 'order_id = ? AND shipping_id = ?';
$objQuery->delete($table, $where, array($order_id, $shipping_id));
}
// added
data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php
$arrAllShipping = $objFormParam->getSwapArray($this->arrShippingKeys);
$arrAllShipmentItem = $objFormParam->getSwapArray($this->arrShipmentItemKeys);
// added
// 削除されたお届け先をDBから削除する。
$arrPreAllShipping = $objPurchase->getShippings($order_id, false);
foreach ($arrPreAllShipping as $arrPreShipping) {
$pre_shipping_id = $arrPreShipping['shipping_id'];
$found_shipping_id = false;
foreach ($arrAllShipping as $arrShipping) {
if ($arrShipping['shipping_id'] == $pre_shipping_id) {
$found_shipping_id = true;
break;
}
}
if ($found_shipping_id === false) {
$objPurchase->deleteShipmentItem($order_id, $pre_shipping_id);
$objPurchase->deleteShipping($order_id, $pre_shipping_id);
}
}
// added
(3)「お届け先の削除」ボタン
画面上の情報を削除する。
data/Smarty/templates/admin/order/edit.tpl
<!--{foreach name=shipping from=$arrAllShipping item=arrShipping key=shipping_index}-->
<!--{if $tpl_shipping_quantity > 1}-->
<h3>お届け先<!--{$smarty.foreach.shipping.iteration}--></h3>
<!--{/if}-->
<!--{assign var=key value="shipping_id"}-->
<input type="hidden" name="<!--{$key}-->[<!--{$shipping_index}-->]" value="<!--{$arrShipping[$key]|default:"0"|h}-->" id="<!--{$key}-->_<!--{$shipping_index}-->" />
<!--{if $tpl_shipping_quantity > 1}-->
<h2>届け先商品情報 <a class="btn-normal" href="java script:;" name="add_product" onclick="eccube.openWindow('<!--{$smarty.const.ROOT_URLPATH}--><!--{$smarty.const.ADMIN_DIR}-->order/product_select.php?order_id=<!--{$arrForm.order_id.value|h}-->&shipping_id=<!--{$shipping_index}-->', 'search', '615', '500', {menubar:'no'}); return false;">商品の追加</a>
<!--{* added *}-->
<a class="btn-normal" href="java script:;" name="delete_shipping" onclick="eccube.setValue('select_shipping_id', <!--{$shipping_index}-->, 'form1'); eccube.setModeAndSubmit('delete_shipping','anchor_key','order_products'); return false;">このお届け先を削除</a>
<!--{* added *}-->
</h2>
data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php
// お届け先の追加
case 'append_shipping':
$objFormParam->setParam($_POST);
$objFormParam->convParam();
$this->setProductsQuantity($objFormParam);
$this->addShipping($objFormParam);
break;
// added
// お届け先の削除
case 'delete_shipping':
$objFormParam->setParam($_POST);
$objFormParam->convParam();
$this->doDeleteShipping($objFormParam);
$this->setProductsQuantity($objFormParam);
break;
// added
default:
break;
// added
/**
* お届け先を削除する.
*
* @param SC_FormParam $objFormParam SC_FormParam インスタンス
* @return void
*/
public function doDeleteShipping(&$objFormParam)
{
$select_shipping_id = $objFormParam->getValue('select_shipping_id');
$arrPreShipmentProductClassIds = $objFormParam->getValue('shipment_product_class_id');
$arrPreProductClassIds = $objFormParam->getValue('product_class_id');
// お届け先商品データをキーとともに逆順に
$arrRevPreShipmentProductClassIds = array_reverse($arrPreShipmentProductClassIds[$select_shipping_id], true);
// お届け先商品データの削除
foreach ($arrRevPreShipmentProductClassIds as $delete_no => $delete_product_class_id) {
$arrNewShipments = $this->deleteShipment($objFormParam, $this->arrShipmentItemKeys , $select_shipping_id, $delete_no);
$is_product_delete = true;
foreach ($arrNewShipments['shipment_product_class_id'] as $shipping_id => $arrShipmentProductClassIds) {
foreach ($arrShipmentProductClassIds as $relation_index => $shipment_product_class_id) {
if (in_array($delete_product_class_id, $arrShipmentProductClassIds)) {
$is_product_delete = false;
break;
}
}
}
//商品情報から削除
if ($is_product_delete) {
$this->checkDeleteProducts($objFormParam, $arrPreProductClassIds, $delete_product_class_id, $this->arrProductKeys);
}
$objFormParam->setParam($arrNewShipments);
}
// お届け先データの削除
$arrShippingIds = $objFormParam->getValue('shipping_id');
foreach($arrShippingIds as $shipping_index => $shipping_data) {
if ($shipping_data == $select_shipping_id) {
$select_shipping_index = $shipping_index;
break;
}
}
foreach($this->arrShippingKeys as $keys) {
$arrShippingKeyTmp = $objFormParam->getValue($keys);
$arrShippingKeyNew = array();
foreach ($arrShippingKeyTmp as $tmp_index => $tmp_data) {
if ($tmp_index != $select_shipping_index) {
$arrShippingKeyNew[$tmp_index] = $tmp_data;
}
}
$objFormParam->setValue($keys, $arrShippingKeyNew);
}
}
// added
気になったので、とりあえず、ここも修正しました。
public function deleteShipment(&$objFormParam, $arrShipmentDeletKeys, $delete_shipping_id, $delete_no)
{
// added
$arrUpdateParams = array();
// added
foreach ($arrShipmentDeletKeys as $delete_key) {
$arrShipments = $objFormParam->getValue($delete_key);
// added
$arrUpdateParams[$delete_key] = array();
// added
foreach ($arrShipments as $shipp_id => $arrKeyData) {
if (empty($arrKeyData)) continue;
foreach ($arrKeyData as $relation_index => $shipment_info) {
if ($relation_index != $delete_no || $shipp_id != $delete_shipping_id) {
$arrUpdateParams[$delete_key][$shipp_id][] = $shipment_info;
}
}
}
}
//$objFormParam->setParam($arrUpdateParams);
return $arrUpdateParams;
}