读书人

色色觅magento bug: $identifierType

发布时间: 2012-10-31 14:37:31 作者: rapoo

色色找magento bug: $identifierType 不管用 的

创建/更新 ... 删除产品时,api接口文档中 提供了

    /**     * Return loaded product instance     *     * @param  int|string $productId (SKU or ID)     * @param  int $store     * @param  string $identifierType     * @return Mage_Catalog_Model_Product     */    public function getProduct($productId, $store, $identifierType = null) {        $loadByIdOnFalse = false;        if ($identifierType == null) {            if (is_string($productId) && !preg_match("/^[+-]?[1-9][0-9]*$|^0$/", $productId)) {                $identifierType = 'sku';                $loadByIdOnFalse = true;            } else {                $identifierType = 'id';            }        }        /** @var $product Mage_Catalog_Model_Product */        $product = Mage::getModel('catalog/product');        if ($store !== null) {            $product->setStoreId($store);        }        if ($identifierType == 'sku') {            $idBySku = $product->getIdBySku($productId);            if ($idBySku) {                $productId = $idBySku;            }            if ($loadByIdOnFalse) {                $identifierType = 'id';            }        }        if ($identifierType == 'id' && is_numeric($productId)) {            $productId = !is_float($productId) ? (int) $productId : 0;            $product->load($productId);        }        return $product;    }
?

发现了 坑爹的代码啊,如果 不指定 identifierType 参数,则 仅仅是 字符串时才使用 sku作为条件

?

但是 当指定了 identifierType 为'sku'时咋都不执行 ,具体见

?

if ($loadByIdOnFalse) {                $identifierType = 'id';            }

?

这坑爹的代码 $loadByIdOnFalse 恒为 false,能执行才怪呢

?

所以 按如下进行修改:

?

if ($identifierType == 'sku') {            $loadByIdOnFalse = true;            $idBySku = $product->getIdBySku($productId);            if ($idBySku) {                $productId = $idBySku;            }            if ($loadByIdOnFalse) {                $identifierType = 'id';            }        }
?

?

此时就OK了 或者你想自己覆盖它的api,随便了 不过想不到 国外的 猿 也不是很细心啊 ...........

?

?

?

?

1 楼 vb2005xu 昨天 http://inchoo.net/ecommerce/magento/magento-v2-soap-demystified/

读书人网 >开源软件

热点推荐