我已经实现了自定义Magento模块,该模块循环来自外部服务的数据,并在Magento多语言,多商店网站中更新价格,重量,名称和一些其他产品属性.
我的解决方案很简单(在我的模型中每天由Cron调用),如下所示:
/* THIS IS CODE SNIPPET INSIDE FOREACH LOOP */
$storeId = (string)$jobConfig->store; //cron for each store
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$extistingProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
$extistingProduct->setPrice($newPrice); //update price
//some code here dealing with Associated products of Configurable product probably not relevant
//...
$extistingProduct->setCanSaveConfigurableAttributes(true);
$extistingProduct->setCanSaveCustomOptions(true);
$extistingProduct->setConfigurableAttributesData($configurableAttributesData);
// This tells Magento to associate the given simple products to this configurable product..
$extistingProduct->setConfigurableProductsData($configurableProductsData);
$extistingProduct->setStoreId($storeId);
$extistingProduct->save();
Run Code Online (Sandbox Code Playgroud)
我在每天运行cron,每个商店分别运行.它通常可以正常工作,只改变每个商店的每个产品的价格,但有时会发生奇怪的事情(比如每2个月一次) - 除了价格之外的所有其他属性都会从商店X覆盖到当前商店$storeId
.这意味着我所有受影响的产品的所有英文产品描述都成为德语(例如).
我不知道怎么会发生这种情况,因为每次我调试它都正常工作,只改变我明确设置的当前范围的价格,但保留所有其他产品属性.它似乎从Store X加载所有产品数据,设置价格,然后将所有这些值存储到我在通过调用保存产品之前设置的存储$extistingProduct->setStoreId($storeId)
.
在发生这种情况的情况下,所有属性都会被同一个商店覆盖(例如,所有英文文本都会变成德语,但在其他情况下,所有文本都将成为西班牙语 - 它们都来自一个随机商店).
有没有人知道这怎么可能发生?我究竟做错了什么?
我正在为Magento实现我自己的支付模块,我在我的支付模型中实现了getCheckoutRedirectUrl()方法.
class My_Module_Model_Payment extends Mage_Payment_Model_Method_Abstract {}
Run Code Online (Sandbox Code Playgroud)
该方法应该只返回用户被重定向到的支付网关的URL,但我也应该将当前的orderId附加到此URL.
问题是我无法获得orderId.我尝试过这里已经接受的解决方案
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
Run Code Online (Sandbox Code Playgroud)
但我得到空的$ orderId.所以这似乎不适用于我的方法.调用不会产生错误,所以我得到一个对象(例如Mage :: getSingleton('checkout/session') - > getQuote() - > getSubtotal()返回订单金额),但orderId为空.
我也尝试过:
$order = Mage::getModel('sales/order');
$order->load(Mage::getSingleton('sales/order')->getLastOrderId());
$orderId = $order->getIncrementId();
Run Code Online (Sandbox Code Playgroud)
它再次返回空的$ orderId.
有任何想法吗?
如何在Magento中获取"原始"类别名称,其中我已经为当前商店视图翻译了类别名称.我想在All Store视图中输入类别名称,因为我想将原始(英文)名称发送给GA进行跟踪 - 当我在类别页面时,我需要这个名称.
我可以通过这种方式获得本地化的类别名称:
<?php
$currentCategory = Mage::registry('current_category');
$name = $currentCategory->getName();
?>
Run Code Online (Sandbox Code Playgroud)
但无法在没有额外调用数据库的情况下找到获取未翻译名称的方法.