/** * Returns all results from a mysql query * @author Sam West aka Nimmit - osc@kangaroopartners.com * @param $strQuery string - mysql query * @return array - all results */ function getAll($strQuery) { $res = amDB::query($strQuery); $results = array(); while ($row = amDB::fetchArray($res)) { $results[] = $row; } return $results; }
/** * Returns an array of options with their related option values * @access protected * @author Sam West aka Nimmit - osc@kangaroopartners.com * @return array All options and option values */ function getAllOptionsAndValues() { if (0 === count($this->arrAllOptionsAndValues)) { $allOptions = $this->getAllOptions(); $allOptionValues = $this->getAllOptionValues(); $query = amDB::query("select * from " . TABLE_PRODUCTS_OPTIONS_VALUES_TO_PRODUCTS_OPTIONS); $optionsId = null; while ($res = amDB::fetchArray($query)) { if ($res['products_options_id'] != $optionsId) { $optionsId = $res['products_options_id']; $this->arrAllOptionsAndValues[$optionsId]['name'] = $allOptions[$optionsId]; } $this->arrAllOptionsAndValues[$optionsId]['values'][$res['products_options_values_id']] = $allOptionValues[$res['products_options_values_id']]; } // add any options that are not yet assigned to the tpovtpo table foreach ($allOptions as $optionId => $option) { if (!array_key_exists($optionId, $this->arrAllOptionsAndValues)) { $this->arrAllOptionsAndValues[$optionId]['name'] = $allOptions[$optionId]; } } } return $this->arrAllOptionsAndValues; }
/** * Returns all or the options and values in the database * @access public * @author Sam West aka Nimmit - osc@kangaroopartners.com * @return array */ function getAllProductOptionsAndValues($reset = false) { if (0 === count($this->arrAllProductOptionsAndValues) || true === $reset) { $this->arrAllProductOptionsAndValues = array(); $allOptionsAndValues = $this->getAllOptionsAndValues(); $queryString = "select * from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '{$this->intPID}' order by "; $queryString .= !AM_USE_SORT_ORDER ? "options_id" : AM_FIELD_OPTION_SORT_ORDER . ", " . AM_FIELD_OPTION_VALUE_SORT_ORDER; $query = amDB::query($queryString); $optionsId = null; while ($res = amDB::fetchArray($query)) { if ($res['options_id'] != $optionsId) { $optionsId = $res['options_id']; $this->arrAllProductOptionsAndValues[$optionsId]['name'] = $allOptionsAndValues[$optionsId]['name']; $this->arrAllProductOptionsAndValues[$optionsId]['track_stock'] = $allOptionsAndValues[$optionsId]['track_stock']; // Trial Rigadin QTPro if (AM_USE_SORT_ORDER) { $this->arrAllProductOptionsAndValues[$optionsId]['sort'] = $res[AM_FIELD_OPTION_SORT_ORDER]; } } $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['name'] = $allOptionsAndValues[$optionsId]['values'][$res['options_values_id']]; $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['price'] = $res['options_values_price']; $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['prefix'] = $res['price_prefix']; if (AM_USE_SORT_ORDER) { $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['sort'] = $res[AM_FIELD_OPTION_VALUE_SORT_ORDER]; } } } return $this->arrAllProductOptionsAndValues; }
function installMoreProductWeight() { if ($this->getValue('AM_USE_MPW') && !amSessionIsRegistered($this->getValue('AM_SESSION_MORE_PRODUCT_WEIGHT_INSTALL_CHECKED'))) { // check that the fields are in the weights table $weightFields = amDB::query("SHOW COLUMNS FROM " . TABLE_PRODUCTS_ATTRIBUTES); while ($field = amDB::fetchArray($weightFields)) { $pa_fields[] = $field['Field']; } $weightFields = amDB::query("SHOW COLUMNS FROM " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES); while ($field = amDB::fetchArray($weightFields)) { $opa_Fields[] = $field['Field']; } $weightFields = amDB::query("SHOW COLUMNS FROM " . $this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES')); while ($field = amDB::fetchArray($weightFields)) { $tmpl_Fields[] = $field['Field']; } $p_Type = ''; $weightFields = amDB::query("SHOW COLUMNS FROM " . TABLE_PRODUCTS); while ($field = amDB::fetchArray($weightFields)) { if ($field['Field'] == 'products_weight') { $p_Type = $field['Type']; break; } } // if not add them if (!in_array('weight_prefix', $pa_fields)) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN `weight_prefix` CHAR (1) NOT NULL"); } if (!in_array('attributes_stock', $pa_fields)) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN `attributes_stock` int(5) DEFAULT 0"); } if (!in_array('options_values_weight', $pa_fields)) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN `options_values_weight` DECIMAL (6,3) DEFAULT '0.000' NOT NULL"); } if (!in_array('weight_prefix', $opa_Fields)) { amDB::query("ALTER TABLE " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " ADD COLUMN `weight_prefix` CHAR (1) NOT NULL"); } if (!in_array('options_values_weight', $opa_Fields)) { amDB::query("ALTER TABLE " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " ADD COLUMN `options_values_weight` DECIMAL (6,3) DEFAULT '0.000' NOT NULL"); } if (!in_array('attributes_stock', $tmpl_Fields) && $this->getValue('AM_USE_SORT_ORDER')) { amDB::query("ALTER TABLE " . $this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES') . " ADD COLUMN `attributes_stock` int(5) DEFAULT 0"); } if (!in_array('weight_prefix', $tmpl_Fields) && $this->getValue('AM_USE_SORT_ORDER')) { amDB::query("ALTER TABLE " . $this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES') . " ADD COLUMN `weight_prefix` CHAR (1) NOT NULL default '+'"); } if (!in_array('options_values_weight', $tmpl_Fields) && $this->getValue('AM_USE_SORT_ORDER')) { amDB::query("ALTER TABLE " . $this->getValue('AM_TABLE_ATTRIBUTES_TO_TEMPLATES') . " ADD COLUMN `options_values_weight` DECIMAL (6,3) DEFAULT '0.000' NOT NULL"); } // change field size of product weight if ($p_Type != '' && $p_Type != strtoupper('DECIMAL(6,3)')) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS . " CHANGE `products_weight` `products_weight` DECIMAL(6,3) DEFAULT '0.000' NOT NULL"); } // register the checked session so that this check is only done once per session amSessionRegister($this->getValue('AM_SESSION_MORE_PRODUCT_WEIGHT_INSTALL_CHECKED'), true); } }
/** * Returns all or the options and values in the database * @access public * @author Sam West aka Nimmit - osc@kangaroopartners.com * @return array */ function getAllProductOptionsAndValues($reset = false) { if (0 === count($this->arrAllProductOptionsAndValues) || true === $reset) { $this->arrAllProductOptionsAndValues = array(); $allOptionsAndValues = $this->getAllOptionsAndValues(); //---------------------------- // Change: Add download attributes function for AM // @author Urs Nyffenegger ak mytool // Function: change query string to add the Download Table fields //----------------------------- $queryString = "select pa.*, pad.products_attributes_filename, pad.products_attributes_maxdays, pad.products_attributes_maxcount from " . TABLE_PRODUCTS_ATTRIBUTES . " as pa INNER JOIN " . TABLE_PRODUCTS_OPTIONS . " po ON pa.options_id=po.products_options_id"; $queryString .= " LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad ON pa.products_attributes_id = pad.products_attributes_id"; $queryString .= " where products_id = '{$this->intPID}' AND language_id=" . (int) $this->getSelectedLanaguage() . " order by "; $queryString .= !AM_USE_SORT_ORDER ? "products_options_name, pa.products_attributes_id" : AM_FIELD_OPTION_VALUE_SORT_ORDER; //---------------------------- // EOF Change: download attributes for AM //----------------------------- $query = amDB::query($queryString); $optionsId = null; while ($res = amDB::fetchArray($query)) { //print_R($res); if ($res['options_id'] != $optionsId) { $optionsId = $res['options_id']; $this->arrAllProductOptionsAndValues[$optionsId]['name'] = $allOptionsAndValues[$optionsId]['name']; // echo $this->arrAllProductOptionsAndValues[$optionsId]['name']; } $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['name'] = $allOptionsAndValues[$optionsId]['values'][$res['options_values_id']]; $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['price'] = $res['options_values_price']; $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['prefix'] = $res['price_prefix']; $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['stock'] = $res['attributes_stock']; if (AM_USE_MPW) { $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['weight'] = $res['options_values_weight']; $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['weight_prefix'] = $res['weight_prefix']; } //---------------------------- // Change: Add download attributes function for AM // @author Urs Nyffenegger ak mytool // Function: get the new Attributes //----------------------------- $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['products_attributes_id'] = $res['products_attributes_id']; $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['products_attributes_filename'] = $res['products_attributes_filename']; $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['products_attributes_maxdays'] = $res['products_attributes_maxdays']; $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['products_attributes_maxcount'] = $res['products_attributes_maxcount']; //---------------------------- // EOF Change: download attributes for AM //----------------------------- if (AM_USE_SORT_ORDER) { $this->arrAllProductOptionsAndValues[$optionsId]['values'][$res['options_values_id']]['sortOrder'] = $res[AM_FIELD_OPTION_VALUE_SORT_ORDER]; } } } return $this->arrAllProductOptionsAndValues; }
function installSortOrder() { if ($this->getValue('AM_USE_SORT_ORDER') && !amSessionIsRegistered($this->getValue('AM_SESSION_SORT_ORDER_INSTALL_CHECKED'))) { // register the checked session so that this check is only done once per session amSessionRegister($this->getValue('AM_SESSION_SORT_ORDER_INSTALL_CHECKED'), true); // check that the fields are in the attributes table $attributeFields = amDB::query("SHOW COLUMNS FROM " . TABLE_PRODUCTS_ATTRIBUTES); while ($field = amDB::fetchArray($attributeFields)) { $fields[] = $field['Field']; } $oInstalled = in_array($this->getValue('AM_FIELD_OPTION_SORT_ORDER'), $fields); $ovInstalled = in_array($this->getValue('AM_FIELD_OPTION_VALUE_SORT_ORDER'), $fields); // if not add them if (!$oInstalled) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN " . $this->getValue('AM_FIELD_OPTION_SORT_ORDER') . " INT UNSIGNED NOT NULL DEFAULT '0'"); } if (!$ovInstalled) { amDB::query("ALTER TABLE " . TABLE_PRODUCTS_ATTRIBUTES . " ADD COLUMN " . $this->getValue('AM_FIELD_OPTION_VALUE_SORT_ORDER') . " INT UNSIGNED NOT NULL DEFAULT '0'"); } // now reset all of the sort orders if (!$oInstalled || !$ovInstalled) { $allAttributes = amDB::getAll("select * from " . TABLE_PRODUCTS_ATTRIBUTES . " order by products_id, options_id, options_values_id"); $productId = $optionId = null; $oCount = $ovCount = 1; $updateValues = array(); if (is_array($allAttributes)) { foreach ($allAttributes as $attrib) { if ($productId != $attrib['products_id']) { $oCount = $ovCount = 0; } if ($optionId != $attrib['options_id']) { $oCount++; $ovCount = 0; } /** for dev only $updateValues[$attrib['products_attributes_id']]['prdoucts_id'] = $attrib['products_id']; $updateValues[$attrib['products_attributes_id']]['options_id'] = $attrib['options_id']; $updateValues[$attrib['products_attributes_id']]['options_values_id'] = $attrib['options_values_id']; **/ $updateValues[$attrib['products_attributes_id']]['option_sort'] = $oCount; $updateValues[$attrib['products_attributes_id']]['option_value_sort'] = ++$ovCount; $productId = $attrib['products_id']; $optionId = $attrib['options_id']; } foreach ($updateValues as $attributeId => $sorts) { amDB::query("update " . TABLE_PRODUCTS_ATTRIBUTES . " set " . $this->getValue('AM_FIELD_OPTION_SORT_ORDER') . " = '{$sorts['option_sort']}', " . $this->getValue('AM_FIELD_OPTION_VALUE_SORT_ORDER') . " = '{$sorts['option_value_sort']}' where products_attributes_id = '{$attributeId}' limit 1"); } } //echo '<pre style="text-align:left">'.print_r($updateValues,true); } } }