/** * Check product availability * * @param integer $qty Quantity desired * @return boolean True if product is available with this quantity */ public function checkQuantity($qty) { if (JeproshopProductPack::isPack((int) $this->product_id) && !JeproshopProductPack::isInStock((int) $this->product_id)) { return false; } if ($this->isAvailableWhenOutOfStock(JeproshopStockAvailableModelStockAvailable::outOfStock($this->product_id))) { return true; } if (isset($this->product_attribute_id)) { $product_attribute_id = $this->product_attribute_id; } else { $product_attribute_id = 0; } return $qty <= JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct($this->product_id, $product_attribute_id); }
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); }