This commit is contained in:
@@ -7,16 +7,12 @@ use App\Entity\Product;
|
||||
use App\Entity\Stock;
|
||||
use App\Entity\Warehouse;
|
||||
use App\Repository\ProductRepository;
|
||||
use App\Repository\StockRepository;
|
||||
use App\Repository\WarehouseRepository;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class HiltesImport
|
||||
{
|
||||
private $productRepository;
|
||||
private $stockRepository;
|
||||
private $warehouseRepository;
|
||||
private $logger;
|
||||
protected $currentDirPath;
|
||||
@@ -24,9 +20,6 @@ class HiltesImport
|
||||
|
||||
public function __construct(ProductRepository $productRepository, LoggerInterface $logger)
|
||||
{
|
||||
// $this->stockRepository = $stockRepository;
|
||||
// $this->warehouseRepository = $warehouseRepository;
|
||||
|
||||
$this->productRepository = $productRepository;
|
||||
$this->logger = $logger;
|
||||
|
||||
@@ -34,7 +27,9 @@ class HiltesImport
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return array|void
|
||||
*/
|
||||
public function startImport()
|
||||
{
|
||||
#*** Holt alle Dateien
|
||||
@@ -44,6 +39,7 @@ class HiltesImport
|
||||
if(is_file($file['realPath'])){
|
||||
$this->loadFiles($file['realPath'],$file['fileSize']);
|
||||
}else{
|
||||
|
||||
return array('error'=>1,'text'=>'Error is_file('.$file['realPath'].')');
|
||||
}
|
||||
}
|
||||
@@ -52,6 +48,10 @@ class HiltesImport
|
||||
}else
|
||||
return array('error'=>1,'text'=>'Error in getFiles');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function getFiles()
|
||||
{
|
||||
$finder = Finder::create();
|
||||
@@ -62,6 +62,8 @@ class HiltesImport
|
||||
# return $file->isDir() || \preg_match('/\.(php|json)$/', $file->getPathname());
|
||||
#});
|
||||
if ($finder->hasResults()) {
|
||||
|
||||
dump($finder);
|
||||
foreach ($finder as $file) {
|
||||
$this->arrData['orgFiles']['data'][] = array(
|
||||
'realPath' => $file->getRealPath(),
|
||||
@@ -79,9 +81,8 @@ class HiltesImport
|
||||
{
|
||||
|
||||
$file = new \SplFileObject($srcFile);
|
||||
|
||||
|
||||
dump($file->getRealPath());
|
||||
|
||||
$this->logger->info('Starte Import von ' . $file->getRealPath());
|
||||
|
||||
$c = 0;
|
||||
@@ -98,6 +99,9 @@ class HiltesImport
|
||||
$this->switchSaveData($this->splitLine($data));
|
||||
}
|
||||
|
||||
// $em = $this->productRepository->getEntityManager();
|
||||
// $em->flush();
|
||||
|
||||
dump($c . ' Datensätze importiert');
|
||||
}
|
||||
protected function splitLine($str){
|
||||
@@ -190,8 +194,8 @@ class HiltesImport
|
||||
#menge;
|
||||
$prod->setStock($stock);
|
||||
|
||||
#gtin;
|
||||
$prod->setGtin($arr[1]);
|
||||
#eanzuIdent;
|
||||
$prod->setGtin($arr[13]);
|
||||
|
||||
$prod->setShopwareId("");
|
||||
|
||||
|
||||
@@ -2,14 +2,17 @@
|
||||
|
||||
namespace App\Helper;
|
||||
|
||||
use App\Entity\Products;
|
||||
use App\Repository\ProductsRepository;
|
||||
|
||||
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
use Vin\ShopwareSdk\Client\AdminAuthenticator;
|
||||
use Vin\ShopwareSdk\Client\GrantType\ClientCredentialsGrantType;
|
||||
use Vin\ShopwareSdk\Data\Context;
|
||||
use Vin\ShopwareSdk\Data\Criteria;
|
||||
use Vin\ShopwareSdk\Data\Entity\Order\OrderDefinition;
|
||||
use Vin\ShopwareSdk\Data\Entity\Product\ProductDefinition;
|
||||
use Vin\ShopwareSdk\Data\Filter\EqualsFilter;
|
||||
use Vin\ShopwareSdk\Factory\RepositoryFactory;
|
||||
|
||||
@@ -34,8 +37,12 @@ class Shopware
|
||||
try {
|
||||
$grantType = new ClientCredentialsGrantType($_ENV['SHOPWARE_API_ID'], $_ENV['SHOPWARE_API_KEY']);
|
||||
$adminClient = new AdminAuthenticator($grantType, $_ENV['SHOPWARE_API_URL']);
|
||||
|
||||
//dump([$grantType, $adminClient,$_ENV['SHOPWARE_API_ID'], $_ENV['SHOPWARE_API_KEY']]);
|
||||
|
||||
return $adminClient->fetchAccessToken();
|
||||
} catch (\Exception $e) {
|
||||
dump($e->getMessage());
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -70,30 +77,58 @@ class Shopware
|
||||
return $orders->getEntities();
|
||||
}
|
||||
|
||||
public function setProduct(Products $product){
|
||||
/**
|
||||
* @param $prod
|
||||
*/
|
||||
public function setProduct($prod): void
|
||||
{
|
||||
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
|
||||
|
||||
//prüfen ob Shopware Produktid schon bekannt ist
|
||||
if($product->getProductId() == null){
|
||||
if($prod->getShopwareId() == null){
|
||||
$this->logger->error('Shopware Produkt ID ist nicht bekannt');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
|
||||
$productRepository->update($product, $context);
|
||||
}
|
||||
|
||||
public function pushStock()
|
||||
{
|
||||
$productRepository = new ProductsRepository();
|
||||
$products = $productRepository->findAll();
|
||||
dump($prod->getShopwareId());
|
||||
|
||||
|
||||
|
||||
|
||||
foreach ($products as $product) {
|
||||
$this->setProduct($product);
|
||||
try {
|
||||
$productRepository->update([
|
||||
'id' => $prod->getShopwareId(),
|
||||
'stock' => $prod->getStock()->getInStock()
|
||||
], $context);
|
||||
} catch (\ShopwareResponseException $e) {
|
||||
$this->logger->error($e->getResponse());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getShopwareIdbyGtin($gtin)
|
||||
{
|
||||
$context = new Context($_ENV['SHOPWARE_API_URL'], $this->shopwareAuth());
|
||||
|
||||
// Create the repository for the entity
|
||||
$productRepository = RepositoryFactory::create(ProductDefinition::ENTITY_NAME);
|
||||
|
||||
// Create the criteria
|
||||
$criteria = new Criteria();
|
||||
$criteria->addFilter(new EqualsFilter('ean', $gtin));
|
||||
|
||||
$products = $productRepository->search($criteria, $context);
|
||||
|
||||
//dump($products->getEntities()->first());
|
||||
|
||||
if($products->count() > 0){
|
||||
$productCollection = $products->getEntities();
|
||||
return $productCollection->first();
|
||||
//$prod->setShopwareId($products->getEntities()->first()->getId());
|
||||
//return $products->getEntities()->first();
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user