Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * Loads the selected template
  * @param $get $_GET
  * @author Sam West aka Nimmit - osc@kangaroopartners.com
  * @return array selected template
  */
 function loadTemplate($get)
 {
     $this->getAndPrepare('template_id', $get, $templateId);
     $allProductsOptionsAndValues = $this->getAllProductOptionsAndValues();
     // used for checking the option still actualy exists in the database
     $allOptions = array_keys($this->getAllOptions());
     $allOptionValues = array_keys($this->getAllOptionValues());
     // first delete all the products existing options
     foreach ($allProductsOptionsAndValues as $optionId => $dontNeed) {
         $this->removeOptionFromProduct(array('option_id' => $optionId));
     }
     // now add the ones in the template
     $allTemplatesAttributes = $this->getAllTemplatesAndAttributes();
     //echo '<br><br>Array ALLTEMPANDATTRIBS:: <br><br>';
     //print_r($allTemplatesAttributes);
     $actionTaken = false;
     if (is_array($allTemplatesAttributes[$templateId])) {
         foreach ($allTemplatesAttributes[$templateId] as $optionsId => $values) {
             // check that the option id in the template is still in the database
             if (in_array($optionsId, $allOptions)) {
                 if (is_array($values)) {
                     foreach ($values as $optionValuesId) {
                         // check that the option values id still exists in the database
                         if (in_array($optionValuesId, $allOptionValues)) {
                             if (!AM_USE_SORT_ORDER && !AM_USE_QT_PRO) {
                                 $this->addAttributeToProduct(array('option_id' => $optionsId, 'option_value_id' => $optionValuesId, 'price' => $allTemplatesAttributes[$templateId]['options_values_price'][$optionValuesId], 'prefix' => $allTemplatesAttributes[$templateId]['price_prefix'][$optionValuesId], 'weight' => $allTemplatesAttributes[$templateId]['options_values_weight'][$optionValuesId], 'weight_prefix' => $allTemplatesAttributes[$templateId]['weight_prefix'][$optionValuesId]));
                             }
                             if (AM_USE_SORT_ORDER && !AM_USE_QT_PRO) {
                                 //								  echo 'TempID '.$templateId . ' OPTvalID ' . $optionValuesId . ' ';
                                 $this->addAttributeToProduct(array('option_id' => $optionsId, 'option_value_id' => $optionValuesId, 'price' => $allTemplatesAttributes[$templateId]['options_values_price'][$optionValuesId], 'prefix' => $allTemplatesAttributes[$templateId]['price_prefix'][$optionValuesId], 'sortOrder' => $allTemplatesAttributes[$templateId]['sortOrder'][$optionValuesId], 'weight' => $allTemplatesAttributes[$templateId]['options_values_weight'][$optionValuesId], 'weight_prefix' => $allTemplatesAttributes[$templateId]['weight_prefix'][$optionValuesId]));
                             }
                             if (AM_USE_QT_PRO && !AM_USE_SORT_ORDER) {
                                 $this->addAttributeToProduct(array('option_id' => $optionsId, 'option_value_id' => $optionValuesId, 'price' => $allTemplatesAttributes[$templateId]['options_values_price'][$optionValuesId], 'prefix' => $allTemplatesAttributes[$templateId]['price_prefix'][$optionValuesId], 'stockTracking' => '0', 'weight' => $allTemplatesAttributes[$templateId]['options_values_weight'][$optionValuesId], 'weight_prefix' => $allTemplatesAttributes[$templateId]['weight_prefix'][$optionValuesId]));
                             }
                             if (AM_USE_QT_PRO && AM_USE_SORT_ORDER) {
                                 $this->addAttributeToProduct(array('option_id' => $optionsId, 'option_value_id' => $optionValuesId, 'price' => $allTemplatesAttributes[$templateId]['options_values_price'][$optionValuesId], 'prefix' => $allTemplatesAttributes[$templateId]['price_prefix'][$optionValuesId], 'sortOrder' => $allTemplatesAttributes[$templateId]['sortOrder'][$optionValuesId], 'stockTracking' => '0', 'weight' => $allTemplatesAttributes[$templateId]['options_values_weight'][$optionValuesId], 'weight_prefix' => $allTemplatesAttributes[$templateId]['weight_prefix'][$optionValuesId]));
                             }
                             $actionTaken = true;
                         } else {
                             // the option value no longer exists in the databse, delete if from all templates
                             amDB::query("delete from " . AM_TABLE_ATTRIBUTES_TO_TEMPLATES . " where  option_values_id = '{$optionValuesId}'");
                         }
                     }
                 }
             } else {
                 // the option no longer exists in the databse, delete it from all templates
                 amDB::query("delete from " . AM_TABLE_ATTRIBUTES_TO_TEMPLATES . " where  options_id = '{$optionsId}'");
             }
         }
     }
     // if something has been loaded reset the options and values
     if ($actionTaken) {
         $this->getAllProductOptionsAndValues(true);
     } else {
         $this->arrAllProductOptionsAndValues = $allProductsOptionsAndValues;
     }
     return array('selectedTemplate' => $templateId);
 }
 /**
  * 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;
 }
 /**
  * Loads the selected template
  * @param $get $_GET
  * @author Sam West aka Nimmit - osc@kangaroopartners.com
  * @return array selected template
  */
 function loadTemplate($get)
 {
     $this->getAndPrepare('template_id', $get, $templateId);
     $allProductsOptionsAndValues = $this->getAllProductOptionsAndValues();
     // used for checking the option still actualy exists in the database
     $allOptions = array_keys($this->getAllOptions());
     $allOptionValues = array_keys($this->getAllOptionValues());
     // first delete all the products existing options
     foreach ($allProductsOptionsAndValues as $optionId => $dontNeed) {
         $this->removeOptionFromProduct(array('option_id' => $optionId));
     }
     // now add the ones in the template
     $allTemplatesAttributes = $this->getAllTemplatesAndAttributes();
     $actionTaken = false;
     if (is_array($allTemplatesAttributes[$templateId])) {
         foreach ($allTemplatesAttributes[$templateId] as $optionsId => $values) {
             // check that the option id in the template is still in the database
             if (in_array($optionsId, $allOptions)) {
                 if (is_array($values)) {
                     foreach ($values as $optionValuesId) {
                         // check that the option values id still exists in the database
                         if (in_array($optionValuesId, $allOptionValues)) {
                             $this->addAttributeToProduct(array('option_id' => $optionsId, 'option_value_id' => $optionValuesId, 'price' => '0.00', 'prefix' => ''));
                             $actionTaken = true;
                         } else {
                             // the option value no longer exists in the databse, delete if from all templates
                             amDB::query("delete from " . AM_TABLE_ATTRIBUTES_TO_TEMPLATES . " where  option_values_id = '{$optionValuesId}'");
                         }
                     }
                 }
             } else {
                 // the option no longer exists in the databse, delete it from all templates
                 amDB::query("delete from " . AM_TABLE_ATTRIBUTES_TO_TEMPLATES . " where  options_id = '{$optionsId}'");
             }
         }
     }
     // if somthing has been loaded reset the options and values
     if ($actionTaken) {
         $this->getAllProductOptionsAndValues(true);
     } else {
         $this->arrAllProductOptionsAndValues = $allProductsOptionsAndValues;
     }
     return array('selectedTemplate' => $templateId);
 }
 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);
         }
     }
 }