[РЕШЕНО] Добавить комиссию paypal в drupal commerce

Главные вкладки

Аватар пользователя mozh mozh 17 ноября 2016 в 14:59

Прилетел таск добавить комиссию на юзера
модули commerce, Commerce Fees, Commerce PayPal

включаем модули, идем сюда /admin/commerce/config/fees Создаем новый fee PayPal fee
далее идем в правила /admin/config/workflow/rules добавляем rules

{ "rules_apply_paypal_fee" : {
    "LABEL" : "Apply paypal fee",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "commerce_payment", "php", "commerce_fees" ],
    "ON" : { "commerce_fees_order" : [] },
    "IF" : [
      { "commerce_payment_selected_payment_method" : { "commerce_order" : [ "commerce_order" ], "method_id" : "paypal_wps" } }
    ],
    "DO" : [
      { "commerce_fees_apply" : {
          "entity" : [ "commerce-order" ],
          "fee" : "paypal_fee",
          "amount" : {
            "select" : "commerce-order:order-id",
            "php" : { "code" : "$order = commerce_order_load($value);\r\n$fee1 = 0.039;\r\n$fee2 = 0.039;\r\n$fixed = 30;\/\/0.30 USD\r\n\r\n$cur_code = commerce_multicurrency_get_user_currency_code();\r\n\r\nif($cur_code != \u0027USD\u0027){\r\n$fixed = ceil(commerce_multicurrency_conversion($fixed, \u0027USD\u0027, $cur_code));\r\n}\r\n\/\/dpm($fixed);\r\n\r\n\r\n$productPrice = $order-\u003Ecommerce_order_total[\u0027und\u0027][0][\u0027amount\u0027];\r\n$productFee = $productPrice*$fee1 + $fixed;\r\n\/\/dpm($productFee);\r\n$feeFromFee = $productFee * $fee2;\r\n\/\/dpm($feeFromFee);\r\n$value = $productFee + $feeFromFee;\r\n\/\/dpm($value);\r\nreturn $value;" }
          },
          "currency_code" : [ "site:commerce-currency" ],
          "include_tax" : "0"
        }
      }
    ]
  }
}

В правиле указано условие: при выборе метода оплаты paypal
жесткий Action c php))

<?php$order = commerce_order_load($value);
$fee1 = 0.039;
$fee2 = 0.039;
$fixed = 30;//0.30 USD

$cur_code = commerce_multicurrency_get_user_currency_code();

if($cur_code != 'USD'){
$fixed = ceil(commerce_multicurrency_conversion($fixed, 'USD', $cur_code));
}
//dpm($fixed);

$productPrice = $order->commerce_order_total['und'][0]['amount'];
$productFee = $productPrice*$fee1 + $fixed;
//dpm($productFee);
$feeFromFee = $productFee * $fee2;
//dpm($feeFromFee);
$value = $productFee + $feeFromFee;
//dpm($value);
return $value;?>

жду ваши пинания по говнокоду, может есть решение по лучше)

ВложениеРазмер
Иконка изображения paypalfee.jpg129.49 КБ