public function getProductMinDeliveryTime($product_id = 0, $section_id = 0, $section = '', $loadDiv = 1) { $db = JFactory::getDbo(); $helper = new redhelper(); if (!$section_id && !$section) { $query = "SELECT min_del_time as deltime, s.max_del_time, s.delivery_time " . " FROM " . $this->_table_prefix . "product_stockroom_xref AS ps , " . $this->_table_prefix . "stockroom as s " . " WHERE " . " ps.product_id = " . (int) $product_id . " AND ps.stockroom_id = s.stockroom_id and ps.quantity >0 ORDER BY min_del_time ASC LIMIT 0,1"; } else { $query = "SELECT min_del_time as deltime, s.max_del_time, s.delivery_time " . " FROM " . $this->_table_prefix . "product_attribute_stockroom_xref AS pas , " . $this->_table_prefix . "stockroom as s " . " WHERE " . " pas.section_id = " . (int) $section_id . " AND pas.section = " . $db->quote($section) . " AND pas.stockroom_id = s.stockroom_id and pas.quantity >0 ORDER BY min_del_time ASC LIMIT 0,1"; } $this->_db->setQuery($query); $result = $this->_db->loadObject(); $product_delivery_time = ''; if ($result) { if (!$section_id && !$section) { $sql = "SELECT min_del_time as deltime, s.max_del_time,s.delivery_time " . " FROM " . $this->_table_prefix . "stockroom as s, " . $this->_table_prefix . "product_stockroom_xref AS ps " . " WHERE " . " ps.product_id = " . (int) $product_id . " AND ps.stockroom_id = s.stockroom_id AND s.min_del_time = " . (int) $result->deltime . " and ps.quantity >=0 ORDER BY max_del_time ASC LIMIT 0,1"; } else { $sql = "SELECT min_del_time as deltime, s.max_del_time,s.delivery_time " . " FROM " . $this->_table_prefix . "stockroom as s, " . $this->_table_prefix . "product_attribute_stockroom_xref AS pas " . " WHERE " . " pas.section_id = " . (int) $section_id . " AND pas.section = '" . $db->quote($section) . "' AND pas.stockroom_id = s.stockroom_id AND s.min_del_time = " . (int) $result->deltime . " AND pas.quantity >=0 ORDER BY max_del_time ASC LIMIT 0,1"; } $this->_db->setQuery($sql); $row = $this->_db->loadObject(); if ($row->deltime == 0 || $row->deltime == ' ') { $product_delivery_time = ''; } else { if ($row->delivery_time == "Days") { $duration = JText::_('COM_REDSHOP_DAYS'); } else { $row->deltime = $row->deltime / 7; $row->max_del_time = $row->max_del_time / 7; $duration = JText::_('COM_REDSHOP_WEEKS'); } $product_delivery_time = (int) $row->deltime . "-" . (int) $row->max_del_time . " " . $duration; } } /** * redCRM includes */ if ($helper->isredCRM()) { if (ENABLE_ITEM_TRACKING_SYSTEM) { // Supplier order helper object $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $sendData = new stdClass(); $sendData->product_id = $product_id; $sendData->property_id = 0; $sendData->subproperty_id = 0; if ($section == 'property') { $sendData->property_id = $section_id; } elseif ($section == 'subproperty') { // Get data for property id $subattribute_data = $this->getAttibuteSubProperty($section_id); $sendData->property_id = $subattribute_data[0]->subattribute_id; $sendData->subproperty_id = $section_id; } $product_delivery_time = $crmSupplierOrderHelper->getProductDeliveryTime($sendData); $dayLanguage = strlen($product_delivery_time) == 1 && $product_delivery_time == 1 ? JText::_('COM_REDSHOP_DAY') : JText::_('COM_REDSHOP_DAYS'); $product_delivery_time = $product_delivery_time . " " . $dayLanguage; } } if ($product_delivery_time && $loadDiv) { $product_delivery_time = '<div id="ProductAttributeMinDelivery' . $product_id . '">' . $product_delivery_time . '</div>'; } return $product_delivery_time; }