gpt4 book ai didi

php - 限制可见性找到的产品?

转载 作者:行者123 更新时间:2023-12-02 06:21:42 25 4
gpt4 key购买 nike

我使用带有以下脚本的 Magento 将我们的目录导入 Google 购物:

<?php
define('SAVE_FEED_LOCATION','google_base_feed.txt');
set_time_limit(1800);
require_once '../app/Mage.php';
Mage::app('default');
try{
$handle = fopen(SAVE_FEED_LOCATION, 'w');

$heading = array('id','mpn', 'upc','title','description','link','image_link','price','brand','product_type','condition', 'google_product_category', 'manufacturer', 'availability');
$feed_line=implode("\t", $heading)."\r\n";
fwrite($handle, $feed_line);

$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToFilter('status', 1);
$products->addAttributeToFilter('visibility', 4);
$products->addAttributeToSelect('*');
$prodIds=$products->getAllIds();

$product = Mage::getModel('catalog/product');

$counter_test = 0;

foreach($prodIds as $productId) {

if (++$counter_test < 30000){

$product->load($productId);

$product_data = array();
$product_data['sku'] = $product->getSku();
$product_data['mpn'] = $product->getData('upc');
$product_data['upc'] = $product->getData('upc');

$title_temp = $product->getName();
if (strlen($title_temp) > 70){
$title_temp = str_replace("Supply", "", $title_temp);
$title_temp = str_replace(" ", " ", $title_temp);
}
$product_data['title'] = $title_temp;


$product_data['description'] = substr(iconv("UTF-8","UTF-8//IGNORE",$product->getDescription()), 0, 900);
$product_data['Deeplink'] = "http://www.domainname.co.uk/store/".$product->getUrlPath();
$product_data['image_link'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage();

$price_temp = round($product->getPrice(),2);
$product_data['price'] = round($product->getPrice(),2) *
1.2;


$product_data['brand'] = $product->getData('brand');

$product_data['product_type'] = 'Pet Products and Accessories';
$product_data['condition'] = "new";
$product_data['category'] = $product_data['brand'];
$product_data['manufacturer'] = $product_data['brand'];

$product_data['availability'] = "in stock";

foreach($product_data as $k=>$val){
$bad=array('"',"\r\n","\n","\r","\t");
$good=array(""," "," "," ","");
$product_data[$k] = '"'.str_replace($bad,$good,$val).'"';
}

echo $counter_test . " ";

$feed_line = implode("\t", $product_data)."\r\n";
fwrite($handle, $feed_line);
fflush($handle);

}

}

fclose($handle);
}
catch(Exception $e){
die($e->getMessage());
}

此脚本的问题在于它似乎导入了所有 产品。不管其中一些被列为“单独不可见”的事实。我正在尝试找到一种方法,将列出的项目限制为“搜索”、“目录”或“目录、搜索”。

我注意到下面一行:

       $products->addAttributeToFilter('visibility', 4);

但我完全不确定数字 4 的相关性。该脚本已使用一些不同的博客文章、SO 答案和教程混合在一起。

最佳答案

另一种方式是定义一个数组:

$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);

// now you can add this filter to call your product collection

$products->addAttributeToFilter('visibility', $visibility);

关于php - 限制可见性找到的产品?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8028678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com