コード例 #1
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);
 }
コード例 #2
0
  
  

  
  
  Copyright © 2006 Kangaroo Partners
  http://kangaroopartners.com
  osc@kangaroopartners.com
*/
require_once 'attributeManager/classes/attributeManagerConfig.class.php';
require_once 'attributeManager/classes/amDB.class.php';
require_once 'attributeManager/classes/stopDirectAccess.class.php';
// Check the session var exists
if (is_array(${AM_SESSION_VAR_NAME}) && is_numeric($products_id)) {
    foreach (${AM_SESSION_VAR_NAME} as $newAttribute) {
        $newAttributeData = array('products_id' => $products_id, 'options_id' => amDB::input($newAttribute['options_id']), 'options_values_id' => amDB::input($newAttribute['options_values_id']), 'options_values_price' => amDB::input($newAttribute['options_values_price']), 'price_prefix' => amDB::input($newAttribute['price_prefix']));
        // insert it into the database
        amDB::perform(TABLE_PRODUCTS_ATTRIBUTES, $newAttributeData);
    }
    /**
     * Delete the temporary session var
     */
    amSessionUnregister(AM_SESSION_VAR_NAME);
    /**
     * remove the direct access authorization so that if the session is hijacked they wont be able
     * access the attributeManagerFile directly without first going to the product addition page.
     * If thats not secured then it doesn't really matter what this script does they have compleate access anyway im not at fault
     */
    stopDirectAccess::deAuthorise(AM_SESSION_VALID_INCLUDE);
}
コード例 #3
0
ファイル: amDB.class.php プロジェクト: digideskio/oscmax2
 /**
  * Returns placebo autoincrement value
  * @access public
  * @param $strTable string table name
  * @param $strField string field name
  * @return mixed
  */
 function getNextAutoValue($strTable, $strField)
 {
     return (int) amDB::getOne("select max({$strField}) + 1 as next from {$strTable} limit 1");
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
 function updateSortedProductArray($newArray)
 {
     reset($newArray);
     while (list($key, $val) = each($newArray)) {
         if (!empty($val['products_attributes_id'])) {
             amDB::perform(TABLE_PRODUCTS_ATTRIBUTES, $val, 'update', 'products_attributes_id = ' . $val['products_attributes_id']);
         }
     }
 }
コード例 #7
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();
     $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);
 }
コード例 #8
0
 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);
         }
     }
 }