我正在尝试覆盖 catalogProductInfo 。我想要做的就是向返回的 soap 结果添加另一个属性。问题是我的新属性没有显示。到目前为止,这是我尝试解决的问题。
soap.wsdl_cache_enabled=1 和 soap.wsdl_cache = 1我正在尝试覆盖以下的 magento 产品信息 api 模型 V2...
http://www.magentocommerce.com/api/soap/catalog/catalogProduct/catalog_product.info.html
我正在使用以下示例的 v2。我想做的是在返回结果中添加另一个属性
$prodInfo = $fclient->catalogProductInfo($fsession, $prod->product_id, null,$attributes);
这就是我所做的,试图覆盖返回的内容...我首先创建了我的模块。这是我的配置文件 /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>
在下面的代码中,我尝试在基本产品数据中添加associated。我这样做只是为了简单地查看它是否出现。问题是当我打 SOAP 电话时。它不会显示在返回结果中。我的模块已成功覆盖 Mage_Catalog_Model_Product_Api_V2,因为我可以在我的模块中破坏它。
/app/code/local/Namespace/ImportExport/Model/Product/Api/V2.php
<?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;
}
}
我什至尝试在模块目录 wsdl.xml 文件中将 associated 添加到 catalogProductReturnEntity
/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>
我还是一无所获。我关闭了 SOAP 缓存。我关闭了所有 magento 缓存。我做错了什么??
[更新]
尽管如此,一切都没有改变。 associated 属性是我要找的那个。我在星期五发了这篇文章。接下来的星期一我试了一下,相关的属性突然出现了。现在有一个新问题。我正在尝试添加一个新属性,但遇到了同样的问题。有什么建议吗??
最佳答案
想通了。 Php Soap 有一个服务器和客户端类。因此,您必须确保清除 soap 请求者和响应的缓存。换句话说,使用 soap 调用的服务器找到缓存并清除它,接收缓存调用的服务器也清除缓存。两者都必须清除才能获得完整更新。不仅仅是 Soap 服务器。
关于php - Magento V2 API 覆盖产品信息模型 V2(属性未显示),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14781579/
我有一个包含模块的模型。我想在模块中覆盖模型的访问器方法。例如:classBlah这显然行不通。有什么想法可以实现吗? 最佳答案 您的代码看起来是正确的。我们正在毫无困难地使用这个确切的模式。如果我没记错的话,Rails使用#method_missing作为属性setter,因此您的模块将优先,阻止ActiveRecord的setter。如果您正在使用ActiveSupport::Concern(参见thisblogpost),那么您的实例方法需要进入一个特殊的模块:classBlah
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)
我有用于控制用户任务的Rails5API项目,我有以下错误,但并非总是针对相同的Controller和路由。ActionController::RoutingError:uninitializedconstantApi::V1::ApiController我向您描述了一些我的项目,以更详细地解释错误。应用结构路线scopemodule:'api'donamespace:v1do#=>Loginroutesscopemodule:'login'domatch'login',to:'sessions#login',as:'login',via::postend#=>Teamroutessc
在Ruby类中,我重写了三个方法,并且在每个方法中,我基本上做同样的事情:classExampleClassdefconfirmation_required?is_allowed&&superenddefpostpone_email_change?is_allowed&&superenddefreconfirmation_required?is_allowed&&superendend有更简洁的语法吗?如何缩短代码? 最佳答案 如何使用别名?classExampleClassdefconfirmation_required?is_a
我们的git存储库中目前有一个Gemfile。但是,有一个gem我只在我的环境中本地使用(我的团队不使用它)。为了使用它,我必须将它添加到我们的Gemfile中,但每次我checkout到我们的master/dev主分支时,由于与跟踪的gemfile冲突,我必须删除它。我想要的是类似Gemfile.local的东西,它将继承从Gemfile导入的gems,但也允许在那里导入新的gems以供使用只有我的机器。此文件将在.gitignore中被忽略。这可能吗? 最佳答案 设置BUNDLE_GEMFILE环境变量:BUNDLE_GEMFI
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
我正在使用Mandrill的RubyAPIGem并使用以下简单的测试模板:testastic按照Heroku指南中的示例,我有以下Ruby代码:require'mandrill'm=Mandrill::API.newrendered=m.templates.render'test-template',[{:header=>'someheadertext',:main_section=>'Themaincontentblock',:footer=>'asdf'}]mail(:to=>"JaysonLane",:subject=>"TestEmail")do|format|format.h
我正在尝试使用Ruby2.0.0和Rails4.0.0提供的API从imgur中提取图像。我已尝试按照Ruby2.0.0文档中列出的各种方式构建http请求,但均无济于事。代码如下:require'net/http'require'net/https'defimgurheaders={"Authorization"=>"Client-ID"+my_client_id}path="/3/gallery/image/#{img_id}.json"uri=URI("https://api.imgur.com"+path)request,data=Net::HTTP::Get.new(path
Rails相对较新。我正在尝试调用一个API,它应该向我返回一个唯一的URL。我的应用程序中捆绑了HTTParty。我已经创建了一个UniqueNumberController,并且我已经阅读了几个HTTParty指南,直到我想要什么,但也许我只是有点迷路,真的不知道该怎么做。基本上,我需要做的就是调用API,获取它返回的URL,然后将该URL插入到用户的数据库中。谁能给我指出正确的方向或与我分享一些代码? 最佳答案 假设API为JSON格式并返回如下数据:{"url":"http://example.com/unique-url"