/** * Парсинг страницы товара * @param CMSTableBrand $brand * @param $itemName * @param $itemStyle */ private function parseItem(CMSTableBrand $brand, $itemName, $itemStyle) { echo "--------Sync item {$itemName}, code - {$itemStyle}.\n"; $result = array(); $variations = $this->getItem($itemStyle); if (!$variations) { echo "----------Where are variations?!\n"; return; } // счетчики $this->countItem++; $this->countAllItem++; foreach ($variations as $key => $variation) { $stock = 0; $this->countVariation++; $this->countAllVariation++; if ($variation['stockStatus'] == "Available") { $stock = 1; } else { echo "\n----------variation {$variation['color']} ({$variation['colorDescription']}) not in stock. (not parse!)\n"; echo "==================================================================\n"; continue; } $this->countVariationInStock++; $this->countAllVariationInStock++; $itemImg = self::URL_IMG . $variation['colorImage']; // определяем тип очков if (stripos($variation['marketingGroupDescription'], "SUN") !== false) { $typeItem = CMSLogicGlassesItemType::getInstance()->getSun(); } else { $typeItem = CMSLogicGlassesItemType::getInstance()->getEye(); } // убираем из названия цвета код цвета $pattern = "/\\(" . $variation['color'] . "\\)/"; $variation['colorDescription'] = trim(preg_replace($pattern, '', $variation['colorDescription'])); preg_match("/(\\d{2})(\\d{2})/", $variation['size'], $matches); $size1 = isset($matches[1]) ? $matches[1] : 0; $size2 = isset($matches[2]) ? $matches[2] : 0; // иногда есть размеры формата 0xxx if ($size1[0] == "0" && $variation['SSA']) { $size1 = $variation['SSA']; $size2 = $variation['SSDBL']; } $upc = trim($variation['upcNumber']); // if(strlen($upc) < 13) { // $upc = "0" . $upc; // } echo "\n"; echo "----------brand - {$brand->getTitle()}\n"; echo "----------model_name - {$itemName}\n"; echo "----------external_id - {$itemStyle}\n"; echo "----------color_title - {$variation['colorDescription']}\n"; echo "----------color_code - {$variation['color']}\n"; echo "----------size 1 - {$size1}\n"; echo "----------size 2 - {$size2}\n"; echo "----------size 3 - {$variation['templeLength']}\n"; echo "----------image - {$itemImg}\n"; echo "----------price - {$variation['retail']}\n"; echo "----------type - {$variation['marketingGroupDescription']}\n"; echo "----------stock - {$stock}\n"; echo "----------upc - {$upc}\n"; echo "--------------------------------------------\n"; // создаем обьект модели и синхронизируем $item = new CMSClassGlassesParserItem(); $item->setBrand($brand); $item->setTitle($itemName); $item->setExternalId($itemStyle); $item->setType($typeItem); $item->setColor($variation['colorDescription']); $item->setColorCode(trim($variation['color'])); $item->setStockCount($stock); $item->setPrice(trim($variation['retail'])); $item->setImg($itemImg); $item->setSize($size1); $item->setSize2($size2); $item->setSize3($variation['templeLength']); $item->setIsValid(1); $item->setUpc($upc); $result[] = $item; } echo "============================================\n"; foreach ($result as $res) { $res->sync(); } }
/** * @param $title * @param $itemUrl * @param CMSTableBrand $brand */ private function parseItem($title, $itemUrl, CMSTableBrand $brand) { $result = array(); echo "--Parse item " . $title . " [" . $itemUrl . "]. Get sub-items ...\n"; $subItems = $this->getSubItems($itemUrl); echo "---Found " . count($subItems) . " sub-items. Get all variations ...\n"; $variationsUrls = $this->getAllVariations($subItems); echo "----Found " . count($variationsUrls) . " variations. Get data ...\n"; $variationsData = $this->getVariations($variationsUrls); foreach ($variationsData as $variation) { $this->countVariation++; $size = isset($variation['size']) ? $variation['size'] : 0; if ($variation['upc']) { $this->countVariationWithUpc++; } if (!$variation['stock']) { echo "\n----------variation {$variation['color']} ({$variation['colorCode']}) not in stock. (not parse!)\n"; echo "--------------------------------------------\n"; continue; } $this->countVariationInStock++; echo "\n"; echo "----------brand - {$brand->getTitle()}\n"; echo "----------model_name - {$title}\n"; echo "----------external_id - {$title}\n"; echo "----------color_title - {$variation['color']}\n"; echo "----------color_code - {$variation['colorCode']}\n"; echo "----------size 1 - {$size}\n"; echo "----------size 2 - ~\n"; echo "----------size 3 - ~\n"; echo "----------image - {$variation['img']}\n"; echo "----------price - {$variation['price']}\n"; echo "----------type - sun\n"; echo "----------upc - {$variation['upc']}\n"; echo "----------stock - {$variation['stock']}\n\n"; echo "--------------------------------------------\n"; // создаем обьект модели и синхронизируем $item = new CMSClassGlassesParserItem(); $item->setBrand($brand); $item->setTitle($title); $item->setExternalId($title); $item->setType(CMSLogicGlassesItemType::getInstance()->getSun()); $item->setColor($variation['color']); $item->setColorCode($variation['colorCode']); $item->setStockCount($variation['stock']); $item->setPrice($variation['price']); $item->setImg($variation['img']); $item->setSize($size); $item->setIsValid(1); if ($variation['upc']) { $item->setUpc($variation['upc']); } $result[] = $item; } echo "\n=============================================================================================\n"; $this->syncingResult($result); echo "\n=============================================================================================\n"; }
/** * Достает сток и изображение вариации из корзины, формирует обьект и отправляет на синхронизацию * @param $content * @param CMSTableBrand $brand * @param $type_value * @param $item */ private function parsePageItems($content, CMSTableBrand $brand, $type_value, $item) { $stock = ''; $image = ''; $external_id = ''; $dom = str_get_html($content); // достаем сток $option_stock_dom = $dom->find('#MainContent_ucCart_rptCart_lblAvailMarker_0'); if (count($option_stock_dom)) { $stock_str = trim($option_stock_dom[0]->plaintext); $stock = trim($stock_str) === "IN-STOCK" ? 1 : 0; } // достаем изображение $option_img_dom = $dom->find('#MainContent_ucCart_rptCart_imgFrame_0'); if (count($option_img_dom)) { $image = preg_replace("/&w=(.*)/", '&w=1250', $option_img_dom[0]->src); $image = self::URL_ROOT . $image; } $image = html_entity_decode($image); // разбираемся с размерами $sizes_arr = explode('-', $item['sizes']); $size_1 = isset($sizes_arr[0]) ? $sizes_arr[0] : 0; $size_2 = isset($sizes_arr[1]) ? $sizes_arr[1] : 1; $size_3 = isset($sizes_arr[2]) ? $sizes_arr[2] : 2; // определяем тип очков if ($type_value === "Sun") { $typeItem = CMSLogicGlassesItemType::getInstance()->getSun(); } else { $typeItem = CMSLogicGlassesItemType::getInstance()->getEye(); } // Формируем переменную которая будет уникальным идентификатором каждой модели // Собственно по ней вариации к модели и попадут $external_id = $item['name'] . " prov " . $this->getProviderId(); echo "\n"; echo "--------brand - {$brand->getTitle()}\n"; echo "--------model_name - {$item['name']}\n"; echo "--------color_title - {$item['color_title']}\n"; echo "--------external_id - {$external_id}\n"; echo "--------color_code - {$item['color_code']}\n"; echo "--------sizes - {$item['sizes']}\n"; echo "--------image - {$image}\n"; echo "--------price - {$item['price']}\n"; echo "--------type - {$type_value}\n"; echo "--------stock - {$stock}\n"; echo "--------upc - {$item['upc']}\n\n"; // создаем обьект модели и синхронизируем $sitem = new CMSClassGlassesParserItem(); $sitem->setBrand($brand); $sitem->setExternalId($external_id); $sitem->setType($typeItem); $sitem->setTitle($item['name']); $sitem->setColor($item['color_title']); $sitem->setColorCode($item['color_code']); $sitem->setStockCount($stock); $sitem->setPrice($item['price']); $sitem->setImg($image); $sitem->setSize($size_1); $sitem->setSize2($size_2); $sitem->setSize3($size_3); $sitem->setIsValid(1); $sitem->setUpc($item['upc']); $sitem->sync(); }