public function replaceProductInStock($product_id = 0, $data_add, $attributes = array(), $attribute_template = array()) { if (count($attribute_template) <= 0) { $attributes = array(); } $stock_status_flag = false; $totalatt = count($attributes); $Id = $product_id; $sec = "product"; $selectedpropertyId = 0; $selectedsubpropertyId = 0; for ($a = 0; $a < count($attributes); $a++) { $selectedId = array(); $property = $this->getAttibuteProperty(0, $attributes[$a]->attribute_id); if ($attributes[$a]->text != "" && count($property) > 0) { for ($i = 0; $i < count($property); $i++) { if ($property[$i]->setdefault_selected) { $selectedId[] = $property[$i]->property_id; } } if (count($selectedId) > 0) { if ($attributes[$a]->allow_multiple_selection) { $selectedpropertyId = implode(",", $selectedId); } else { $selectedpropertyId = $selectedId[count($selectedId) - 1]; } $Id = $selectedpropertyId; $sec = "property"; } if (count($selectedId) > 0) { $stock_status_flag = true; $i = count($selectedId) - 1; $subproperty = $this->getAttibuteSubProperty(0, $selectedId[$i]); $selectedId = array(); for ($sp = 0; $sp < count($subproperty); $sp++) { if ($subproperty[$sp]->setdefault_selected) { $selectedId[] = $subproperty[$sp]->subattribute_color_id; } } if (count($selectedId) > 0) { if ($subproperty[0]->setmulti_selected) { $selectedsubpropertyId = implode(",", $selectedId); } else { $selectedsubpropertyId = $selectedId[count($selectedId) - 1]; } $Id = $selectedsubpropertyId; $sec = "subproperty"; } } } } $stockroomhelper = new rsstockroomhelper(); $productinstock = $stockroomhelper->getStockAmountwithReserve($Id, $sec); if ($productinstock == 0) { $product_detail = $this->getProductById($product_id); $product_preorder = $product_detail->preorder; if ($product_preorder == "global" && ALLOW_PRE_ORDER || $product_preorder == "yes" || $product_preorder == "" && ALLOW_PRE_ORDER) { $productinpreorderstock = $stockroomhelper->getPreorderStockAmountwithReserve($Id, $sec); } } if (strstr($data_add, "{products_in_stock}")) { $data_add = str_replace("{products_in_stock}", JText::_('COM_REDSHOP_PRODUCT_IN_STOCK_LBL') . ' <span id="displayProductInStock' . $product_id . '">' . $productinstock . '</span>', $data_add); } if (strstr($data_add, "{product_stock_amount_image}")) { $stockamountList = $stockroomhelper->getStockAmountImage($Id, $sec, $productinstock); $stockamountImage = ""; if (count($stockamountList) > 0) { $thumbUrl = RedShopHelperImages::getImagePath($stockamountList[0]->stock_amount_image, '', 'thumb', 'stockroom', DEFAULT_STOCKAMOUNT_THUMB_WIDTH, DEFAULT_STOCKAMOUNT_THUMB_HEIGHT, USE_IMAGE_SIZE_SWAPPING); $stockamountImage = '<a class="imgtooltip"><span>'; $stockamountImage .= '<div class="spnheader">' . JText::_('COM_REDSHOP_STOCK_AMOUNT') . '</div>'; $stockamountImage .= '<div class="spnalttext" id="stockImageTooltip' . $product_id . '">' . $stockamountList[0]->stock_amount_image_tooltip . '</div></span>'; $stockamountImage .= '<img src="' . $thumbUrl . '" alt="' . $stockamountList[0]->stock_amount_image_tooltip . '" id="stockImage' . $product_id . '" /></a>'; } $data_add = str_replace("{product_stock_amount_image}", $stockamountImage, $data_add); } return $data_add; }