浏览代码

product state changes

master
Dukai Károly 3 年前
父节点
当前提交
6e9455de2f
共有 4 个文件被更改,包括 96 次插入1 次删除
  1. +68
    -0
      modules/custom/arlista/src/Entity/Product.php
  2. +1
    -0
      modules/custom/arlista/src/Entity/Status.php
  3. +3
    -1
      modules/custom/arlista/src/Form/Product/ProductAdd.php
  4. +24
    -0
      modules/custom/arlista/src/Form/Product/ProductUploadedEdit.php

+ 68
- 0
modules/custom/arlista/src/Entity/Product.php 查看文件

@@ -666,4 +666,72 @@ class Product extends AbstractEntity {
return $this->warranty != $product->getPrevWarranty();
}

/**
* ON manual product save form submit
*/
public function hasChanges(Product $previousProductState): bool {

$fabricNameChange = $this->isProductFabricNameStateChanged($previousProductState);
$eolChange = $this->isProductEolStateChanged($previousProductState);
$descriptionChange = $this->isProductDescriptionStateChanged($previousProductState);
$notesChangeChange = $this->isProductNotesStateChanged($previousProductState);
$warrantyChange = $this->isProductWarrantyChanged($previousProductState);
$axicoNameChange = $this->isProductAxicoNameChanged($previousProductState);

return $fabricNameChange || $eolChange || $descriptionChange || $notesChangeChange || $warrantyChange || $axicoNameChange;
}

public function isProductFabricNameStateChanged(Product $product): bool {
if ($product->getFabricName()) {
return strpos(
strtolower($this->fabricName),
strtolower($product->getFabricName())
) !== false;
}
return false;
}

public function isProductEolStateChanged(Product $product): bool {
if ($product->getEol()) {
return strpos(
strtolower($this->eol),
strtolower($product->getEol())
) !== false;
}
return false;
}

public function isProductDescriptionStateChanged(Product $product): bool {
if ($product->getDescription()) {
return strpos(
strtolower($this->description),
strtolower($product->getDescription())
) !== false;
}return false;
}

public function isProductNotesStateChanged(Product $product): bool {
if ($product->getNotes()) {
return strpos(
strtolower($this->notes),
strtolower($product->getNotes())
) !== false;
}
return false;
}

public function isProductAxicoNameStateChanged(Product $product): bool {
if ($product->getAxicoName()) {
return strpos(
strtolower($this->axicoName),
strtolower($product->getAxicoName())
) !== false;
}
return false;
}

public function isProductWarrantyStateChanged(Product $product): bool {
return $this->warranty != $product->getWarranty();
}

}

+ 1
- 0
modules/custom/arlista/src/Entity/Status.php 查看文件

@@ -23,6 +23,7 @@ class Status {
'TOROLT' => 'Törölt',
'ISMERETLEN' => 'Ismeretlen',
'UJ' => 'Új',
'UJRA_AKTIVALHATO' => 'Újra aktiválható',
'CORRECT_IMPORTED' => 'Aktív adatbázisban',
];
}

+ 3
- 1
modules/custom/arlista/src/Form/Product/ProductAdd.php 查看文件

@@ -376,10 +376,12 @@ class ProductAdd extends ArlistaAbstractForm {
}
$product->setCalculation($calculation);
$product->setCorrectStatus(Status::UJ);
$product->calculatePrices();
$product->setCorrectStatus(Status::UJ);
$product = $this->getProductFactory()->save($product);
\Drupal::messenger()->addStatus('Sikeres mentés!');
$result['products'][0] = $product;

// /{id}/{page}/{correctStatus}/{keyWords}/{listed}/{cikkszam}/{source}/{mid}/{fid}
$params = [

+ 24
- 0
modules/custom/arlista/src/Form/Product/ProductUploadedEdit.php 查看文件

@@ -468,6 +468,10 @@ class ProductUploadedEdit extends ArlistaAbstractForm {

$values = $form_state->getValues();
$product = $this->getProductFactory()->find($values['id']);

$previousProductState = $product;
$previousPrice = $product->getPrice();

$product->setName($values['name']);
$product->setfabricName($values['fabric_name'] ? $values['fabric_name'] : $values['name']);
$product->setAxicoName($values['axico_name'] ? $values['axico_name'] : $values['name']);
@@ -503,6 +507,26 @@ class ProductUploadedEdit extends ArlistaAbstractForm {
$product->setListed($values['listable']);
$product->setPriceDevDTwo($values['price_dev_d_two'] ? $values['price_dev_d_two'] : 0.000);

if($previousPrice !== $product->getPrice()){
if ($product->isComponentBased()) {
$component = $this->getComponentFactory()->find($product->getParentComponentId());
$calculation = $this->getCalculationFactory()->findByComponent($component);
$calculation->setExchangeRate($this->getCalculationFactory()->getExchangeRate($product->getCurrency()));
} else {
$category = $this->getCategoryFactory()->find($product->getParentCategoryId());
$manufacturer = $this->getManufacturerFactory()->find($product->getParentManufacturerId());
$calculation = $this->getCalculationFactory()->findByManufacturerAndCategory($manufacturer, $category);
$calculation->setExchangeRate($this->getCalculationFactory()->getExchangeRate($product->getCurrency()));
}
$product->setCalculation($calculation);
$product->calculatePrices();
}

if($product->hasChanges($previousProductState)){
$product->setCorrectStatus(Status::FRISSITENDO);
}

$product = $this->getProductFactory()->save($product);
$this->getCacheService()->resetCache([$this->getFormId(), $this->source, $product->getId()]);


正在加载...
取消
保存