确切的查询:
选择
coupon_coupons。code,
coupon_coupons.discountTypeAS“类型”,
coupon_coupons.discountAmountAS“金额”,
coupon_coupons.discountAppliedAS“应用”,
coupon_coupons.description,
group_concat(coupon_targetsku.separatorsku';') AS 'targetsku'
FROMcoupon_coupons
LEFT JOINcoupon_targetskuONcoupon_coupons。code=coupon_targetsku。code
在哪里coupon_coupons。code= '测试代码'coupon_coupons.code = 主键
coupon_targetsku.code = fk(coupon_coupons.code)
如果coupon_coupons. code在数据库中找到时,查询将按预期运行,但当未找到时,返回的结果集是一行,全部为 NULL 值。我猜我左连接做错了。
如果找不到代码,我希望此查询返回零行。
我正在使用 mysql:
服务器版本 5.1.36-community-log
协议版本:10
提前致谢。
我正在为Magento构建一个自定义产品导入模块,之前从未与Magento合作过.
我有一个包含所有产品的CSV文件.其中一列包含应使用斜杠分隔产品的类别.例如:
Jewelry / Rings / Diamond
Jewelry / Neckless / Diamond
Run Code Online (Sandbox Code Playgroud)
等.
我遇到的问题是钻石类别可以作为任何数量的父类别中的子类别存在.我的解决方案是打破路径(即expload($ categoryPath,"/"))
使用第一个例子(珠宝/戒指/钻石)我从商店根类别开始,检查它是否包含珠宝的子类别,如果它我得到该子类别的ID并递归地前往终点线,或者至少那是理论.
我遇到的问题就在这里......
$rootCategory = Mage::getModel('catalog/category') -> load($rootCategoryId);
$currentCategory = $rootCategory -> getChildrenCategories() -> loadByAttribute('name', $targetCategoryName);
Run Code Online (Sandbox Code Playgroud)
这引发了一个错误......"在一个非对象上调用成员函数getName()"...我假设因为getChildrenCategories()正在返回一个集合而我无法在其上调用loadByAttribute.
如果这对任何人都有意义,请告诉我如何仅使用名称从根类别加载子类别.我希望如果loadByAttribute无法加载类别(因为它不存在),它将返回False,然后我可以创建类别.
$targetCategoryName = 'Jewelry';
$subCategories = $rootCategory
-> getChildrenCategories()
-> addAttributeToFilter('name',$targetCategoryName)
-> setCurPage(1)
-> setPageSize(1)
-> load();
$currentCategory = $subCategories
-> getFirstItem();
Run Code Online (Sandbox Code Playgroud)
$ currentCategory的名称是'dummy-category'.看起来过滤器不起作用.
我是Magento的新手,文档,主要是phpDocs,很难导航.例如,
$attributeSet = Mage::getModel('eav/entity_attribute_set')->load($id);
Run Code Online (Sandbox Code Playgroud)
在类Mage_Eav_Model_Entity_Attribute_Set的php文档中, 没有在继承的方法或其他方面提及方法getAttributeSetName(),但这仍然有效.
$attributeSet = Mage::getModel('eav/entity_attribute_set')->load($id);
echo $attributeSet->getAttributeSetName();
Run Code Online (Sandbox Code Playgroud)
所以我想我有几个问题.
我的理论是,有一些继承或设计模式的实施,我不理解,也许有人可以为我阐明这一点.
我的一位同事最近告诉我,PSR-2编码标准说你不允许使用"_"字符来表明变量是私有的还是受保护的.
他引用了http://www.php-fig.org/psr/psr-2/的 "4.2属性"部分
必须在所有属性上声明可见性.
var关键字绝不能用于声明属性.
每个声明不得超过一个属性.
属性名称不应以单个下划线为前缀,以指示受保护或私有可见性.
当我听到这个时,我感到非常愤怒,因为我是私人和受保护的vars上_前缀的忠实粉丝,我无法相信社区会接受这样的标准.
我对此基于"SHOULD NOT"关键字的解释是,在声明类的属性时必须使用范围关键字,并且建议您不要使用_字符,但仍然允许它仍然是PSR-2如果您选择使用此投诉.
虽然我不同意这一点,并建议每个人使用下划线为私有和受保护的变量加前缀,但我怀疑这背后的原因是为了防止人们忽略scope关键字(Public,Protected,Private)并仅依赖命名约定.这使得因为,因为我们都知道范围变量PHP使一切都公开.
http://www.ietf.org/rfc/rfc2119.txt
总结一个问题:PSR-2类上的私有和受保护变量上的"_"前缀是否兼容?
编辑:此外,我不是在寻找个人偏好辩论,我只是想知道_前缀的使用是否符合PSR-2标准.