本文整理汇总了PHP中Marketplace::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP Marketplace::findFirst方法的具体用法?PHP Marketplace::findFirst怎么用?PHP Marketplace::findFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Marketplace
的用法示例。
在下文中一共展示了Marketplace::findFirst方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addByIDAction
public function addByIDAction()
{
$request = $this->request;
$response = $this->response;
$flash = $this->flash;
if ($request->isPost()) {
$product_id = $request->getPost('product_id', 'int');
$mplace_id = $request->getPost('mplace_id', 'int');
$lang = $request->getPost('lang', 'string');
$product = PProductMain::findFirst($product_id);
$mplace = Marketplace::findFirst($mplace_id);
// Validations
if (!$product) {
$flash->error('Ошибка: товар не найден!');
return $response->redirect('seller/addbyid');
}
if ($product->hold == 1) {
$flash->error('Ошибка: товар на холде!');
return $response->redirect('seller/addbyid');
}
if (!$mplace) {
$flash->error('Ошибка: площадка не найдена!');
return $response->redirect('seller/addbyid');
}
if (!preg_match("/{$lang}/", $mplace->prefs)) {
$flash->error('Ошибка: язык не соответствует площадке!');
return $response->redirect('seller/addbyid');
}
// Check for appropriate marketseller
$marketseller = Marketseller::findFirst("user_id={$this->auth->id} AND marketplace_id={$mplace_id} AND tmaterial_id={$product->tmaterial_id} AND langcode LIKE '%{$lang}%'");
// If there is no marketseller or if the product is already placed create a new marketseller
if (!$marketseller or MPlacement::findFirst("marketseller_id={$marketseller->id} AND product_id={$product->id}")) {
$mseller = new Marketseller();
$mseller->id = $mseller->id();
$mseller->created = time();
$mseller->updated = time();
$mseller->fio = "{$product->PCategoryGroup->title} на {$mplace->title}";
$mseller->user_id = $this->auth->id;
$mseller->marketplace_id = $mplace_id;
$mseller->tmaterial_id = $product->tmaterial_id;
$mseller->langcode = $mplace->prefs;
if (!$mseller->create()) {
$flash->error('Ошибка при создании нового виртуального магазина!');
return $response->redirect('seller/addbyid');
} else {
return $response->redirect("seller/product/{$mseller->id}/{$product_id}/{$lang}");
}
} else {
return $response->redirect("seller/product/{$marketseller->id}/{$product_id}/{$lang}");
}
}
}