目录价格规则计算是否不应始终提前3天发生?
-
16-10-2019 - |
题
我们有简单的目录价格规则,无限期有效。
在我们在午夜生成的Google购物提要中,价格规则不适用。
我的理论是,有一个很少的时间范围,而计算的价格则无法可用。
我检查过 catalogrule_product_price
- 直到今天,似乎只计算出价格(2013-04-22
),所以他们会在午夜到期:
mysql> select distinct rule_date from catalogrule_product_price; +------------+ | rule_date | +------------+ | 2013-04-20 | | 2013-04-21 | | 2013-04-22 | +------------+ 3 rows in set (0.05 sec)
这是正常的吗?cron_schedule
有最近的条目,所以我认为Cron系统通常正在运行。
我已经记住了,价格规则总是提前几天生成,只是为了避免这种时间跨越错误的价格 - 我对这个假设有错吗?这里发生了什么?
编辑:今天再次检查(2013-04-25
) - 同样的问题。我希望我昨天检查一下,看看是否也23.,24。 25.在存在的地方,因此价格始终以束或树生成,如果价格始终生成,直到今天和三天。
mysql> select distinct rule_date from catalogrule_product_price; +------------+ | rule_date | +------------+ | 2013-04-23 | | 2013-04-24 | | 2013-04-25 | +------------+ 3 rows in set (0.00 sec)
解决方案
不。
Cron Job称观察者方法 Mage_CatalogRule_Model_Observer::dailyCatalogUpdate()
. 。这个打电话 Mage_CatalogRule_Model_Resource_Rule::applyAllRulesForDateRange()
没有争论。
如果 applyAllRulesForDateRange()
被称为没有参数,有一天+/-假定当前日期。
那么你 能够 创建较新或以上的日期,但夜间Cron工作却没有。
其他提示
我花了一些时间来理解这一点:)
脚本计算了 当前日期, 前一天 和 第二天.
其中,更新包括3天的间隔[Magento 2.2.x
- 当前一天 - + 1天前1天
克朗的每日更新目录价格规则
/Vendor/magento/module-catalog-rule/cron/dailycatalogupdate.php
- 更新包括间隔3天 - 当前一天 - + 1天前1天
- 此方法是从Cron过程中调用的,Cron在UTC时间和
- 我们应该生成间隔-1天的数据... +1天
根据规则设置的reindex产品价格。
/Vendor/magento/module-catalog-rule/model/indexer/reindexruleproductprice.php
public function execute(
$batchCount,
\Magento\Catalog\Model\Product $product = null,
$useAdditionalTable = false
) {
$fromDate = mktime(0, 0, 0, date('m'), date('d') - 1);
$toDate = mktime(0, 0, 0, date('m'), date('d') + 1);
/**
* Update products rules prices per each website separately
* because of max join limit in mysql
*/
-
-
-
$ruleData['from_time'] = $this->roundTime($ruleData['from_time']);
$ruleData['to_time'] = $this->roundTime($ruleData['to_time']);
/**
* Build prices for each day
*/
for ($time = $fromDate; $time <= $toDate; $time += IndexBuilder::SECONDS_IN_DAY) {
if (($ruleData['from_time'] == 0 ||
$time >= $ruleData['from_time']) && ($ruleData['to_time'] == 0 ||
$time <= $ruleData['to_time'])
) {
$priceKey = $time . '_' . $productKey;
if (isset($stopFlags[$priceKey])) {
continue;
}
if (!isset($dayPrices[$priceKey])) {
$dayPrices[$priceKey] = [
'rule_date' => $time,
'website_id' => $ruleData['website_id'],
'customer_group_id' => $ruleData['customer_group_id'],
'product_id' => $ruleProductId,
'rule_price' => $this->productPriceCalculator->calculate($ruleData),
'latest_start_date' => $ruleData['from_time'],
'earliest_end_date' => $ruleData['to_time'],
];
} else {
$dayPrices[$priceKey]['rule_price'] = $this->productPriceCalculator->calculate(
$ruleData,
$dayPrices[$priceKey]
);
$dayPrices[$priceKey]['latest_start_date'] = max(
$dayPrices[$priceKey]['latest_start_date'],
$ruleData['from_time']
);
$dayPrices[$priceKey]['earliest_end_date'] = min(
$dayPrices[$priceKey]['earliest_end_date'],
$ruleData['to_time']
);
}
if ($ruleData['action_stop']) {
$stopFlags[$priceKey] = true;
}
}
}
因此计算持续时间
$fromDate = mktime(0, 0, 0, date('m'), date('d') - 1);
$toDate = mktime(0, 0, 0, date('m'), date('d') + 1);
在Magento 1.x中 漏洞 如果您生活在GMT超过+01:00的时区中,则会发生。默认的cronjob在01:00运行,并使用GMT时间来设置Rule_date。在上述情况下,日期将是“昨天”,因此当天没有价格规则。
例子:
Current Datetime: 2017-07-19 01:00:00 (at current timezone)
Current Datetime at GMT: 2017-07-18 23:00:00
At 01:00 cronjob runs to write price rules with "$coreDate->gmtTimestamp('Today');"
Function will return "2017-07-18" which in this example is "yesterday"
解决方案2.2.x
/Vendor/magento/module-catalog-rule/model/indexer/indexbuilder.php
$fromTime = strtotime($rule->getFromDate());
$toTime = strtotime($rule->getToDate());
$toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
参考