嗨,我有一个脚本,其中有foreach
一个foreach
. 第一个 foreach
用于唯一的 id,但第二个foreach
用于产品的相关图像,该图像应根据图像数量循环。但是,它限制我只能获取一张相关图片,我怎样才能获取所有相关图片?
$i=0;
foreach ($collection as $product_all) {
//echo $product_all->getId().'<br/>';
if($i==10) break;
$id = $product_all->getId();
$neew = Mage::getModel('catalog/product')->load($id);
//echo'<pre>';
echo 'active products id ===='.$neew ->getId().'<br/>';
echo 'active products name ===='.$neew->getname().'<br/>';
echo 'active products style_ideas ===='.$neew->getstyle_ideas().'<br/>';
echo 'active products size and fit ===='.$neew->getsize_fit().'<br/>';
echo 'active products short description ===='.$neew->getshort_description().'<br/>';
echo 'active products description ===='.$neew->getdescription().'<br/>';
//print_r($neew);
if (count($neew->getMediaGalleryImages()) > 0){
$i = 0 ;
$j = 0 ;
foreach ($neew->getMediaGalleryImages() as $_image){
$relative_image = Mage::helper('catalog/image')->init($neew->getProduct(), 'image', $_image->getFile())->resize(2000);
$relative_image1 = str_replace('/webApps/migration/productapi/new/','/',$relative_image);
//echo 'relative_image => '.$relative_image1.'<br/>';
$relative_image_save = $relative_image1 ;
$relative_image_save1 = explode('/', $relative_image_save);//explode / to get only image name
$end1 = end($relative_image_save1);
$relative_image3 = $end1;
//$handle1 = fopen( $relative_image3, 'w') or die('Cannot open file: '. $relative_image);
$path12 = '/mnt/aviesta/development/webApps/migration/productapi/new/'.'sku-'.$neew->getsku().'_' .$i++.'.jpg';
copy($relative_image_save, $path12);
echo 'relative image with sku path_'.$j++.' ====>'.$path12.'<br/><br/>';
}
}
$i++;
}