Bei Bestellimport werden ESD Artikel nicht zugeordnet.

Guten Tag, Im vorraus möchte ich sagen, das ich wirklich kein Fachmann bin, was Programmierung angeht. Beide vorgestellten Codes stammen von einem gekauften Plugin. Es geht um folgendes: Über das Plugin von Via Ebay werden alle Bestellungen auf Ebay in unseren Shop importiert. Anschließend wird durch das Plugin " Automatische Belegerstellung ein Lizenzschlüssel+ Rechnung versand. Soweit die Theorie. Solange die Bestellung direkt über den Shop kommt, funktioniert das auch einwandfrei. Wird die Bestellung allerdings durch das Via Ebay Plugin importiert, wird dem Käufer kein Lizenzschlüssel zugewiesen. Hier der Code des Imports aus Ebay: ########################### ### Import Orders START ### ########################### /\*\* \* get the Orders from VIA eBay and import or Update in Shopware \*/ public function getVIAeBayOrdersAction() { $VIAeBay = new VIAeBay(); $config = Shopware()-\>Plugins()-\>Backend()-\>SwpVIAeBay()-\>Config(); $date = Shopware()-\>Db()-\>fetchOne('SELECT MAX(ordertime) FROM s\_order AS o INNER JOIN s\_order\_attributes AS oa ON o.id = oa.orderID WHERE oa.swp\_viaebay\_id IS NOT NULL'); /\* if($date) $date = date('Y-m-d', strtotime($date)).'T'.date('H:i:s', strtotime($date)); else $date = null; \*/ $orders = $VIAeBay-\>getSalesOrders(); foreach($orders-\>d as $order) { $checkOrder = Shopware()-\>Db()-\>fetchOne('SELECT orderID FROM s\_order\_attributes WHERE swp\_viaebay\_id='.$order-\>Id); if(!$checkOrder) { $userID = self::importCustomerAsGuest($order); $orderID = self::createOrderMainData($VIAeBay, $order, $userID); self::createOrderBillingAddressData($orderID, $userID, ($order-\>Address) ?: $order-\>ShippingAddress); self::createOrderShippingAddressData($orderID, $userID, ($order-\>ShippingAddress) ?: $order-\>Address); self::createOrderDetailsData($orderID, $order-\>SalesOrderItems); } else { self::updateOrderStatus($order, $config-\>shippingcompletestatus, $config-\>paymentcompletestatus); } } } /\*\* \* import the VIA eBay customer as guest in Shopware \* @param Object $order Order from VIA eBay \* @return Int new userID from Shopware \*/ protected static function importCustomerAsGuest($order) { self::splitStreetAndHouseNo($billingStreet, $order-\>Address-\>Street); self::splitStreetAndHouseNo($shippingStreet, $order-\>ShippingAddress-\>Street); $billingCountryID = self::getCounzryID($order-\>Address-\>Country); $shippingCountryID = self::getCounzryID($order-\>ShippingAddress-\>Country); if($billingCountryID) $billingStateID = self::getStateID($billingCountryID, $order-\>Address-\>State); else { $billingCountryID = 0; $billingStateID = 0; } if($shippingCountryID) $shippingStateID = self::getStateID($shippingCountryID, $order-\>ShippingAddress-\>State); else { $shippingCountryID = 0; $shippingStateID = 0; } $data = array( 'email' =\> $order-\>Address-\>Email, 'accountMode' =\> '1', 'internalComment' =\> 'VIA eBay Import', 'billing' =\> array( 'company' =\> ($order-\>Address-\>Company) ?: '', 'salutation' =\> self::getSalutation($order-\>Address-\>Salutation), 'firstName' =\> ($order-\>Address-\>Name) ?: '', 'lastName' =\> ($order-\>Address-\>Surname) ?: '', 'street' =\> ($billingStreet-\>Street) ?: '', 'streetNumber' =\> ($billingStreet-\>HouseNo) ?: '', 'zipCode' =\> ($order-\>Address-\>PostalCode) ?: '', 'city' =\> ($order-\>Address-\>Town) ?: '', 'countryId' =\> ($billingCountryID) ?: '', 'stateId' =\> ($billingStateID) ?: '', 'phone' =\> ($order-\>Address-\>Phone) ?: '' ), 'shipping' =\> array( 'company' =\> ($order-\>ShippingAddress-\>Company) ?: '', 'salutation' =\> self::getSalutation($order-\>ShippingAddress-\>Salutation), 'firstName' =\> ($order-\>ShippingAddress-\>Name) ?: '', 'lastName' =\> ($order-\>ShippingAddress-\>Surname) ?: '', 'street' =\> ($shippingStreet-\>Street) ?: '', 'streetNumber' =\> ($shippingStreet-\>HouseNo) ?: '', 'zipCode' =\> ($order-\>ShippingAddress-\>PostalCode) ?: '', 'city' =\> ($order-\>ShippingAddress-\>Town) ?: '', 'countryId' =\> ($shippingCountryID) ?: '', 'stateId' =\> ($shippingStateID) ?: '' ) ); $userResource = \Shopware\Components\Api\Manager::getResource('customer'); $newUser = $userResource-\>create($data); $newUserID = $newUser-\>getId(); return $newUserID; } /\*\* \* create the order main data \* @param Object $order The VIA eBay Order Ressource \* @return Int Order ID from Shopware \*/ protected static function createOrderMainData($VIAeBay, $order, $userID) { date\_default\_timezone\_set('Europe/Berlin'); $config = Shopware()-\>Plugins()-\>Backend()-\>SwpVIAeBay()-\>Config(); $sOrder = array( 'ordernumber' =\> Shopware()-\>System()-\>sMODULES['sOrder']-\>sGetOrderNumber(), 'userID' =\> $userID, 'invoice\_amount' =\> ($order-\>TotalPrice + $order-\>ShippingServiceCost), 'invoice\_shipping' =\> $order-\>ShippingServiceCost, 'language' =\> Shopware()-\>Db()-\>fetchOne('SELECT id FROM s\_core\_multilanguage WHERE `default`=1'), 'ordertime' =\> date('Y-m-d H:i:s', preg\_replace('/[^\d]/','', $order-\>CreationDate)/1000), 'net' =\> '0', 'internalcomment' =\> 'VIA eBay Import | '.$order-\>ShippingService, 'taxfree' =\> '0', 'dispatchID' =\> Shopware()-\>Db()-\>fetchOne('SELECT id FROM s\_premium\_dispatch WHERE name="Versand"'), 'currency' =\> $order-\>CurrencyCode, 'subshopID' =\> Shopware()-\>Db()-\>fetchOne('SELECT id FROM s\_core\_shops WHERE main\_id IS NULL'), ); $paymentID = self::getShopPaymentID($order-\>PaymentOption); if($paymentID) $sOrder['paymentID'] = $paymentID; if($order-\>PaymentTransactionId) $sOrder['transactionID'] = $order-\>PaymentTransactionId; if($order-\>MarkedAsShipped && $config-\>shippingcompletestatus) $sOrder['status'] = $config-\>shippingcompletestatus; else $sOrder['status'] = '0'; if($order-\>MarkedAsPayed && $config-\>paymentcompletestatus) $sOrder['cleared'] = $config-\>paymentcompletestatus; else $sOrder['cleared'] = '17'; if($order-\>PaidDate) $sOrder['cleareddate'] = date('Y-m-d H:i:s', preg\_replace('/[^\d]/','', $order-\>PaidDate)/1000); if($order-\>BuyerCheckoutMessage) $sOrder['customercomment'] = $order-\>BuyerCheckoutMessage; Shopware()-\>Db()-\>insert('s\_order', $sOrder); $orderID = Shopware()-\>Db()-\>lastInsertId(); $sOrderAttributes = array( 'orderID' =\> $orderID, 'swp\_viaebay\_id' =\> $order-\>Id, ); Shopware()-\>Db()-\>insert('s\_order\_attributes', $sOrderAttributes); $VIAeBay-\>updateForeignOrderID($order-\>Id, (string)$sOrder['ordernumber']); return $orderID; } /\*\* \* create the Order Billing Address in Shopware \* @param Int $orderID Order ID \* @param Object $billingAddress VIA eBay Billing Adress Ressource \*/ protected static function createOrderBillingAddressData($orderID, $userID, $billingAddress) { self::splitStreetAndHouseNo($street, $billingAddress-\>Street); $countryID = self::getCounzryID($billingAddress-\>Country); if($countryID) $StateID = self::getStateID($countryID, $billingAddress-\>State); else { $countryID = 0; $StateID = 0; } $sOrderBillingAddress = array( 'userID' =\> $userID, 'orderID' =\> $orderID, 'company' =\> ($billingAddress-\>Company) ?: '', 'salutation' =\> self::getSalutation($billingAddress-\>Salutation), 'firstname' =\> ($billingAddress-\>Name) ?: '', 'lastname' =\> ($billingAddress-\>Surname) ?: '', 'street' =\> ($street-\>Street) ?: '', 'streetnumber' =\> ($street-\>HouseNo) ?: '', 'zipcode' =\> ($billingAddress-\>PostalCode) ?: '', 'city' =\> ($billingAddress-\>Town) ?: '', 'phone' =\> ($billingAddress-\>Phone) ?: '', 'countryID' =\> $countryID, 'stateID' =\> $StateID ); Shopware()-\>Db()-\>insert('s\_order\_billingaddress', $sOrderBillingAddress); $billingID = Shopware()-\>Db()-\>lastInsertId(); $sOrderBillingAddressAttributes = array( 'billingID' =\> $billingID, 'swp\_viaebay\_id' =\> $billingAddress-\>Id ); Shopware()-\>Db()-\>insert('s\_order\_billingaddress\_attributes', $sOrderBillingAddressAttributes); } /\*\* \* create the Order Shipping Address in Shopware \* @param Int $orderID Order ID \* @param Object $shippingAddress VIA eBay Shipping Adress Ressource \*/ protected static function createOrderShippingAddressData($orderID, $userID, $shippingAddress) { self::splitStreetAndHouseNo($street, $shippingAddress-\>Street); $countryID = self::getCounzryID($shippingAddress-\>Country); if($countryID) $StateID = self::getStateID($countryID, $shippingAddress-\>State); else { $countryID = 0; $StateID = 0; } $sOrderShippingAddress = array( 'userID' =\> $userID, 'orderID' =\> $orderID, 'company' =\> ($shippingAddress-\>Company) ?: '', 'salutation' =\> self::getSalutation($shippingAddress-\>Salutation), 'firstname' =\> ($shippingAddress-\>Name) ?: '', 'lastname' =\> ($shippingAddress-\>Surname) ?: '', 'street' =\> ($street-\>Street) ?: '', 'streetnumber' =\> ($street-\>HouseNo) ?: '', 'zipcode' =\> ($shippingAddress-\>PostalCode) ?: '', 'city' =\> ($shippingAddress-\>Town) ?: '', 'countryID' =\> $countryID, 'stateID' =\> $StateID ); Shopware()-\>Db()-\>insert('s\_order\_shippingaddress', $sOrderShippingAddress); $shippingID = Shopware()-\>Db()-\>lastInsertId(); $sOrderShippingAddressAttributes = array( 'shippingID' =\> $shippingID, 'swp\_viaebay\_id' =\> $shippingAddress-\>Id ); Shopware()-\>Db()-\>insert('s\_order\_shippingaddress\_attributes', $sOrderShippingAddressAttributes); } /\*\* \* create the ordered Articles in Shopware \* @param Int $orderID Order ID \* @param Array $orderDetails Array with ordered Articles \*/ protected static function createOrderDetailsData($orderID, $orderDetails) { foreach($orderDetails as $orderDetail) { if($orderDetail-\>ProductVariationId) $name = Shopware()-\>Db()-\>fetchOne('SELECT a.name FROM s\_articles AS a INNER JOIN s\_articles\_attributes as aa ON a.id=aa.articleID WHERE aa.swp\_viaebay\_id='.$orderDetail-\>ProductVariationId); elseif($orderDetail-\>Name) $name = $orderDetail-\>Name; if(!$name) $name = '-'; if($orderDetail-\>ProductVariationId) $articleordernumber = Shopware()-\>Db()-\>fetchOne('SELECT ad.ordernumber FROM s\_articles\_details AS ad INNER JOIN s\_articles\_attributes AS aa ON ad.id=aa.articledetailsID WHERE aa.swp\_viaebay\_id='.$orderDetail-\>ProductVariationId); elseif($orderDetail-\>ForeignId) $articleordernumber = $orderDetail-\>ForeignId; else $articleordernumber = $orderDetail-\>ProductId; $sOrderDetails = array( 'orderID' =\> $orderID, 'ordernumber' =\> Shopware()-\>Db()-\>fetchOne('SELECT ordernumber FROM s\_order WHERE id='.$orderID), 'articleordernumber' =\> $articleordernumber, 'price' =\> $orderDetail-\>Price, 'quantity' =\> $orderDetail-\>Amount, 'name' =\> $name, 'releasedate' =\> '0000-00-00', 'modus' =\> '0', 'esdarticle' =\> '0', 'taxID' =\> '0', 'tax\_rate' =\> self::getArticleTax($orderDetail-\>ForeignId) ); Shopware()-\>Db()-\>insert('s\_order\_details', $sOrderDetails); $detailID = Shopware()-\>Db()-\>lastInsertId(); $sOrderDetailsAttributes = array( 'detailID' =\> $detailID, 'swp\_viaebay\_id' =\> $orderDetail-\>Id ); Shopware()-\>Db()-\>insert('s\_order\_details\_attributes', $sOrderDetailsAttributes); if($orderDetail-\>ProductVariationId) { $stock = Shopware()-\>Db()-\>fetchOne('SELECT ad.instock FROM s\_articles\_details AS ad INNER JOIN s\_articles\_attributes AS aa ON ad.id=aa.articledetailsID WHERE aa.swp\_viaebay\_id="'.$orderDetail-\>ProductVariationId.'"'); if($stock !== false && $stock != '') { $newStock = (int)$stock - (int)$orderDetail-\>Amount; Shopware()-\>Db()-\>exec('UPDATE s\_articles\_details AS ad INNER JOIN s\_articles\_attributes AS aa ON ad.id=aa.articledetailsID SET ad.instock='.$newStock.' WHERE aa.swp\_viaebay\_id="'.$orderDetail-\>ProductVariationId.'"'); } } elseif($orderDetail-\>ForeignId) { $stock = Shopware()-\>Db()-\>fetchOne('SELECT instock FROM s\_articles\_details WHERE ordernumber="'.$orderDetail-\>ForeignId.'"'); if($stock !== false && $stock != '') { $newStock = (int)$stock - (int)$orderDetail-\>Amount; Shopware()-\>Db()-\>exec('UPDATE s\_articles\_details SET instock='.$newStock.' WHERE ordernumber="'.$orderDetail-\>ForeignId.'"'); } } } } /\*\* \* map VIA eBay payment to shop payment \* @param String $paymentCode Payment Code from VIA eBay \* @return Boolean/Int False on error or paymentID from Shopware \*/ protected static function getShopPaymentID($paymentCode) { switch($paymentCode) { case 'CashOnPickup': $paymentName = 'Bar bei Abholung'; break; case 'COD': $paymentName = 'Nachnahme'; break; case 'MoneyXferAccepted': case 'MoneyXferAcceptedInCheckout': $paymentName = 'Vorkasse'; break; case 'Paypal': case 'PayPal': $paymentName = 'PayPal'; break; default: return false; } $paymentID = Shopware()-\>Db()-\>fetchOne('SELECT id FROM s\_core\_paymentmeans WHERE description="'.$paymentName.'"'); if($paymentID) return $paymentID; else return false; } /\*\* \* get the correct salutation for Shopware \* @param String $salutation Salutation from VIA eBay \* @return String Salutaion for Shopware \*/ protected static function getSalutation($salutation) { switch($salutation) { case 'Firma': return 'company'; break; case 'Herr': return 'mr'; break; case 'Frau': return 'ms'; break; default: return 'mr'; break; } } /\*\* \* split the full Street in Street and Housenumber \* @param Object $obj Object to modify to split the Street and Housenumber \* @param String $street the full Street \*/ protected static function splitStreetAndHouseNo(&$obj, $street) { if(preg\_match ('/(.\*)(\d+)$/U', $street, $m)) { $obj-\>Street = $m[1]; $obj-\>HouseNo = $m[2]; } elseif (preg\_match ('/(.\*)\s+(\S+)$/', $street, $m)) { $obj-\>Street = $m[1]; $obj-\>HouseNo = $m[2]; } else { $obj-\>Street = $street; $obj-\>HouseNo = '1'; } $obj-\>Street = trim($obj-\>Street); $obj-\>HouseNo = trim($obj-\>HouseNo); } /\*\* \* get the Country ID from Shopware \* @param String $country ISO Code for Country \* @return Int ID for the Country \*/ protected static function getCounzryID($country) { return Shopware()-\>Db()-\>fetchOne('SELECT id FROM s\_core\_countries WHERE countryiso="'.$country.'"'); } /\*\* \* get the State ID from Shopware \* @param Int $countryID Coubtry ID \* @param String $state shortcode for state \* @return Int ID for the State \*/ protected static function getStateID($countryID, $state) { return Shopware()-\>Db()-\>fetchOne('SELECT id FROM s\_core\_countries\_states WHERE countryID='.$countryID.' AND shortcode="'.$state.'"'); } /\*\* \* get the Tax and the net Price for the Article \* @param String $foreignId Shopware ordernumber for the Article \* @param Double $price \* @return Object with Tax and net Price for this Article \*/ protected static function getArticleTax($foreignId) { if($foreignId) { $taxID = Shopware()-\>Db()-\>fetchOne('SELECT a.taxID FROM s\_articles AS a INNER JOIN s\_articles\_details AS ad ON a.id = ad.articleID WHERE ad.ordernumber="'.$foreignId.'"'); if($taxID === false) return '19'; else return Shopware()-\>Db()-\>fetchOne('SELECT tax FROM s\_core\_tax WHERE id='.$taxID); } else return '19'; } /\*\* \* update the order status from VIA eBay to Shopware \* @param Object $order Order from VIA eBay \* @param Int $orderStatus Shopware order status configured in Plugin \* @param Int $paymentStatus Shopware payment status configured in Plugin \*/ protected static function updateOrderStatus($order, $orderStatus, $paymentStatus) { date\_default\_timezone\_set('Europe/Berlin'); $sOrder = array(); $orderID = Shopware()-\>Db()-\>fetchOne('SELECT orderID FROM s\_order\_attributes WHERE swp\_viaebay\_id='.$order-\>Id); if(!$orderID) return; if(!$order-\>MarkedAsShipped && !$order-\>MarkedAsPayed && !$order-\>PaidDate) return; if($order-\>MarkedAsShipped && $orderStatus) $sOrder['status'] = $orderStatus; if($order-\>MarkedAsPayed && $paymentStatus) $sOrder['cleared'] = $paymentStatus; if($order-\>PaidDate) $sOrder['cleareddate'] = date('Y-m-d H:i:s', preg\_replace('/[^\d]/','', $order-\>PaidDate)/1000); Shopware()-\>Db()-\>update ('s\_order', $sOrder, 'id='.$orderID); } ######################### ### Import Orders END ### ######################### Ich hoffe wirklich ihr könnt mir da weiterhelfen. So ist unser System nämlich wirklich uneffektiv. LG Benedikt

Dazu musst du programmieren können, traurige Wahrheit. Die Funktion die Artikel der Bestellung hinzufügt muss erweitert werden. So sieht das für mich nach einem kurzen Blick aus.