/**
  * Синхронизация брендов на сайте из существующими в системе
  */
 public function doSyncBrands()
 {
     $http = $this->getHttp();
     $brands = array();
     $option_value = '';
     if (!$http->doGet(self::URL_RAPIDORDER)) {
         throw new CMSException();
     }
     $content = $http->getContents();
     $dom = str_get_html($content);
     $brands_options_dom = $dom->find('#MainContent_ddlCollectionGroup option');
     // удаляем первую так как она просто информирует
     unset($brands_options_dom[0]);
     foreach ($brands_options_dom as $brand_option) {
         $option_value = $brand_option->value;
         $option_value_explode = explode("|", $option_value);
         $brand_value = trim($option_value_explode[0]);
         $brands[$brand_value] = array('name' => $brand_value, 'code' => $brand_value);
     }
     if (!$brands) {
         throw new CMSException();
     }
     $myBrands = CMSLogicBrand::getInstance()->getAll($this->getProvider());
     foreach ($myBrands as $m) {
         if ($m instanceof CMSTableBrand) {
             $coded[$m->getCode()] = $m;
         }
     }
     $this->_coded_brands = $coded;
     foreach ($brands as $code => $info) {
         $name = $info['name'];
         if (!isset($coded[$code])) {
             echo "--Create brand - {$name}, code - {$code}\n";
             CMSLogicBrand::getInstance()->create($this->getProvider(), $name, $code, '');
         } else {
             echo "--Brand - {$name}, code - {$code} already isset\n";
         }
     }
 }
 /**
  * @throws Exception
  */
 public function doSyncItems()
 {
     $brands = CMSLogicBrand::getInstance()->getAll($this->getProvider());
     foreach ($brands as $brand) {
         if (!$brand instanceof CMSTableBrand) {
             throw new Exception("Brand mast be an instance of CMSTableBrand!");
         }
         if ($brand->getValid()) {
             echo get_class($this), ': syncing items of brand: [', $brand->getId(), '] ', $brand->getTitle(), "\n";
         } else {
             echo get_class($this), ': SKIP! syncing items of Disabled brand: [', $brand->getId(), '] ', $brand->getTitle(), "\n";
             continue;
         }
         // Сбрасываем is_valid для моделей бренда - флаг наличия модели у провайдера
         $this->resetModelByBrand($brand);
         // Сбрасываем сток для бренда
         $this->resetStockByBrand($brand);
         $content = $this->doGetAndGetContents(self::URL_BRAND);
         $linksDom = $this->getLinksOfCategoriesDom($content);
         $links = $this->getLinksOfCategoriesFromDom($linksDom);
         $items = $this->getItemsFromCategories($links);
         $this->syncCategoryProducts($items, $brand);
     }
     echo "\n---Count variations {$this->countVariation}\n";
     echo "---Count variations in stock {$this->countVariationInStock}\n";
     echo "---Count variations with upc {$this->countVariationWithUpc}\n";
 }
 /**
  * Sync items on category page (get urls)
  */
 public function doSyncItems()
 {
     $product_url = '';
     $count = 0;
     $all_count = 0;
     $links = array();
     $http = $this->getHttp();
     $brands = CMSLogicBrand::getInstance()->getAll($this->getProvider());
     $brand = $brands[0];
     if ($brand instanceof CMSTableBrand) {
         if ($brand->getValid()) {
             echo get_class($this), ': syncing items of brand: [', $brand->getId(), '] ', $brand->getTitle(), "\n";
         } else {
             echo get_class($this), ': SKIP! syncing items of Disabled brand: [', $brand->getId(), '] ', $brand->getTitle(), "\n";
             continue;
         }
     } else {
         throw new Exception('Brand not CMSTableBrand instance');
     }
     // Сбрасываем is_valid для моделей бренда - флаг наличия модели у провайдера
     $this->resetModelByBrand($brand);
     // Сбрасываем сток для моделей
     $this->resetStockByBrand($brand);
     $category_links = $this->_category_links;
     foreach ($category_links as $type => $link) {
         for ($i = 1; true; $i++) {
             $product_url = sprintf($link, $i);
             $http->doGet($product_url);
             $content = $http->getContents();
             $dom = str_get_html($content);
             $items_selector = '.product-list-item .carousel-inner .active';
             $items = $dom->find($items_selector);
             // Если товары закончились переходим к следующей категории
             // условие важно так как это единственный выход из бесконечного цикла
             if (!count($items)) {
                 break;
             }
             // чтобы долго не ждать при отладке
             // if($i == 2) {
             // 	break;
             // }
             $count = count($items);
             $all_count += $count;
             echo "Get links for {$count} ({$all_count}) {$type} products on {$i} page.\n";
             foreach ($items as $key => $item) {
                 $cur_item_href = $item->find('.EcomProductLink');
                 $cur_item_stock = $item->find('.EcomProductStock');
                 $cur_item_name = $item->find('.EcomProductName');
                 $cur_item_price = $item->find('.EcomProductPrice');
                 $href = trim($cur_item_href[0]->href);
                 $stock = trim($cur_item_stock[0]->plaintext);
                 $name = trim($cur_item_name[0]->plaintext);
                 $price = trim($cur_item_price[0]->plaintext);
                 $href = htmlspecialchars_decode(self::URL_BASE . $href);
                 $links[$type][] = ['href' => $href, 'stock' => $stock, 'name' => $name, 'price' => $price];
             }
         }
     }
     // перходим к парсингу страничек продуктов
     foreach ($links as $type => $type_links) {
         foreach ($type_links as $key => $link) {
             $this->parsePageItems($link['href'], $type, $brand);
         }
     }
 }
 /**
  * Синхронизация товаров
  */
 public function doSyncItems()
 {
     $brands = CMSLogicBrand::getInstance()->getAll($this->getProvider());
     $brandUrl = CMSPluginUrl::parse(self::URL_BRAND);
     foreach ($brands as $brand) {
         if (!$brand instanceof CMSTableBrand) {
             throw new Exception("Brand mast be an instance of CMSTableBrand!");
         }
         if ($brand->getValid()) {
             echo get_class($this), ': syncing items of brand: [', $brand->getId(), '] ', $brand->getTitle(), "\n";
         } else {
             echo get_class($this), ': SKIP! syncing items of Disabled brand: [', $brand->getId(), '] ', $brand->getTitle(), "\n";
             continue;
         }
         if (in_array($brand->getId(), $this->syncedBrandsIds)) {
             echo "--Brand " . $brand->getTitle() . "[" . $brand->getId() . "] already synced!!\n";
             continue;
         }
         // if(!in_array($brand->getId(), array(87))) {
         //     continue;
         // }
         $countItemsDom = $this->getBrandItemsCountDom($brandUrl, $brand->getCode());
         if (!count($countItemsDom)) {
             echo "--No one model for brand. Continue.\n";
             continue;
         }
         // Сбрасываем is_valid для моделей бренда - флаг наличия модели у провайдера
         $this->resetModelByBrand($brand);
         // Сбрасываем сток для бренда
         $this->resetStockByBrand($brand);
         $this->syncedBrandsIds[] = $brand->getId();
         $countItems = $this->getCountItemsNumberFromDom($countItemsDom);
         echo "\nitems count - " . $countItems . "\n";
         $allBrandItemsDom = $this->getBrandItemsDom($brandUrl, $countItems);
         echo "----Item links found: ", count($allBrandItemsDom), "\n";
         $this->syncCategoryProducts($allBrandItemsDom, $brand);
         $this->doReLogin();
     }
 }
 /**
  * Парсинг товаров на странице категорий
  */
 public function doSyncItems()
 {
     echo "\n--Marshon Sync Items start\n";
     $brands = CMSLogicBrand::getInstance()->getAll($this->getProvider());
     foreach ($brands as $brand) {
         if ($brand instanceof CMSTableBrand) {
             $this->countItem = 0;
             $this->countVariation = 0;
             $this->countVariationInStock = 0;
             if ($brand->getValid()) {
                 echo '----', get_class($this), ': syncing items of brand: [', $brand->getId(), '] ', $brand->getTitle(), ' code - ' . $brand->getCode(), "\n";
             } else {
                 echo '----', get_class($this), ': SKIP! syncing items of Disabled brand: [', $brand->getId(), '] ', $brand->getTitle(), "\n";
                 continue;
             }
             // Сбрасываем is_valid для моделей бренда - флаг наличия модели у провайдера
             echo "------Set is_valid flag in 0 for {$brand->getTitle()}\n";
             $this->resetModelByBrand($brand);
             // Сбрасываем сток для бренда
             echo "------Set detail_stock_count flag in 0 for {$brand->getTitle()} details\n";
             $this->resetStockByBrand($brand);
             $items = $this->getBrandItems($brand->getCode());
             foreach ($items as $key => $item) {
                 $this->parseItem($brand, $item['styleName'], $item['style']);
             }
             echo "\n--------" . $brand->getTitle() . "\n";
             echo "----------Count item {$this->countItem}\n";
             echo "----------Count variations {$this->countVariation}\n";
             echo "----------In stock count variations {$this->countVariationInStock}\n";
             echo "===============================================================\n\n";
         }
     }
     echo "\n---All count item {$this->countAllItem}\n";
     echo "---All count variations {$this->countAllVariation}\n";
     echo "---All in stock count variations {$this->countAllVariationInStock}\n";
 }
 /**
  * Синхронизация моделей
  */
 public function doSyncItems()
 {
     $brands = CMSLogicBrand::getInstance()->getAll($this->getProvider());
     // так как бренд один то берем первый элемент из массива
     $brand = current($brands);
     if ($brand instanceof CMSTableBrand) {
         if ($brand->getValid()) {
             echo get_class($this), ': syncing items of brand: [', $brand->getId(), '] ', $brand->getTitle(), "\n";
         } else {
             echo get_class($this), ': SKIP! syncing items of Disabled brand: [', $brand->getId(), '] ', $brand->getTitle(), "\n";
             return;
         }
     } else {
         throw new Exception("Brand mast be an instance CMSTableBrand!");
     }
     // Сбрасываем is_valid для моделей бренда - флаг наличия модели у провайдера
     $this->resetModelByBrand($brand);
     // Сбрасываем сток для бренда
     $this->resetStockByBrand($brand);
     $category_links = $this->getCategoryLinks(self::URL_CATEGORY);
     $categories_sections = $this->getCategorySections($category_links);
     $product_links = $this->getProdLinks($categories_sections);
     foreach ($product_links as $key => $product_link) {
         // if($product_link['name'] != "JUNKET (52)") continue;
         echo "----Get variations for {$product_link['name']} ({$product_link['href']})\n";
         $this->parseItem($product_link, $brand);
     }
     echo "\nSync items - {$this->count_items},  variations - {$this->count_variations}.\n";
 }