public function execute()
 {
     $order_id = waRequest::get('order_id', null, waRequest::TYPE_INT);
     $customer_id = waRequest::get('customer_id', null, waRequest::TYPE_INT);
     $order_id = $order_id ? $order_id : null;
     $currency = waRequest::get('currency');
     if (!$currency && $order_id) {
         $order_model = new shopOrderModel();
         $order = $order_model->getOrder($order_id);
         $currency = $order['currency'];
     }
     $product_id = waRequest::get('product_id', 0, waRequest::TYPE_INT);
     if (!$product_id) {
         $this->errors[] = _w("Unknown product");
         return;
     }
     $sku_id = waRequest::get('sku_id', 0, waRequest::TYPE_INT);
     if ($sku_id) {
         $sku = $this->getSku($sku_id, $order_id);
         $skus = shopPricePlugin::prepareSkus(array($sku_id => $sku), $customer_id);
         if (!empty($skus[$sku_id])) {
             $sku = $skus[$sku_id];
         }
         $this->response['sku'] = $sku;
         $this->response['service_ids'] = array_keys($sku['services']);
     } else {
         $product = $this->getProduct($product_id, $order_id);
         $products = shopPricePlugin::prepareProducts(array($product_id => $product), $customer_id, $currency);
         if (!empty($products[$product_id])) {
             $product = $products[$product_id];
         }
         $product['skus'] = shopPricePlugin::prepareSkus($product['skus'], $customer_id, $currency);
         foreach ($product['skus'] as &$sku) {
             if (isset($sku['price'])) {
                 $sku['price_str'] = wa_currency($sku['price'], $currency);
                 $sku['price_html'] = wa_currency_html($sku['price'], $currency);
             }
         }
         unset($sku);
         $this->response['product'] = $product;
         $this->response['sku_ids'] = array_keys($product['skus']);
         $this->response['service_ids'] = array_keys($product['services']);
     }
 }
Ejemplo n.º 2
0
function shop_currency($n, $in_currency = null, $out_currency = null, $format = true)
{
    /**
     * @var shopConfig $config
     */
    $config = wa('shop')->getConfig();
    $primary = $config->getCurrency(true);
    // current currency
    $currency = $config->getCurrency(false);
    if (!$in_currency) {
        $in_currency = $primary;
    }
    if ($in_currency === true || $in_currency === 1) {
        $in_currency = $currency;
    }
    if (!$out_currency) {
        $out_currency = $currency;
    }
    if ($in_currency != $out_currency) {
        $currencies = wa('shop')->getConfig()->getCurrencies(array($in_currency, $out_currency));
        if (isset($currencies[$in_currency]) && $in_currency != $primary) {
            $n = $n * $currencies[$in_currency]['rate'];
        }
        if ($out_currency != $primary) {
            $n = $n / ifempty($currencies[$out_currency]['rate'], 1.0);
        }
    }
    if ($format === 'h') {
        return wa_currency_html($n, $out_currency);
    } elseif ($format) {
        return wa_currency($n, $out_currency);
    } else {
        return str_replace(',', '.', $n);
    }
}