/** * generating the worksheet * * @param UDate $lastUpdatedInDB * @param PHPExcel_Worksheet $sheet * @param array $data * @param string $preFix * @param bool $debug * * @return Array The array of images */ private static function _genSheet(UDate $lastUpdatedInDB, PHPExcel_Worksheet &$sheet, array $data, $preFix = '', $debug = false) { self::_log('-- Generating the sheets: ', __CLASS__ . '::' . __FUNCTION__, $preFix); $rowNo = 1; $titles = array_keys(self::_getRowWithDefaultValues($lastUpdatedInDB, null, $preFix, $debug)); foreach ($titles as $colNo => $colValue) { $sheet->setCellValueByColumnAndRow($colNo, $rowNo, $colValue); } $rowNo += 1; self::_log('Generated title row', '', $preFix . self::TAB); $imageFiles = array(); foreach ($data as $index => $product) { self::_log('ROW: ' . $index . ', SKU: ' . $product->getSku(), '', $preFix . self::TAB); if (!$product instanceof Product) { self::_log('SKIPPED, invalid product.', '', $preFix . self::TAB . self::TAB); continue; } $rowValue = self::_getRowWithDefaultValues($lastUpdatedInDB, $product, $preFix, $debug); $rowValues = array($rowValue); $images = ProductImage::getAllByCriteria('productId = ? and updated > ?', array($product->getId(), trim($lastUpdatedInDB))); //images self::_log('Got ' . count($images) . ' ProductImage(s) after "' . trim($lastUpdatedInDB) . '" for productID: ' . $product->getId(), '', $preFix . self::TAB); if (count($images) > 0) { foreach ($images as $index => $image) { if (!($asset = $image->getAsset()) instanceof Asset) { self::_log('No Asset found for Image Index: ' . $index, '', $preFix . self::TAB . self::TAB); continue; } if (!is_file($asset->getPath())) { self::_log('No file found: ' . $asset->getPath(), '', $preFix . self::TAB . self::TAB); continue; } $imageFiles[] = array('fileName' => $asset->getFilename(), 'filePath' => $asset->getPath()); self::_log('Added array(fileName=>' . $asset->getFilename() . ', filePath => ' . $asset->getPath() . ') to imageFiles', '', $preFix . self::TAB . self::TAB); $imageFilePath = '{{IMAGE_IMPORT_DIR}}/' . self::$_imageDirName . '/' . $asset->getFilename(); self::_log('New Image Path into the CSV("image" column):' . $imageFilePath, '', $preFix . self::TAB . self::TAB); if (intval($index) === 0) { $rowValues[0]['image'] = $imageFilePath; $rowValues[0]['small_image'] = $imageFilePath; $rowValues[0]['thumbnail'] = $imageFilePath; } else { $rowValues[0]['media_gallery'] = $rowValues[0]['media_gallery'] . ';' . $imageFilePath; self::_log('added onto media_gallery: ' . $rowValues[0]['media_gallery'], '', $preFix . self::TAB . self::TAB); } } } //start looping in the outer loop self::_log('There are ' . count($rowValues) . ' row(s) in total.', '', $preFix . self::TAB); foreach ($rowValues as $row) { foreach (array_values($row) as $colNo => $colValue) { $sheet->setCellValueByColumnAndRow($colNo, $rowNo, $colValue); } $rowNo += 1; } self::_log('ADDED.', '', $preFix . self::TAB . self::TAB); } self::_log('-- DONE', __CLASS__ . '::' . __FUNCTION__, $preFix); return $imageFiles; }
/** * Getting all the images * * @return multitype: */ public function getImages() { if (!isset($this->_cache['images'])) { $this->_cache['images'] = ProductImage::getAllByCriteria('productId = ? ', array($this->getId())); } return $this->_cache['images']; }