Created
September 28, 2012 12:53
-
-
Save ochronus/3799634 to your computer and use it in GitHub Desktop.
A régi CreatePFLookupValue függvény
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CreatePFLookupValue() { | |
global $akweb_connection; | |
$property_values = array(); | |
$Query = " | |
CREATE TABLE IF NOT EXISTS `PFLookupValue` ( | |
`ProductId` INT UNSIGNED NOT NULL, | |
`CategoryId` SMALLINT UNSIGNED NOT NULL, | |
`PropertyId` INT NOT NULL, | |
`PropertyValueId` INT UNSIGNED NOT NULL, | |
PRIMARY KEY (`ProductId`, `PropertyValueId`), | |
INDEX (`ProductId`), | |
INDEX (`CategoryId`), | |
INDEX (`PropertyValueId`) | |
) ENGINE = MYISAM | |
"; | |
DataBaseQuery($Query, $akweb_connection); | |
DataBaseQuery("TRUNCATE TABLE PFLookupValue", $akweb_connection); | |
$pvres = DataBaseQuery(" | |
SELECT Id, | |
PropertyId, | |
CategoryId, | |
Value, | |
Code | |
FROM PropertyValues | |
", $akweb_connection); | |
while (($pvdr = mysql_fetch_assoc($pvres))) { | |
$property_values[$pvdr['CategoryId']][$pvdr['Id']] = $pvdr; | |
} | |
$manufacturers = array(); | |
$res = DataBaseQuery("SELECT ManufacturerName FROM Product", $akweb_connection); | |
while (($dr = mysql_fetch_assoc($res))) { | |
if (!$manufacturers[$dr['ManufacturerName']]) $manufacturers[$dr['ManufacturerName']] = CreateUrlName($dr['ManufacturerName']); | |
} | |
$query = " | |
SELECT DISTINCT P.Id, | |
P.CategoryId, | |
P.ManufacturerName, | |
P.Properties | |
FROM Product AS P | |
LEFT JOIN ProductAttributes AS PA | |
ON P.Id = PA.ProductId AND | |
PA.Type != 'AK' | |
WHERE PA.Id IS NOT NULL | |
"; | |
$res = DataBaseQuery($query , $akweb_connection); | |
$insert_query = "INSERT IGNORE INTO PFLookupValue (ProductId, CategoryId, PropertyId, PropertyValueId) VALUES"; | |
$values = array(); | |
while (($dr = mysql_fetch_assoc($res))) { | |
// manufacturer | |
$property_values_cat = $property_values[$dr['CategoryId']]; | |
if (!empty($property_values_cat)) { | |
foreach ($property_values_cat as $property => $property_value) { | |
if ($property_value['PropertyId'] == PROPERTY_MANUFACTURER && | |
$property_value['Code'] == $manufacturers[$dr['ManufacturerName']]) { | |
$property_id = $property_values[$dr['CategoryId']][$property]['PropertyId']; | |
$values[] = "('{$dr['Id']}', '{$dr['CategoryId']}', '{$property_id}', '{$property}')"; | |
break; | |
} | |
} | |
} | |
// enum, set, boolean | |
$properties = explode('|', $dr['Properties']); | |
foreach ($properties as $property) { | |
$property = trim($property); | |
if (!empty($property)) { | |
$property_id = $property_values[$dr['CategoryId']][$property]['PropertyId']; | |
$values[] = "('{$dr['Id']}', '{$dr['CategoryId']}', '{$property_id}', '{$property}')"; | |
} | |
} | |
if (count($values) > 100) { | |
DataBaseQuery($insert_query . implode(',', $values)); | |
$values = array(); | |
} | |
} | |
if (count($values) > 0) { | |
DataBaseQuery($insert_query . implode(',', $values)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment