예제 #1
0
 public function getLabels($product_id)
 {
     if (!defined('JOURNAL_INSTALLED')) {
         return array();
     }
     /* get latest label */
     if ($this->journal2->settings->get('label_latest_status', 'always') !== 'never') {
         if (self::$latest === null) {
             self::$latest = $this->model_catalog_product->getLatestProducts($this->journal2->settings->get('label_latest_limit', 10));
         }
         if (!$this->hasLabel($product_id, 'latest') && is_array(self::$latest)) {
             foreach (self::$latest as $product) {
                 if ($product_id == $product['product_id']) {
                     $this->addLabel($product_id, 'latest', $this->journal2->settings->get('label_latest_text', 'New'));
                     break;
                 }
             }
         }
     }
     $product = $this->model_catalog_product->getProduct($product_id);
     /* get special label */
     if ($this->journal2->settings->get('label_special_status', 'always') !== 'never') {
         if ((double) $product['special']) {
             if ($this->journal2->settings->get('label_special_type', 'percent') === 'percent') {
                 if ($this->config->get('config_customer_price') && $this->customer->isLogged() || !$this->config->get('config_customer_price')) {
                     $price = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));
                 } else {
                     $price = false;
                 }
                 $special = $this->tax->calculate($product['special'], $product['tax_class_id'], $this->config->get('config_tax'));
                 if ($price > 0.0) {
                     $this->addLabel($product_id, 'sale', '-' . round(($price - $special) / $price * 100) . '%');
                 }
             } else {
                 $this->addLabel($product_id, 'sale', $this->journal2->settings->get('label_special_text', 'Sale'));
             }
         }
     }
     /* get stock label */
     if ($product['quantity'] <= 0 && Journal2Utils::canGenerateImages()) {
         $this->addLabel($product_id, 'outofstock', $product['stock_status']);
     }
     if (!isset(self::$cache[$product_id])) {
         return array();
     }
     return self::$cache[$product_id];
 }