Ejemplo n.º 1
0
 public function onAfterSerialConsume(&$serial)
 {
     $user = hikaserial::loadUser(true);
     $cms_id = (int) @$user->user_cms_id;
     $serial_user = null;
     $ids = array();
     if (!empty($serial->serial_user_id)) {
         $userClass = hikaserial::get('shop.class.user');
         $serial_user = $userClass->get($serial->serial_user_id);
     }
     parent::listPlugins('pointsconsumer', $ids, false);
     foreach ($ids as $id) {
         parent::pluginParams($id);
         if (in_array($serial->serial_pack_id, $this->plugin_params->packs_id)) {
             $points = (int) $this->plugin_params->value;
             if (!empty($this->plugin_params->dynamic_value) && !empty($serial->serial_extradata['points_value'])) {
                 $points += (int) $serial->serial_extradata['points_value'];
             }
             $user_id = $cms_id;
             if (!empty($this->plugin_params->target_serial_user) && !empty($serial_user->serial_user_id)) {
                 $user_id = $serial_user->user_cms_id;
             }
             $this->givePoints($cms_id, $points);
         }
     }
 }
Ejemplo n.º 2
0
 public function generate(&$pack, &$order, $quantity, &$serials)
 {
     parent::pluginParams(0, 'secureebook');
     $product_code = '';
     if (!empty($order->cart->products)) {
         foreach ($order->cart->products as $p) {
             if ($p->product_id == $pack->product_id) {
                 $product_code = $p->order_product_code;
                 break;
             }
         }
     }
     if (empty($product_code)) {
         return;
     }
     $data = '<' . '?xml version="1.0"?' . '>' . "\r\n" . '<request vendorcode="' . @$this->plugin_params->vendor_code . '" secureebookproductcode="' . $this->tobool(@$this->plugin_params->remote_product_code) . '" userdata="' . $order->order_id . '" testmode="' . $this->tobool(@$this->plugin_params->test_mode) . '">' . "\r\n" . '<product code="' . $product_code . '" qty="' . $quantity . '" />' . "\r\n" . '<orderinfo name="' . @$order->customer->name . '" email="' . @$order->customer->user_email . '" total="' . @$order->order_full_price . '" />' . "\r\n" . '</request>';
     $result = $this->send('xml=' . urlencode($data));
     $token = $this->extractElems('token', $result, true);
     if (isset($token[0]['token'])) {
         $token = $token[0]['token'];
     } else {
         $app = JFactory::getApplication();
         $app->enqueueMessage(JText::sprintf('SECURE_EBOOK_ERROR', 'no token. Invalid request for product [' . $product_code . ']'));
         return false;
     }
     $data = '<' . '?xml version="1.0"?' . '>' . "\r\n" . '<confirm code="' . strtolower(md5($token . $this->plugin_params->sdk_key)) . '"/>';
     $result = $this->send('xml=' . urlencode($data));
     if (strpos($result, '<success') !== false) {
         $keys = $this->extractElems('key', $result, true);
         $links = $this->extractElems('link', $result, true);
         $books = array();
         foreach ($keys as $key) {
             $code = $key['productcode'];
             if (!isset($books[$code])) {
                 $books[$code] = array();
             }
             $books[$code][] = array('key' => $key['key']);
         }
         foreach ($links as $link) {
             $code = $link['productcode'];
             if (isset($books[$code])) {
                 foreach ($books[$code] as $i => $v) {
                     $books[$code][$i]['link'] = $link['url'];
                 }
             }
         }
         foreach ($books as $book) {
             foreach ($book as $b) {
                 $serials[] = serialize($b);
             }
         }
     } else {
         $error = $this->extractContent('error', $result);
         $app = JFactory::getApplication();
         $app->enqueueMessage(JText::sprintf('SECURE_EBOOK_ERROR', $error[0]));
         return false;
     }
 }
Ejemplo n.º 3
0
 public function onAfterSerialConsume(&$serial)
 {
     $user = hikaserial::loadUser(true);
     $cms_id = $user->user_cms_id;
     $ids = array();
     parent::listPlugins('groupconsumer', $ids, false);
     foreach ($ids as $id) {
         parent::pluginParams($id);
         if ($this->plugin_params->pack_id == $serial->serial_pack_id) {
             $this->updateGroup($cms_id, $this->plugin_params->group_id);
         }
     }
 }
Ejemplo n.º 4
0
 public function onBeforeSerialMailSend(&$mail, &$mailer, &$serials, $order)
 {
     $ids = array();
     parent::listPlugins('mailtocustomfield', $ids, false);
     if (empty($ids)) {
         return;
     }
     $fullOrder = null;
     foreach ($ids as $id) {
         parent::pluginParams($id);
         $customfield_type = null;
         foreach ($serials as $k => $serial) {
             if (is_string($this->plugin_params->packs) && strpos(',' . $this->plugin_params->packs . ',', ',' . $serial->serial_pack_id . ',') === false) {
                 continue;
             }
             if (is_array($this->plugin_params->packs) && !in_array($serial->serial_pack_id, $this->plugin_params->packs)) {
                 continue;
             }
             $custom_field = $this->plugin_params->custom_field;
             if (empty($custom_field)) {
                 continue;
             }
             list($customfield_type, $custom_field) = explode('.', $custom_field, 2);
             if ($fullOrder === null) {
                 $orderClass = hikaserial::get('shop.class.order');
                 $fullOrder = $orderClass->loadFullOrder($order->order_id, true, false);
             }
             if ($customfield_type == 'order' && !isset($fullOrder->{$custom_field})) {
                 continue;
             }
             if ($customfield_type == 'item') {
                 $f = false;
                 foreach ($fullOrder->products as $k => $product) {
                     if (isset($product->{$custom_field})) {
                         $f = true;
                         break;
                     }
                 }
                 if (!$f) {
                     continue;
                 }
             }
             if ($customfield_type == 'item') {
                 $this->sendCustomEmail($serial, $fullOrder);
             } else {
                 $this->sendCustomEmail($serials, $fullOrder);
                 break;
             }
         }
     }
 }
Ejemplo n.º 5
0
 public function onBeforeSerialConsume(&$serial, $user_id, &$do, &$extra_data)
 {
     $user = hikaserial::loadUser(true);
     $ids = array();
     parent::listPlugins('groupfilterconsumer', $ids, false);
     if (!$do) {
         return;
     }
     foreach ($ids as $id) {
         parent::pluginParams($id);
         if (in_array($serial->serial_pack_id, $this->plugin_params->packs_id)) {
             if (empty($user) || empty($user->user_cms_id)) {
                 $do = false;
             }
             if (!empty($this->plugin_params->groups)) {
                 $valid_groups = explode(',', trim($this->plugin_params->groups, ','));
                 foreach ($valid_groups as &$g) {
                     $g = (int) $g;
                 }
                 unset($g);
                 if (!HIKASHOP_J16) {
                     $joomla_user = clone JFactory::getUser($user->user_cms_id);
                     $userGroups = array($joomla_user->gid);
                 } else {
                     jimport('joomla.access.access');
                     $userGroups = JAccess::getGroupsByUser($user->user_cms_id, true);
                 }
                 $f = false;
                 foreach ($userGroups as $g) {
                     if (in_array($g, $valid_groups)) {
                         $f = true;
                         break;
                     }
                 }
                 if (!$f) {
                     $do = false;
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
 public function onSerialOrderPreUpdate($new, &$order, &$order_serial_params)
 {
     if (!$new) {
         return;
     }
     $ids = array();
     parent::listPlugins('serialperorder', $ids, false);
     foreach ($ids as $id) {
         parent::pluginParams($id);
         if ((int) $this->plugin_params->quantity == 0 || (int) $this->plugin_params->pack_id == 0) {
             continue;
         }
         if (empty($order_serial_params['order'][(int) $this->plugin_params->pack_id])) {
             $order_serial_params['order'][(int) $this->plugin_params->pack_id] = array(0, 0);
         }
         if (!is_array($order_serial_params['order'][(int) $this->plugin_params->pack_id])) {
             $order_serial_params['order'][(int) $this->plugin_params->pack_id] = array($order_serial_params['order'][(int) $this->plugin_params->pack_id], 0);
         }
         $order_serial_params['order'][(int) $this->plugin_params->pack_id][1] += (int) $this->plugin_params->quantity;
     }
 }
Ejemplo n.º 7
0
 public function __construct(&$subject, $config)
 {
     parent::__construct($subject, $config);
 }
Ejemplo n.º 8
0
 public function onPackGeneratorTypeDisplay(&$values)
 {
     parent::listPlugins('coupongen', $values);
 }
Ejemplo n.º 9
0
    public function populateForm(&$pack)
    {
        $ret = '';
        if (isset($pack->pointsgen)) {
            parent::pluginParams($pack->pointsgen);
        }
        if (isset($this->plugin_params)) {
            $ret .= '<tr>
				<td class="key"><label>' . JText::_('POINTS_VALUE') . '</label></td>
				<td><strong>' . $this->plugin_params->value . '</strong></td>
			</tr>';
            if (!empty($this->plugin_params->currency_rate)) {
                $shopConfig = hikaserial::config(false);
                $main_currency = $shopConfig->get('main_currency', 1);
                $currencyClass = hikaserial::get('shop.class.currency');
                $currency = $currencyClass->get($main_currency);
                $ret .= '<tr>
					<td class="key"><label>' . JText::_('POINTS_CURRENCY_RATE') . '</label></td>
					<td><strong>' . $this->plugin_params->currency_rate . ' ' . JText::sprintf('POINTS_CONVERSION', $currency->currency_code . ' ' . $currency->currency_symbol) . '</strong></td>
				</tr>';
            }
            $ret .= '<tr>
				<td class="key"><label>' . JText::_('ADD_POINTS') . '</label></td>
				<td><input type="text" name="data[points_value]" value="0"/></td>
			</tr>';
        } else {
            $ret .= '<tr>
				<td class="key"><label>' . JText::_('POINTS_VALUE') . '</label></td>
				<td><input type="text" name="data[points_value]" value=""/></td>
			</tr>';
        }
        return $ret;
    }
Ejemplo n.º 10
0
 public function onPackGeneratorTypeDisplay(&$values)
 {
     parent::listPlugins('timelimitedgen', $values);
 }
Ejemplo n.º 11
0
 public function onBeforeSerialConsume(&$serial, $user_id, &$do, &$extra_data)
 {
     if (empty($user_id)) {
         $user_id = hikaserial::loadUser();
     }
     $app = JFactory::getApplication();
     $products_added = array();
     $ids = array();
     $product_qty = array();
     $current_products = $app->getUserState('com_hikaserial.plg_productaddconsumer.products', array());
     if (!empty($current_products)) {
         $current_products[$serial->serial_id] = array();
         foreach ($current_products as $serial_id => $products) {
             foreach ($products as $product_id) {
                 if (empty($product_qty[$product_id])) {
                     $product_qty[$product_id] = 0;
                 }
                 $product_qty[$product_id]++;
             }
         }
     }
     parent::listPlugins('productaddconsumer', $ids, false);
     foreach ($ids as $id) {
         parent::pluginParams($id);
         if ($this->plugin_params->pack_id == $serial->serial_pack_id) {
             if (empty($user_id)) {
                 $app->enqueueMessage(JText::_('PLEASE_LOGIN'));
                 $do = false;
                 return;
             } elseif ($serial->serial_user_id != 0 && $serial->serial_user_id != $user_id) {
                 $app->enqueueMessage(JText::_('NOT_YOUR_SERIAL'));
                 $do = false;
                 return;
             }
             if (empty($product_qty[$this->plugin_params->product_id])) {
                 $product_qty[$this->plugin_params->product_id] = 1;
             } else {
                 $product_qty[$this->plugin_params->product_id]++;
             }
             $this->addProductToCart($this->plugin_params->product_id, $product_qty[$this->plugin_params->product_id]);
             if (empty($products_added[$serial->serial_id])) {
                 $products_added[$serial->serial_id] = array();
             }
             $products_added[$serial->serial_id][] = $this->plugin_params->product_id;
         }
     }
     if (!empty($products_added)) {
         if (!empty($current_products)) {
             foreach ($current_products as $serial_id => $products) {
                 if (empty($products_added[$serial_id])) {
                     $products_added[$serial_id] = $products;
                 } else {
                     $products_added[$serial_id] = array_merge($products_added[$serial_id], $products);
                 }
             }
         }
         $app->enqueueMessage(JText::_('PRODUCT_ADDED_TO_YOUR_CART'));
         $app->setUserState('com_hikaserial.plg_productaddconsumer.products', $products_added);
         $serial->managed = true;
         if (empty($serial->serial_user_id)) {
             $updateSerial = new stdClass();
             $updateSerial->serial_id = $serial->serial_id;
             $updateSerial->serial_user_id = $user_id;
             $serialClass = hikaserial::get('class.serial');
             $serialClass->save($updateSerial);
         }
     }
 }