构建一个简单的下拉菜单时,标题出现错误。这是我的看法:
function get_unpaid_orders() {
global $wpdb;
$unpaid_orders = $wpdb->get_col( $wpdb->prepare( "
SELECT posts.ID
FROM {$wpdb->posts} AS posts
WHERE posts.post_status = 'wc-on-hold'
AND posts.post_date < %s
", date( 'Y-m-d H:i:s', strtotime('-1 minute') ) ) );
return $unpaid_orders;
}
add_action( 'woocommerce_cancel_unpaid_submitted', 'cancel_unpaid_orders' );
function cancel_unpaid_orders() {
$unpaid_orders = get_unpaid_orders();
if ( $unpaid_orders ) {
foreach ( $unpaid_orders as $unpaid_order ) {
$order = wc_get_order( $unpaid_order );
$cancel_order = true;
foreach ( $order->get_items() as $item_key => $item_values) {
$manage_stock = get_post_meta( $item_values, '_manage_stock', true );
if ( $manage_stock == "yes" ) {
$payment_method = $order->get_payment_method();
if ( $payment_method == "bacs" ) {
$cancel_order = false;
}
}
}
if ( $cancel_order == true ) {
$order -> update_status( 'cancelled', __( 'The order was cancelled due to no payment from customer.', 'woocommerce') );
}
}
}
}
ViewModel:
<td>
<select asp-for="ThisShutdown.Id" asp-items=@(new
SelectList(Model.ListOfAllGGGs,"Id","Location"))>
<option>Selelct a GGG</option>
</select>
</td>
控制器:
public class PlannerViewModel
{
public GGGShutdown ThisShutdown { get; set; }
public IEnumerable<GGGShutdown> ExistingShutdowns { get; set; }
public IEnumerable<GGG> ListOfAllGGGs { get; set; }
}
有关信息,这是GGG类,这是我用来构建下拉菜单的类:
public class PlannerController : Controller
{
private readonly IGGGRepository _GGGRepository;
private readonly IGGGShutdownRepository _GGGShutdownRepository;
public PlannerController (IGGGShutdownRepository GGGShutdownRepository, IGGGRepository GGGRepository)
{
_GGGShutdownRepository = GGGShutdownRepository;
_GGGRepository = GGGRepository;
}
public IActionResult ShowGGGShutdowns()
{
IEnumerable<GGGShutdown> CurrentShutdowns = _GGGShutdownRepository.GGGShutdowns;
IEnumerable<GGG> AllGGGs = _GGGRepository.GGGs;
PlannerViewModel MyViewModel = new PlannerViewModel();
MyViewModel.ExistingShutdowns = CurrentShutdowns;
MyViewModel.ListOfAllGGGs = AllGGGs;
return View(MyViewModel);
}
}
有什么主意吗?
答案 0 :(得分:1)
“无效列名”错误几乎总是由于您的实体与数据库中代表该表的表不同步而引起的。您可能已经重命名了属性,添加了新属性等,却忽略了生成新的迁移。或者,如果您使用的是现有数据库,则可能需要再次从数据库中重新折叠实体。无论如何,Id
或Location
都不与表中的实际列匹配。找出原因,并解决您的问题。