0) { $this->excludedProdStatusesArr = explode(',', $excludedProdStatusesStr); } } protected function getItems() { $pOrdersIds = isset($this->data[self::IMPORT_ITEMS_IDS_PARAM]) ? $this->data[self::IMPORT_ITEMS_IDS_PARAM] : null; $args = array( 'post_type' => 'atum_purchase_order', 'post_status' => 'any', 'posts_per_page' => -1, 'post__in' => $pOrdersIds ); $query = new \WP_Query($args); $this->items = $query->posts; } protected function getAtumOrder($postId) { return is_plugin_active('atum-stock-manager-for-woocommerce/atum-stock-manager-for-woocommerce.php') ? \Atum\Inc\Helpers::get_atum_order_model(absint($postId), TRUE, \Atum\PurchaseOrders\PurchaseOrders::POST_TYPE) : null; } protected function getOrderItemsProducts($ordersIds, $orderQuantity = '', $itemsIds = null) { $items = array(); foreach ($ordersIds as $id) { $itemIdToProductIdMap = array(); $quantities = array(); $itemQuantities = array(); $orderItems = array(); $orderItemsByItemId = array(); $order = $this->getAtumOrder($id); if (!$order) { continue; } foreach ($order->get_items('line_item') as $itemId => $itemData) { if (!$itemsIds || in_array($itemId, $itemsIds)) { $product = \Atum\Inc\Helpers::get_atum_product( $itemData->get_product() ); if (!$product instanceof \WC_Product ) { continue; } $productId = $product->get_ID(); $quantity = $itemData->get_quantity(); $quantities[$productId] = isset($quantities[$productId]) ? $quantities[$productId] + $quantity : $quantity; $itemQuantities[$itemId] = $quantity; $orderItems[$productId] = $itemData; $itemIdToProductIdMap[$itemId] = $productId; $orderItemsByItemId[$itemId] = $itemData; } } $orderProducts = uslp_a4bGetPosts(array( 'post_type' => array('product', 'product_variation'), 'post__in' => empty($itemIdToProductIdMap) ? array(0) : array_values($itemIdToProductIdMap), 'orderby' => 'post__in', )); $orderProductsIndexedByPostId = array(); foreach ($orderProducts as $orderProduct) { $orderProductsIndexedByPostId[$orderProduct->ID] = $orderProduct; } foreach ($itemIdToProductIdMap as $itemId => $productId) { $item = clone $orderProductsIndexedByPostId[$productId]; $item->orderId = $id; $item->productInOrderQty = isset($itemQuantities[$itemId]) ? $itemQuantities[$itemId] : ''; $item->orderItem = isset($orderItemsByItemId[$itemId]) ? $orderItemsByItemId[$itemId] : null; if ($orderQuantity === 'by-orders') { if (isset($itemQuantities[$itemId])) { for ($i = 0; $i < $itemQuantities[$itemId]; $i++) { $items[] = $item; } } } else { $items[] = $item; } } } return $items; } }