Open sidebar
private function deleteProduct($productId) { if (wp_delete_post($productId, true)) { $args = [ //'numberposts' => 2, 'order' => 'ASC', 'post_mime_type' => 'image', 'post_parent' => (int) $productId, 'post_status' => 'inherit', 'post_type' => 'attachment', ]; $child = get_children($args); foreach ($child as $id => $item) { wp_delete_attachment($id, true); } return true; } else { return false; } } private function manageProducts($brand) { if ($products = $this->dsApi->getProductsByBrand($brand)) { $preparedProducts = $this->prepareProducts($products, $brand); echo 'Brand ' . $brand->name . '('. count($products) .' items)' .'...'; if (!empty($preparedProducts['delete'])) { foreach ($preparedProducts['delete'] as $key => $productId) { if ($this->deleteProduct($productId)) { $this->logger->log->info( 'Brand ' . $brand->name . '(' . $brand->id_brand . ')' . ' id: ' . $productId . ' was deleted' ); } else { $this->logger->log->error( 'Brand ' . $brand->name . '(' . $brand->id_brand . ')' . ' id: ' . $productId . ' was not deleted' ); } } } if (!empty($preparedProducts['create'])) { foreach ($preparedProducts['create'] as $key => $product) { $idProduct = $this->createProduct($product, $brand); if ($idProduct != 0) { $this->logger->log->info( 'Brand ' . $brand->name . '(' . $brand->id_brand . ') sku: ' . $product['sku'] . ' was imported' ); } } } if (!empty($preparedProducts['update'])) { foreach ($preparedProducts['update'] as $key => $product) { $idProduct = $this->updateProduct($product, $brand, $product['idProductWc']); if ($idProduct != 0) { $this->logger->log->info( 'Brand ' . $brand->name . '(' . $brand->id_brand . ') sku: ' . $product['sku'] . ' id: ' . $product['idProductWc'] . ' was updated' ); } } } } }
Close sidebar
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting
Back
Please note that all pasted data is publicly available.
Twitter
GitHub
Use setting