Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/BugfixVariantUVP'
Browse files Browse the repository at this point in the history
* origin/BugfixVariantUVP:
  Variant UVP bugfix
  unnused variable
  use the variant uvp and purchaseprice from the variant and fallback to the priceSet if not present
  Add 2 new events to alter the way linked data is handled

# Conflicts:
#	Components/Import/Entity/PlentymarketsImportEntityItemLinked.php
  • Loading branch information
jochenmanz committed Nov 2, 2016
2 parents 408c952 + c806d8d commit 6808960
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 22 deletions.
41 changes: 34 additions & 7 deletions Components/Import/Entity/PlentymarketsImportEntityItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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'];
}
Expand Down
34 changes: 24 additions & 10 deletions Components/Import/Entity/PlentymarketsImportEntityItemPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -156,11 +163,18 @@ public function getPrices()
$price['price'] = $this->getItemPrice($this->PLENTY_PriceSet);
}

// 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;
Expand Down
6 changes: 5 additions & 1 deletion Components/Import/PlentymarketsImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
54 changes: 50 additions & 4 deletions Components/Import/PlentymarketsImportItemVariantController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
{
//
Expand All @@ -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);

/**
Expand All @@ -140,7 +166,7 @@ public function __construct($ItemBase)
*/
foreach ($Response_GetAttributeValueSets->AttributeValueSets->item as $AttributeValueSet)
{
$this->variant2markup[$AttributeValueSet->AttributeValueSetID] = 0;
$this->variant2markup[$AttributeValueSet->AttributeValueSetID] = 0.0;

foreach ($AttributeValueSet->Attribute->item as $Attribute)
{
Expand Down Expand Up @@ -313,6 +339,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
*
Expand Down

0 comments on commit 6808960

Please sign in to comment.