예제 #1
0
 /**
  * Get the original price before any discounts are applied.
  *
  * @since 1.0
  *
  * @param bool $format
  *
  * @return float|string
  */
 public function get_original_price($format = false)
 {
     $base_price = $this->upgrade_product->get_feature('base-price');
     if (!empty($this->variant_hash)) {
         $variants = $this->upgrade_product->get_feature('base-price', array('setting' => 'variants'));
         if (isset($variants[$this->variant_hash])) {
             $base_price = $variants[$this->variant_hash]['value'];
         }
     }
     return $format ? it_exchange_format_price($base_price) : $base_price;
 }
예제 #2
0
 /**
  * (PHP 5 &gt;= 5.1.0)<br/>
  * Constructs the object
  *
  * @link http://php.net/manual/en/serializable.unserialize.php
  *
  * @param string $serialized <p>
  *                           The string representation of the object.
  *                           </p>
  *
  * @return void
  */
 public function unserialize($serialized)
 {
     $data = unserialize($serialized);
     $this->product = itelic_get_product($data['product']);
     $this->feature_data = $this->product->get_feature('licensing-discount');
     $this->key = itelic_get_key($data['key']);
 }
예제 #3
0
 /**
  * Check if a key is renewable.
  *
  * @since 1.0
  *
  * @return bool
  */
 public function is_renewable()
 {
     if ($this->get_expires() === null) {
         return false;
     }
     return $this->product->has_feature('recurring-payments');
 }
/**
 * Generate a key for a certain transaction product.
 *
 * @internal
 *
 * @since 1.0
 *
 * @param \IT_Exchange_Transaction $transaction
 * @param Product                  $product
 * @param Factory                  $factory
 * @param string                   $status Optionally override the new key's status. Default active.
 * @param string                   $key    Optionally specify the license key to be used. If empty, uses Factory.
 *
 * @return Key
 */
function generate_key_for_transaction_product(\IT_Exchange_Transaction $transaction, Product $product, Factory $factory, $status = '', $key = '')
{
    $customer = it_exchange_get_transaction_customer($transaction);
    if (!$customer instanceof \IT_Exchange_Customer) {
        $customer = new \IT_Exchange_Customer($customer);
    }
    if (!$key) {
        $key = $factory->make();
    }
    foreach ($transaction->get_products() as $tran_product) {
        if ($tran_product['product_id'] == $product->ID) {
            if (empty($tran_product['itemized_data'])) {
                continue;
            }
            if (is_string($tran_product['itemized_data'])) {
                $itemized = maybe_unserialize($tran_product['itemized_data']);
            } else {
                $itemized = $tran_product['itemized_data'];
            }
            if (isset($itemized['it_variant_combo_hash'])) {
                $hash = $itemized['it_variant_combo_hash'];
                $max = $product->get_feature('licensing', array('field' => 'limit', 'for_hash' => $hash));
            }
        }
    }
    if (!isset($max)) {
        $max = $product->get_feature('licensing', array('field' => 'limit'));
    }
    if (!$product->has_feature('recurring-payments')) {
        $expires = null;
    } else {
        $type = $product->get_feature('recurring-payments', array('setting' => 'interval'));
        $count = $product->get_feature('recurring-payments', array('setting' => 'interval-count'));
        $interval = convert_rp_to_date_interval($type, $count);
        $expires = make_date_time($transaction->post_date_gmt);
        $expires->add($interval);
    }
    return Key::create($key, $transaction, $product, $customer, $max, $expires, $status);
}
예제 #5
0
 /**
  * Get variant limit value for a product.
  *
  * @param \ITELIC\Product $product
  *
  * @return array|string
  */
 protected function get_variant_limit_for_product(\ITELIC\Product $product)
 {
     if (!function_exists('it_exchange_variants_addon_get_product_feature_controller')) {
         return 'disabled';
     }
     $c = it_exchange_variants_addon_get_product_feature_controller($product->ID, 'base-price', array('setting' => 'variants'));
     $hashes = $product->get_feature('licensing', array('field' => 'activation_variant'));
     $return = array();
     foreach ($c->post_meta as $hash => $variant) {
         $limit = empty($hashes[$hash]) ? 'Unlimited' : $hashes[$hash];
         $return[] = array('combo' => $variant['combos_title'], 'limit' => $limit, 'hash' => $hash);
     }
     return $return;
 }
예제 #6
0
    /**
     * Outputs the change log edit popup.
     *
     * @since 1.0
     */
    public function changelog_popup()
    {
        if (isset($_GET['post'])) {
            $ID = $_GET['post'];
        } else {
            $ID = false;
        }
        ?>

		<div id="itelic-edit-changelog-popup" style="display: none">
			<div class="wrap changelog-wrap">
				<?php 
        echo $ID ? Product::get($ID)->get_changelog() : '';
        ?>
			</div>
		</div>

		<?php 
    }
예제 #7
0
 /**
  * Perform the activation.
  *
  * Updates the version in product meta, and store the previous version.
  * Updates the file in the download meta, and store the previous file.
  *
  * @since 1.0
  *
  * @param Product  $product
  * @param \WP_Post $file
  * @param string   $version
  */
 protected static function do_activation(Product $product, \WP_Post $file, $version)
 {
     $download_id = $product->get_feature('licensing', array('field' => 'update-file'));
     $download_data = get_post_meta($download_id, '_it-exchange-download-info', true);
     $old_url = isset($download_data['source']) ? $download_data['source'] : '';
     // update the download url
     $download_data['source'] = wp_get_attachment_url($file->ID);
     // save the new download
     update_post_meta($download_id, '_it-exchange-download-info', $download_data);
     $download = get_post($download_id);
     // check if the download name is being stored as the plugin file
     // if it is, we want to update the download name.
     if (preg_replace('/\\.[^.]+$/', '', basename($old_url)) == $download->post_title) {
         wp_update_post(array('ID' => $download_id, 'post_title' => preg_replace('/\\.[^.]+$/', '', basename(get_attached_file($file->ID)))));
     }
     $product->update_feature('licensing', array('version' => $version));
 }
예제 #8
0
/**
 * Retrieve a product.
 *
 * @api
 *
 * @since 1.0
 *
 * @param int $ID
 *
 * @return \ITELIC\Product|null
 */
function itelic_get_product($ID)
{
    return \ITELIC\Product::get($ID);
}