注意:如果您一直在通过PHP代码编辑产品,请在之后将它们重新编入管理员的索引中,并节省大量时间尝试找出为什么它们在下面没有像我一样显示出来...
我正在兜圈子,试图弄清楚is_salable
产品的设置方式,从而弄清楚为什么我的产品现在展示。
我发现在代码中只有一个地方可以设置它:
$salable = $this->isAvailable();
但是我无法弄清楚如何或从何处获得此信息,因为当我遵循时,isAvailable
它似乎只是循环回去...。
/app/code/core/Mage/Catalog/Model/Product.php
public function isSalable()
{
Mage::dispatchEvent('catalog_product_is_salable_before', array(
'product' => $this
));
$salable = $this->isAvailable();
$object = new Varien_Object(array(
'product' => $this,
'is_salable' => $salable
));
Mage::dispatchEvent('catalog_product_is_salable_after', array(
'product' => $this,
'salable' => $object
));
return $object->getIsSalable();
}
从这里跟随$ this-> isAvailable()之后,它会走几行:
**public function isAvailable()
{
return $this->getTypeInstance(true)->isSalable($this);
}**
然后调用app / code / core / Mage / Catalog / Model / Product / Type / Configurable.php的isSalable
public function isSalable($product = null)
{
$salable = parent::isSalable($product);
if ($salable !== false) {
$salable = false;
if (!is_null($product)) {
$this->setStoreFilter($product->getStoreId(), $product);
}
foreach ($this->getUsedProducts(null, $product) as $child) {
if ($child->isSalable()) {
$salable = true;
break;
}
}
}
return $salable;
}
它调用父级:/app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php的isSalable:
public function isSalable($product = null)
{
$salable = $this->getProduct($product)->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED;
if ($salable && $this->getProduct($product)->hasData('is_salable')) {
$salable = $this->getProduct($product)->getData('is_salable');
}
elseif ($salable && $this->isComposite()) {
$salable = null;
}
return (boolean) (int) $salable;
}
is / saleable值仅拥有/获取数据的哪个?!?我追踪正确吗?这个值从哪里来?
我在安装中为is_salable发出了一个递归grep,肯定会显示设置它的任何行,但是我看不到任何行:
grep -r is_salable *
app/code/core/Mage/CatalogInventory/Model/Stock/Status.php: $object = new Varien_Object(array('is_in_stock' => $product->getData('is_salable')));
app/code/core/Mage/XmlConnect/Block/Wishlist.php: $itemXmlObj->addChild('is_salable', (int)$item->getProduct()->isSalable());
app/code/core/Mage/XmlConnect/Block/Catalog/Product.php: $item->addChild('is_salable', (int)$product->isSalable());
app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php: $itemXmlObj->addChild('is_salable', 0);
app/code/core/Mage/XmlConnect/Block/Cart/Crosssell.php: $itemXmlObj->addChild('is_salable', (int)$product->isSalable());
app/code/core/Mage/Catalog/Model/Product.php: Mage::dispatchEvent('catalog_product_is_salable_before', array(
app/code/core/Mage/Catalog/Model/Product.php: 'is_salable' => $salable
app/code/core/Mage/Catalog/Model/Product.php: Mage::dispatchEvent('catalog_product_is_salable_after', array(
app/code/core/Mage/Catalog/Model/Product.php: if ($this->hasData('is_salable')) {
app/code/core/Mage/Catalog/Model/Product.php: return $this->getData('is_salable');
app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php: if ($salable && $this->getProduct($product)->hasData('is_salable')) {
app/code/core/Mage/Catalog/Model/Product/Type/Abstract.php: $salable = $this->getProduct($product)->getData('is_salable');
发现:
grep -r setIsSalable *
app/code/core/Mage/CatalogInventory/Model/Stock/Status.php: $product->setIsSalable($stockStatus);
app/code/core/Mage/CatalogInventory/Model/Stock/Status.php: $product->setIsSalable($status);
我不认为/不知道要寻找的是setIsSalable,而不仅仅是setIsSalable。