drvpvmz16241016 2013-02-08 21:22
浏览 59

Magento V2 API覆盖产品信息模型V2(属性未显示)

I am trying to override catalogProductInfo . All I am trying to do is add another attribute to the returning soap result. The problem is my new attribute is not showing. This is what I've tried so far to fix the issue.

  1. I tried to go into the php.ini file and turning off soap.wsdl_cache_enabled=1 and soap.wsdl_cache = 1
  2. I tried going into /tmp/ folder and deleting the wsdl cache file
  3. I disabled magento cacheing and I tried reindex

I am trying to override the magento product info api model V2 which is the following...

http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.info.html

I am using v2 which is the following example. What I want to do is add another attribute to the returning result

$prodInfo = $fclient->catalogProductInfo($fsession, $prod->product_id, null,$attributes);

This is what I did to try to override what is returned... I first created my module. Here is my config file /app/code/local/Namespace/ImportExport/etc/config.xml

<config>
    <modules>
        <Namespace_ImportExport>
            <version>0.0.1</version>
        </Namespace_ImportExport>
    </modules>
    <global>
        <models>
            <catalog>
                <rewrite>
                    <product_api_v2>Namespace_ImportExport_Model_Product_Api_V2</product_api_v2>
                </rewrite>
            </catalog>
        </models>
    </global>
</config>

In the below code, I try to add associated in the basic product data. I am doing this just to simply see if it shows up. The problem is when I make a soap call. It does not show up in the returning results. My module has successfully overrided Mage_Catalog_Model_Product_Api_V2 because I can break it within my module.

/app/code/local/Namespace/ImportExport/Model/Product/Api/V2.php

Namespace_ImportExport_Model_Product_Api_V2

<?php
class Namespace_ImportExport_Model_Product_Api_V2
    extends Mage_Catalog_Model_Product_Api_V2
{

    /**
     * Retrieve product info
     *
     * @param int|string $productId
     * @param string|int $store
     * @param stdClass $attributes
     * @return array
     */
    public function info($productId, $store = null, $attributes = null, $identifierType = null)
    {
        $product = $this->_getProduct($productId, $store, $identifierType);

        if (!$product->getId()) {
            $this->_fault('not_exists');
        }

        $result = array( // Basic product data
            'associated' =>"test",
            'product_id' => $product->getId(),
            'sku'        => $product->getSku(),
            'set'        => $product->getAttributeSetId(),
            'type'       => $product->getTypeId(),
            'categories' => $product->getCategoryIds(),
            'websites'   => $product->getWebsiteIds(),
        );
        if($product->getTypeId() == "configurable") {
            Mage::log($product);
//          $child_products = $product->getTypeInstance(true)->getAssociatedProducts($product);
//          if(!empty($child_products)) {
//              $result['associated_products'] = "";
//              foreach ($child_products as $p) {
//                  $result['associated_products'] .= $p->getData('sku').",";
//              }
//          }
        }

        $allAttributes = array();
        if (isset($attributes->attributes)) {
            $allAttributes += array_merge($allAttributes, $attributes->attributes);
        }

        $_additionalAttributeCodes = array();
        if (isset($attributes->additional_attributes)) {
            foreach ($attributes->additional_attributes as $k => $_attributeCode) {
                $allAttributes[] = $_attributeCode;
                $_additionalAttributeCodes[] = $_attributeCode;
            }
        }

        $_additionalAttribute = 0;
        foreach ($product->getTypeInstance(true)->getEditableAttributes($product) as $attribute) {
            if ($this->_isAllowedAttribute($attribute, $allAttributes)) {
                if (in_array($attribute->getAttributeCode(), $_additionalAttributeCodes)) {
                    $result['additional_attributes'][$_additionalAttribute]['key'] = $attribute->getAttributeCode();
                    $result['additional_attributes'][$_additionalAttribute]['value'] = $product->getData($attribute->getAttributeCode());
                    $_additionalAttribute++;
                } else {
                    $result[$attribute->getAttributeCode()] = $product->getData($attribute->getAttributeCode());
                }
            }
        }

        return $result;
    }

}

I have even tried adding associated to catalogProductReturnEntity within the module catalog wsdl.xml file /app/code/core/Mage/Catalog/etc/wsdl.xml

<complexType name="catalogProductReturnEntity">
    <all>
        <element name="associated" type="xsd:string" minOccurs="0" />
        <element name="product_id" type="xsd:string" minOccurs="0" />
        <element name="sku" type="xsd:string" minOccurs="0" />
        <element name="set" type="xsd:string" minOccurs="0" />
        <element name="type" type="xsd:string" minOccurs="0" />
        <element name="categories" type="typens:ArrayOfString" minOccurs="0" />
        <element name="websites" type="typens:ArrayOfString" minOccurs="0" />
        <element name="created_at" type="xsd:string" minOccurs="0" />
        <element name="updated_at" type="xsd:string" minOccurs="0" />
        <element name="type_id" type="xsd:string" minOccurs="0" />
        <element name="name" type="xsd:string" minOccurs="0" />
        <element name="description" type="xsd:string" minOccurs="0" />
        <element name="short_description" type="xsd:string" minOccurs="0" />
        <element name="weight" type="xsd:string" minOccurs="0" />
        <element name="status" type="xsd:string" minOccurs="0" />
        <element name="url_key" type="xsd:string" minOccurs="0" />
        <element name="url_path" type="xsd:string" minOccurs="0" />
        <element name="visibility" type="xsd:string" minOccurs="0" />
        <element name="category_ids" type="typens:ArrayOfString" minOccurs="0" />
        <element name="website_ids" type="typens:ArrayOfString" minOccurs="0" />
        <element name="has_options" type="xsd:string" minOccurs="0" />
        <element name="gift_message_available" type="xsd:string" minOccurs="0" />
        <element name="price" type="xsd:string" minOccurs="0" />
        <element name="special_price" type="xsd:string" minOccurs="0" />
        <element name="special_from_date" type="xsd:string" minOccurs="0" />
        <element name="special_to_date" type="xsd:string" minOccurs="0" />
        <element name="tax_class_id" type="xsd:string" minOccurs="0" />
        <element name="tier_price" type="typens:ArrayOfString" minOccurs="0" />
        <element name="meta_title" type="xsd:string" minOccurs="0" />
        <element name="meta_keyword" type="xsd:string" minOccurs="0" />
        <element name="meta_description" type="xsd:string" minOccurs="0" />
        <element name="custom_design" type="xsd:string" minOccurs="0" />
        <element name="custom_layout_update" type="xsd:string" minOccurs="0" />
        <element name="options_container" type="xsd:string" minOccurs="0" />
        <element name="additional_attributes" type="typens:associativeArray" minOccurs="0" />
    </all>
</complexType>

Still I get nothing. I have soap cacheing turned off. I have all magento cacheing turned off. What am I doing wrong ??

[Update] Despite all of this, nothing changes. the attribute associated is the one I am looking for. I made this post on a friday. The following monday I tried it out and the associated attribute show up out of no where. There is a new problem now. I am trying to add a new attribute but getting the same issue. Any suggestions ??

  • 写回答

1条回答 默认 最新

  • drwf69817 2013-02-15 16:06
    关注

    figured it out. Php Soap has a Server and Client class. So you must make sure you clear the cache of the soap requester, and response. in other words, the server that uses the soap calls, find the cache and clear it and the also the server the receives the cache calls, clear as well. BOTH must be cleared to get full updates. Not just the Soap Server.

    评论

报告相同问题?

悬赏问题

  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件
  • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
  • ¥30 线性代数的问题,我真的忘了线代的知识了