From ef2f53dba89cace6faf02fc36f14cff793b0c777 Mon Sep 17 00:00:00 2001 From: Jochen Manz Date: Thu, 8 Sep 2016 11:55:12 +0200 Subject: [PATCH 1/4] Add 2 new events to alter the way linked data is handled --- .../PlentymarketsImportEntityItemLinked.php | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Components/Import/Entity/PlentymarketsImportEntityItemLinked.php b/Components/Import/Entity/PlentymarketsImportEntityItemLinked.php index 859ba16c2..7df807ee5 100644 --- a/Components/Import/Entity/PlentymarketsImportEntityItemLinked.php +++ b/Components/Import/Entity/PlentymarketsImportEntityItemLinked.php @@ -69,6 +69,15 @@ protected function purge() { Shopware()->Db()->delete('s_articles_relationships', 'articleID = ' . $this->SHOPWARE_itemId); Shopware()->Db()->delete('s_articles_similar', 'articleID = ' . $this->SHOPWARE_itemId); + + // Allow plugins to change the data + Shopware()->Events()->notify( + 'PlentyConnector_ImportEntityItemLinked_AfterPurge', + array( + 'subject' => $this, + 'id' => $this->SHOPWARE_itemId, + ) + ); } /** @@ -108,6 +117,8 @@ public function link() continue; } + $table = ''; + if ($LinkedItem->Relationship == 'Accessory') { $table = 's_articles_relationships'; @@ -118,7 +129,19 @@ public function link() } else { - continue; + // Allow plugins to change the data + $table = Shopware()->Events()->filter( + 'PlentyConnector_ImportEntityItemLinked_GetTable', + $table, + array( + 'subject' => $this, + 'item' => $LinkedItem + ) + ); + + if (empty($table)) { + continue; + } } Shopware()->Db()->insert( From 5c6f2d4117bfae1b36816bb7a97f628079a6024f Mon Sep 17 00:00:00 2001 From: Jochen Manz Date: Thu, 8 Sep 2016 15:47:30 +0200 Subject: [PATCH 2/4] use the variant uvp and purchaseprice from the variant and fallback to the priceSet if not present --- .../Entity/PlentymarketsImportEntityItem.php | 63 +++++++++++++------ .../PlentymarketsImportEntityItemPrice.php | 36 ++++++++--- .../Import/PlentymarketsImportController.php | 6 +- ...entymarketsImportItemVariantController.php | 55 ++++++++++++++-- 4 files changed, 127 insertions(+), 33 deletions(-) diff --git a/Components/Import/Entity/PlentymarketsImportEntityItem.php b/Components/Import/Entity/PlentymarketsImportEntityItem.php index 671f4e68f..e301a1661 100644 --- a/Components/Import/Entity/PlentymarketsImportEntityItem.php +++ b/Components/Import/Entity/PlentymarketsImportEntityItem.php @@ -81,7 +81,7 @@ class PlentymarketsImportEntityItem * @var array */ protected $categories = array(); - + /** * * @var array @@ -487,7 +487,7 @@ protected function setVariants() { $details['additionaltext'] = $AttributeValueSet->AttributeValueSetName; } - + $details['ean'] = $AttributeValueSet->EAN; $details['X_plentySku'] = $sku; @@ -525,9 +525,9 @@ protected function setCategories() { continue; } - + $categoryToStore = false; - + if(!empty($Category->ItemStandardCategory->item)) { foreach($Category->ItemStandardCategory->item as $ItemStandardCategory) @@ -536,7 +536,7 @@ protected function setCategories() { continue; } - + $categoryToStore = true; } } @@ -547,7 +547,7 @@ protected function setCategories() $this->categories[] = array( 'id' => $categoryId ); - + if($categoryToStore) { $this->seoCategories[] = array( @@ -570,7 +570,7 @@ protected function setCategories() $this->categories[] = array( 'id' => $categoryId ); - + if($categoryToStore) { $this->seoCategories[] = array( @@ -851,13 +851,13 @@ public function importCategories() } $data['categories'][$category['id']] = $category; } - + $SHOPWARE_itemID = PlentymarketsMappingController::getItemByPlentyID($this->ItemBase->ItemID); - + Shopware()->Db()->query("DELETE FROM s_articles_categories_seo WHERE shop_id = ? AND article_id = ?", array($this->Shop->getId(), $SHOPWARE_itemID)); - + if(!empty($this->seoCategories)) - { + { Shopware()->Db()->query("INSERT INTO s_articles_categories_seo (shop_id,article_id,category_id) VALUES(?,?,?)", array($this->Shop->getId(), $SHOPWARE_itemID, $this->seoCategories[0]['categoryId'])); } @@ -961,10 +961,18 @@ public function import() { // Directly add the prices $PlentymarketsImportEntityItemPrice = new PlentymarketsImportEntityItemPrice( - $this->ItemBase->PriceSet, $VariantController->getMarkupByVariantId($variantId) + $this->ItemBase->PriceSet, + $VariantController->getMarkupByVariantId($variantId), + $VariantController->getReferencePriceByVaraintId($variantId) ); + $variant['prices'] = $PlentymarketsImportEntityItemPrice->getPrices(); - $variant['purchasePrice'] = $PlentymarketsImportEntityItemPrice->getPurchasePrice(); + $variant['purchasePrice'] = $VariantController->getPurchasePriceByVariantId($variantId); + + // use purchase price from main product instead + if (empty($variant['purchasePrice'])) { + $variant['purchasePrice'] = $PlentymarketsImportEntityItemPrice->getPurchasePrice(); + } // If the variant has an id, it is already created and mapped soo we just keep it if (array_key_exists('id', $variant)) @@ -1102,7 +1110,11 @@ public function import() else { // Preise eines Normalen Artikels aktualisieren - $PlentymarketsImportEntityItemPrice = new PlentymarketsImportEntityItemPrice($this->ItemBase->PriceSet); + $PlentymarketsImportEntityItemPrice = new PlentymarketsImportEntityItemPrice( + $this->ItemBase->PriceSet, + 0.0, + $this->ItemBase->PriceSet->RRP + ); $PlentymarketsImportEntityItemPrice->update($SHOPWARE_itemID); } @@ -1171,7 +1183,12 @@ public function import() // Media // Preise - $PlentymarketsImportEntityItemPrice = new PlentymarketsImportEntityItemPrice($this->ItemBase->PriceSet); + $PlentymarketsImportEntityItemPrice = new PlentymarketsImportEntityItemPrice( + $this->ItemBase->PriceSet, + 0.0, + $this->ItemBase->PriceSet->RRP + ); + $PlentymarketsImportEntityItemPrice->update($Article->getId()); } @@ -1203,9 +1220,19 @@ public function import() $variant['configuratorOptions'] = $VariantController->getOptionsByVariantId($variantId); // Prices - $PlentymarketsImportEntityItemPrice = new PlentymarketsImportEntityItemPrice($this->ItemBase->PriceSet, $VariantController->getMarkupByVariantId($variantId)); - $variant['prices'] = $PlentymarketsImportEntityItemPrice->getPrices(); - $variant['purchasePrice'] = $PlentymarketsImportEntityItemPrice->getPurchasePrice(); + $PlentymarketsImportEntityItemPrice = new PlentymarketsImportEntityItemPrice( + $this->ItemBase->PriceSet, + $VariantController->getMarkupByVariantId($variantId), + $VariantController->getReferencePriceByVaraintId($variantId) + ); + + $variant['prices'] = $PlentymarketsImportEntityItemPrice->getPrices(); + $variant['purchasePrice'] = $VariantController->getPurchasePriceByVariantId($variantId); + + // use purchase price from main product instead + if (empty($variant['purchasePrice'])) { + $variant['purchasePrice'] = $PlentymarketsImportEntityItemPrice->getPurchasePrice(); + } $number2sku[$variant['number']] = $variant['X_plentySku']; } diff --git a/Components/Import/Entity/PlentymarketsImportEntityItemPrice.php b/Components/Import/Entity/PlentymarketsImportEntityItemPrice.php index 84fd94d30..35a66a37a 100644 --- a/Components/Import/Entity/PlentymarketsImportEntityItemPrice.php +++ b/Components/Import/Entity/PlentymarketsImportEntityItemPrice.php @@ -47,18 +47,25 @@ class PlentymarketsImportEntityItemPrice * * @var float */ - protected $PLENTY_markup = 0; + protected $PLENTY_markup = 0.0; - /** - * Constructor method - * - * @param PlentySoapObject_ItemPriceSet $PriceSet - * @param float $markup - */ - public function __construct($PriceSet, $markup = 0) + /** + * @var float + */ + protected $referencePrice = 0.0; + + /** + * Constructor method + * + * @param PlentySoapObject_ItemPriceSet $PriceSet + * @param float $markup + * @param float $referencePrice + */ + public function __construct($PriceSet, $markup = 0.0, $referencePrice = 0.0) { $this->PLENTY_PriceSet = $PriceSet; $this->PLENTY_markup = $markup; + $this->referencePrice = $referencePrice; $this->prepare(); } @@ -156,11 +163,20 @@ public function getPrices() $price['price'] = $this->getItemPrice($this->PLENTY_PriceSet); } + $referencePrice = 0.0; + + // if uvp is empty, try to load from the price set, which could be the main product + if (empty($this->referencePrice)) { + $referencePrice = $this->PLENTY_PriceSet->RRP; + } else { + $referencePrice = $this->referencePrice; + } + // Reliably available starting in SOAP 111 // check whether the RRP is higher than price to prevent ugly display - if (isset($this->PLENTY_PriceSet->RRP) && !is_null($this->PLENTY_PriceSet->RRP) && isset($price['price']) && ($this->PLENTY_PriceSet->RRP > $price['price'])) + if (isset($referencePrice) && !is_null($referencePrice) && isset($price['price']) && ($referencePrice > $price['price'])) { - $price['pseudoPrice'] = $this->PLENTY_PriceSet->RRP; + $price['pseudoPrice'] = $referencePrice; } $prices[] = $price; diff --git a/Components/Import/PlentymarketsImportController.php b/Components/Import/PlentymarketsImportController.php index 07f2591cf..eaa087042 100644 --- a/Components/Import/PlentymarketsImportController.php +++ b/Components/Import/PlentymarketsImportController.php @@ -86,7 +86,11 @@ public static function importItemPrices() else { $itemDetailID = PlentymarketsMappingController::getItemVariantByPlentyID($ItemsPriceUpdate->SKU); - $PlentymarketsImportEntityItemPrice = new PlentymarketsImportEntityItemPrice($ItemsPriceUpdate, $ItemsPriceUpdate->Markup); + $PlentymarketsImportEntityItemPrice = new PlentymarketsImportEntityItemPrice( + $ItemsPriceUpdate, + $ItemsPriceUpdate->Markup, + $ItemsPriceUpdate->RRP + ); $PlentymarketsImportEntityItemPrice->updateVariant($itemDetailID); } diff --git a/Components/Import/PlentymarketsImportItemVariantController.php b/Components/Import/PlentymarketsImportItemVariantController.php index 794013c38..48ca0678e 100644 --- a/Components/Import/PlentymarketsImportItemVariantController.php +++ b/Components/Import/PlentymarketsImportItemVariantController.php @@ -88,18 +88,31 @@ class PlentymarketsImportItemVariantController * * @var array */ - static $mapping = array( + public static $mapping = array( 'group' => array(), 'option' => array() ); - /** + /** + * @var array + */ + protected $referencePrices; + + /** + * @var + */ + protected $purchasePrices; + + /** * Constructor method * * @param PlentySoapObject_ItemBase $ItemBase */ public function __construct($ItemBase) { + $this->referencePrices = []; + $this->purchasePrices = []; + $this->ItemBase = $ItemBase; foreach ($this->ItemBase->ItemAttributeMarkup->item as $ItemAttributeMarkup) @@ -119,7 +132,11 @@ public function __construct($ItemBase) { $Request_GetAttributeValueSets->AttributeValueSets = array(); - // Attribute Value Sets abfragen + /** + * Attribute Value Sets abfragen + * + * @var PlentySoapObject_ItemAttributeValueSet $AttributeValueSet + */ foreach ($chunk as $AttributeValueSet) { // @@ -130,8 +147,17 @@ public function __construct($ItemBase) $RequestObject_GetAttributeValueSets->AttributeValueSetID = $AttributeValueSet->AttributeValueSetID; $RequestObject_GetAttributeValueSets->Lang = 'de'; $Request_GetAttributeValueSets->AttributeValueSets[] = $RequestObject_GetAttributeValueSets; + + // Reference Price (UVP) + $this->referencePrices[$AttributeValueSet->AttributeValueSetID] = $AttributeValueSet->UVP; + + // Purchase Price + $this->purchasePrices[$AttributeValueSet->AttributeValueSetID] = $AttributeValueSet->PurchasePrice; } + /** + * @var PlentySoapResponse_GetAttributeValueSets $Response_GetAttributeValueSets + */ $Response_GetAttributeValueSets = PlentymarketsSoapClient::getInstance()->GetAttributeValueSets($Request_GetAttributeValueSets); /** @@ -140,7 +166,8 @@ public function __construct($ItemBase) */ foreach ($Response_GetAttributeValueSets->AttributeValueSets->item as $AttributeValueSet) { - $this->variant2markup[$AttributeValueSet->AttributeValueSetID] = 0; + $this->referencePrices[$AttributeValueSet->AttributeValueSetID] = 0.0; + $this->variant2markup[$AttributeValueSet->AttributeValueSetID] = 0.0; foreach ($AttributeValueSet->Attribute->item as $Attribute) { @@ -313,6 +340,26 @@ public function getMarkupByVariantId($variantId) return $this->variant2markup[$variantId]; } + /** + * @param $variantId + * + * @return float + */ + public function getReferencePriceByVaraintId($variantId) + { + return $this->referencePrices[$variantId]; + } + + /** + * @param $variantId + * + * @return float + */ + public function getPurchasePriceByVariantId($variantId) + { + return $this->purchasePrices[$variantId]; + } + /** * Returns an array of configurator groups for the use with the shopware REST API * From 1d67d65b75c4caa66004cb86acb92c6283f61097 Mon Sep 17 00:00:00 2001 From: Jochen Manz Date: Thu, 8 Sep 2016 15:50:43 +0200 Subject: [PATCH 3/4] unnused variable --- Components/Import/Entity/PlentymarketsImportEntityItemPrice.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/Components/Import/Entity/PlentymarketsImportEntityItemPrice.php b/Components/Import/Entity/PlentymarketsImportEntityItemPrice.php index 35a66a37a..3d0f69574 100644 --- a/Components/Import/Entity/PlentymarketsImportEntityItemPrice.php +++ b/Components/Import/Entity/PlentymarketsImportEntityItemPrice.php @@ -163,8 +163,6 @@ public function getPrices() $price['price'] = $this->getItemPrice($this->PLENTY_PriceSet); } - $referencePrice = 0.0; - // if uvp is empty, try to load from the price set, which could be the main product if (empty($this->referencePrice)) { $referencePrice = $this->PLENTY_PriceSet->RRP; From c806d8d64a7c87d599ac887bb94f96f1e38209ba Mon Sep 17 00:00:00 2001 From: Jochen Manz Date: Mon, 12 Sep 2016 15:54:22 +0200 Subject: [PATCH 4/4] Variant UVP bugfix --- Components/Import/PlentymarketsImportItemVariantController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Components/Import/PlentymarketsImportItemVariantController.php b/Components/Import/PlentymarketsImportItemVariantController.php index 48ca0678e..a9b27c7b1 100644 --- a/Components/Import/PlentymarketsImportItemVariantController.php +++ b/Components/Import/PlentymarketsImportItemVariantController.php @@ -166,7 +166,6 @@ public function __construct($ItemBase) */ foreach ($Response_GetAttributeValueSets->AttributeValueSets->item as $AttributeValueSet) { - $this->referencePrices[$AttributeValueSet->AttributeValueSetID] = 0.0; $this->variant2markup[$AttributeValueSet->AttributeValueSetID] = 0.0; foreach ($AttributeValueSet->Attribute->item as $Attribute)