Example #1
0
 public static function getProductProperties($lang_id, $row, JeproshopContext $context = null)
 {
     if (!$row->product_id) {
         return false;
     }
     if ($context == null) {
         $context = JeproshopContext::getContext();
     }
     // Product::getDefaultAttribute is only called if id_product_attribute is missing from the SQL query at the origin of it:
     // consider adding it in order to avoid unnecessary queries
     $row->allow_out_of_stock_ordering = JeproshopProductModelProduct::isAvailableWhenOutOfStock($row->out_of_stock);
     if (JeproshopCombinationModelCombination::isFeaturePublished() && (!isset($row->product_attribute_id) || !$row->product_attribute_id) && (isset($row->cache_default_attribute) && ($default_product_attribute_id = $row->cache_default_attribute) !== null || ($default_product_attribute_id = JeproshopProductModelProduct::getDefaultAttribute($row->product_id, !$row->allow_out_of_stock_ordering)))) {
         $row->product_attribute_id = $default_product_attribute_id;
     }
     if (!JeproshopCombinationModelCombination::isFeaturePublished() || !isset($row->product_attribute_id)) {
         $row->product_attribute_id = 0;
     }
     // Tax
     $useTax = JeproshopTaxModelTax::taxExcludedOption();
     $cache_key = $row->product_id . '_' . $row->product_attribute_id . '_' . $lang_id . '_' . (int) $useTax;
     if (isset($row->product_pack_id)) {
         $cache_key .= '_pack_' . $row->product_pack_id;
     }
     if (isset(self::$_productPropertiesCache[$cache_key])) {
         return JeproshopTools::updateObjectData($row, self::$_productPropertiesCache[$cache_key]);
     }
     // Datas
     $row->category = JeproshopCategoryModelCategory::getLinkRewrite((int) $row->default_category_id, (int) $lang_id);
     $row->link = $context->controller->getProductLink((int) $row->product_id, $row->link_rewrite, $row->category, $row->ean13);
     $row->attribute_price = 0;
     if (isset($row->product_attribute_id) && $row->product_attribute_id) {
         $row->attribute_price = (double) JeproshopProductModelProduct::getProductAttributePrice($row->product_attribute_id);
     }
     $row->price_tax_exc = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, self::$_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED ? 2 : 6);
     if (self::$_taxCalculationMethod == COM_JEPROSHOP_TAX_EXCLUDED) {
         $row->price_tax_exc = JeproshopTools::roundPrice($row->price_tax_exc, 2);
         $row->price = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 6);
         $row->price_without_reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, false);
     } else {
         $row->price = JeproshopTools::roundPrice(JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2), 2);
         $row->price_without_reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) && !empty($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 6, null, false, false);
     }
     $specific_prices = null;
     $row->reduction = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, (bool) $useTax, (int) $row->product_attribute_id, 6, null, true, true, 1, true, null, null, null, $specific_prices);
     $row->specific_prices = $specific_prices;
     $row->quantity = JeproshopProductModelProduct::getQuantity((int) $row->product_id, 0, isset($row->cache_is_pack) ? $row->cache_is_pack : null);
     $row->quantity_all_versions = $row->quantity;
     if ($row->product_attribute_id) {
         $row->quantity = JeproshopProductModelProduct::getQuantity((int) $row->product_id, $row->product_attribute_id, isset($row->cache_is_pack) ? $row->cache_is_pack : null);
     }
     $row->image_id = JeproshopProductModelProduct::defineProductImage($row, $lang_id);
     $row->features = JeproshopProductModelProduct::getFrontStaticFeatures((int) $lang_id, $row->product_id);
     $row->attachments = array();
     if (!isset($row->cache_has_attachments) || $row->cache_has_attachments) {
         $row->attachments = JeproshopProductModelProduct::getStaticAttachments((int) $lang_id, $row->product_id);
     }
     $row->virtual = !isset($row->is_virtual) || $row->is_virtual ? 1 : 0;
     // Pack management
     $row->pack = !isset($row->cache_is_pack) ? JeproshopProductPack::isPack($row->product_id) : (int) $row->cache_is_pack;
     $row->packItems = $row->pack ? JeproshopProductPack::getItemTable($row->product_id, $lang_id) : array();
     $row->no_pack_price = $row->pack ? JeproshopProductPack::noPackPrice($row->product_id) : 0;
     if ($row->pack && !JeproshopProductPack::isInStock($row->product_id)) {
         $row->quantity = 0;
     }
     $row->customization_required = false;
     if (isset($row->customizable) && $row->customizable && JeproshopCustomization::isFeaturePublished()) {
         if (count(JeproshopProductModelProduct::getStaticRequiredCustomizableFields((int) $row->product_id))) {
             $row->customization_required = true;
         }
     }
     $row = JeproshopProductModelProduct::getTaxesInformations($row, $context);
     self::$_productPropertiesCache[$cache_key] = $row;
     return self::$_productPropertiesCache[$cache_key];
 }
Example #2
0
 public function renderView($tpl = null)
 {
     $app = JFactory::getApplication();
     if (!isset($this->context) && null == $this->context) {
         $this->context = JeproshopContext::getContext();
     }
     if (!isset($this->context->cart)) {
         $this->context->cart = new JeproshopCartModelCart();
     }
     if (!$this->context->controller->isInitialized()) {
         $this->initialize();
     }
     $useSSL = isset($this->context->controller->ssl_enabled) && $this->context->controller->ssl_enabled && $app->input->get('enable_ssl') || JeproshopTools::usingSecureMode() ? true : false;
     $protocol_content = $useSSL ? 'https://' : 'http://';
     $this->loadObject();
     if (JeproshopProductPack::isPack((int) $this->product->product_id) && !JeproshopProductPack::isInStock((int) $this->product->product_id)) {
         $this->product->quantity = 0;
     }
     $this->product->description = $this->transformDescriptionWithImg($this->product->description);
     // Assign to the template the id of the virtual product. "0" if the product is not downloadable.
     $virtual = JeproshopProductDownloadModelProductDownload::getIdFromProductId((int) $this->product->product_id);
     $this->assignRef('virtual', $virtual);
     $customization_form_target = JeproshopTools::safeOutput(urldecode($_SERVER['REQUEST_URI']));
     $this->assignRef('customization_form_target', $customization_form_target);
     $delete_picture = $app->input->get('delete_picture');
     if ($app->input->get('submit_customized_datas')) {
         // If cart has not been saved, we need to do it so that customization fields can have an id_cart
         // We check that the cookie exists first to avoid ghost carts
         if (!$this->context->cart->cart_id && isset($_COOKIE[$this->context->cookie->getName()])) {
             $this->context->cart->add();
             $this->context->cookie->cart_id = (int) $this->context->cart->cart_id;
         }
         $this->pictureUpload();
         $this->textRecord();
         $this->formTargetFormat();
     } else {
         if (isset($delete_picture) && !$this->context->cart->deleteCustomizationToProduct($this->product->product_id, $app->input->get('delete_picture'))) {
             $this->errors[] = JText::_('An error occurred while deleting the selected picture.');
         }
     }
     $pictures = array();
     $text_fields = array();
     if ($this->product->customizable) {
         $files = $this->context->cart->getProductCustomization($this->product->product_id, JeproshopProductModelProduct::CUSTOMIZE_FILE, true);
         foreach ($files as $file) {
             $pictures['pictures_' . $this->product->product_id . '_' . $file['index']] = $file['value'];
         }
         $texts = $this->context->cart->getProductCustomization($this->product->product_id, JeproshopProductModelProduct::CUSTOMIZE_TEXT_FIELD, true);
         foreach ($texts as $text_field) {
             $text_fields['textFields_' . $this->product->product_id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
         }
     }
     $this->assignRef('pictures', $pictures);
     $this->assignRef('textFields', $text_fields);
     $this->product->customization_required = false;
     $customizationFields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->lang_id) : false;
     if (is_array($customizationFields)) {
         foreach ($customizationFields as $customizationField) {
             if ($this->product->customization_required = $customizationField['required']) {
                 break;
             }
         }
     }
     // Assign template vars related to the category + execute hooks related to the category
     $this->assignCategory();
     // Assign template vars related to the price and tax
     $this->assignPriceAndTax();
     // Assign template vars related to the images
     $this->assignImages();
     // Assign attribute groups to the template
     $this->assignAttributesGroups();
     // Assign attributes combinations to the template
     $this->assignAttributesCombinations();
     // Pack management
     $pack_items = $this->product->cache_is_pack ? JeproshopProductPack::getItemTable($this->product->product_id, $this->context->language->lang_id, true) : array();
     $this->assignRef('packItems', $pack_items);
     $packs = JeproshopProductPack::getPacksTable($this->product->product_id, $this->context->language->lang_id, true, 1);
     $this->assignRef('packs', $packs);
     if (isset($this->category->category_id) && $this->category->category_id) {
         $return_link = JeproshopTools::safeOutput($this->context->controller->getCategoryLink($this->category));
     } else {
         $return_link = 'javascript: history.back();';
     }
     if (!$this->context->controller->useMobileTheme()) {
     }
     //'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
     //		'customizationFields' => $customizationFields,
     $accessories = $this->product->getAccessories($this->context->language->lang_id);
     $this->assignRef('accessories', $accessories);
     $enable_jqzoom = JeproshopSettingModelSetting::getValue('enable_jqzoom');
     $this->assignRef('jqZoomEnabled', $enable_jqzoom);
     $manufacturer = new JeproshopManufacturerModelManufacturer((int) $this->product->manufacturer_id, $this->context->language->lang_id);
     $this->assignRef('product_manufacturer', $manufacturer);
     $features = $this->product->getFrontFeatures($this->context->language->lang_id);
     $this->assignRef('features', $features);
     $attachments = $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->lang_id) : array();
     $this->assignRef('attachments', $attachments);
     $display_discount_price = JeproshopSettingModelSetting::getValue('display_discount_price');
     $this->assignRef('display_discount_price', $display_discount_price);
     $this->assignRef('return_link', $return_link);
     $content_only = $app->input->get('content_only');
     $this->assignRef('content_only', $content_only);
     $last_quantities = JeproshopSettingModelSetting::getValue('last_quantities');
     $this->assignRef('last_quantities', $last_quantities);
     $display_quantities = JeproshopSettingModelSetting::getValue('display_quantities');
     $this->assignRef('display_quantities', $display_quantities);
     $allow_out_of_stock_ordering = JeproshopSettingModelSetting::getValue('allow_out_of_stock_ordering');
     $this->assignRef('allow_out_of_stock_ordering', $allow_out_of_stock_ordering);
     $catalog_mode = (bool) (JeproshopSettingModelSetting::getValue('catalog_mode') || !JeproshopGroupModelGroup::getCurrent()->show_prices);
     $this->assignRef('catalog_mode', $catalog_mode);
     $extra_left = null;
     $this->assignRef('extra_left', $extra_left);
     $extra_right = null;
     $this->assignRef('extra_right', $extra_right);
     parent::display($tpl);
 }