我在prestashop上开发了一个模块,并创建了x命令,我尝试为每个要创建的命令分配不同的日期,这是我已经拥有的:
public function newBox($theCart, $referencesProducts, $subscribeMonth, $showDate)
{
$nbMonth = preg_replace('~\D~', '', $subscribeMonth);
foreach ($referencesProducts as $referencesProduct) {
$ids_product[] = Db::getInstance()->getRow('SELECT p.id_product FROM ' . _DB_PREFIX_ . 'product p WHERE p.reference =\'' . $referencesProduct . '\'');
}
// Si le nbMonth est égale à 1 an alors on applique un resultat à 12 (mois)
if ($nbMonth == 1) {
$productSelected = array_slice($ids_product, 0, 12);
} else {
$productSelected = array_slice($ids_product, 0, $nbMonth);
}
foreach ($productSelected as $product) {
$cart = new Cart();
$cart->id_shop_group = $theCart->id_shop_group;
$cart->id_shop = $theCart->id_shop;
$cart->id_customer = $theCart->id_customer;
$cart->id_carrier = $theCart->id_carrier;
$cart->id_address_delivery = $theCart->id_address_delivery;
$cart->id_address_invoice = $theCart->id_address_invoice;
$cart->id_currency = $theCart->id_currency;
$cart->id_lang = $theCart->id_lang;
$cart->secure_key = $theCart->secure_key;
$cart->add();
$cart->updateQty(1, (int) $product['id_product']);
$this->setDate($cart->id, $showDate['date_delivery'], '');
$cart->addCartRule(847);
$cart->autosetProductAddress();
$this->validateOrder($cart->id, 3, 0.00, 'Abonnement', null, null, false, $cart->secure_key);
}
}
用于计算日期的功能:
function calcDate($date)
{
$m = date('m', strtotime('+30 days', strtotime($date)));
if($m >= 7 && $m < 9){
$dateSelect = date('Y-09-d', strtotime($date));
}else{
$dateSelect = date('Y-m-d', strtotime('+30 days', strtotime($date)));
}
$N = date("N", strtotime($dateSelect));
if($N >6) $dateSelect = date("Y-m-d", strtotime($dateSelect . " previous Saturday"));
return $dateSelect;
}
您知道我的代码中缺少什么吗?
谢谢您的帮助。