Esempio n. 1
0
 public static function savePlugin($plugin)
 {
     $default = array('status' => 0);
     $plugin = array_merge($default, $plugin);
     $model = new shopPluginModel();
     if (!empty($plugin['id']) && ($id = max(0, intval($plugin['id']))) && ($row = $model->getByField(array('id' => $id, 'type' => shopPluginModel::TYPE_PAYMENT)))) {
         $plugin['plugin'] = $row['plugin'];
         $model->updateById($plugin['id'], $plugin);
     } elseif (!empty($plugin['plugin'])) {
         $plugin['type'] = shopPluginModel::TYPE_PAYMENT;
         $plugin['id'] = $model->insert($plugin);
     }
     if (!empty($plugin['id']) && isset($plugin['settings'])) {
         waPayment::factory($plugin['plugin'], $plugin['id'], self::getInstance())->saveSettings($plugin['settings']);
     }
     if (!empty($plugin['id'])) {
         ifset($plugin['shipping'], array());
         $plugins = $model->listPlugins(shopPluginModel::TYPE_SHIPPING, array('all' => true));
         $app_settings = new waAppSettingsModel();
         $settings = json_decode($app_settings->get('shop', 'shipping_payment_disabled', '{}'), true);
         if (empty($settings) || !is_array($settings)) {
             $settings = array();
         }
         if (!isset($settings[$plugin['id']])) {
             $settings[$plugin['id']] = array();
         }
         $s =& $settings[$plugin['id']];
         foreach ($plugins as $item) {
             if (empty($plugin['shipping'][$item['id']])) {
                 $s[] = $item['id'];
             } else {
                 $key = array_search($item['id'], $s);
                 if ($key !== false) {
                     unset($s[$key]);
                 }
             }
         }
         $s = array_unique($s);
         if (empty($s)) {
             unset($settings[$plugin['id']]);
         }
         $app_settings->set('shop', 'shipping_payment_disabled', json_encode($settings));
     }
     return $plugin;
 }
Esempio n. 2
0
 public static function savePlugin($plugin)
 {
     $default = array('status' => 0);
     $plugin = array_merge($default, $plugin);
     if (!intval(ifempty($plugin['id'])) && isset($plugin['settings'])) {
         $instance = waShipping::factory($plugin['plugin'], null, self::getInstance());
         $instance->saveSettings($plugin['settings']);
     }
     $model = new shopPluginModel();
     if (!empty($plugin['id']) && ($id = max(0, intval($plugin['id']))) && ($row = $model->getByField(array('id' => $id, 'type' => shopPluginModel::TYPE_SHIPPING)))) {
         $plugin['plugin'] = $row['plugin'];
         $model->updateById($plugin['id'], $plugin);
     } elseif (!empty($plugin['plugin'])) {
         $plugin['type'] = shopPluginModel::TYPE_SHIPPING;
         $plugin['id'] = $model->insert($plugin);
     }
     if (!empty($plugin['id']) && isset($plugin['settings'])) {
         $instance = waShipping::factory($plugin['plugin'], $plugin['id'], self::getInstance());
         $instance->saveSettings($plugin['settings']);
     }
     return $plugin;
 }