| return $this->warranty != $product->getPrevWarranty(); | 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(); | |||||
| } | |||||
| } | } |
| 'TOROLT' => 'Törölt', | 'TOROLT' => 'Törölt', | ||||
| 'ISMERETLEN' => 'Ismeretlen', | 'ISMERETLEN' => 'Ismeretlen', | ||||
| 'UJ' => 'Új', | 'UJ' => 'Új', | ||||
| 'UJRA_AKTIVALHATO' => 'Újra aktiválható', | |||||
| 'CORRECT_IMPORTED' => 'Aktív adatbázisban', | 'CORRECT_IMPORTED' => 'Aktív adatbázisban', | ||||
| ]; | ]; | ||||
| } | } |
| } | } | ||||
| $product->setCalculation($calculation); | $product->setCalculation($calculation); | ||||
| $product->setCorrectStatus(Status::UJ); | |||||
| $product->calculatePrices(); | $product->calculatePrices(); | ||||
| $product->setCorrectStatus(Status::UJ); | |||||
| $product = $this->getProductFactory()->save($product); | |||||
| \Drupal::messenger()->addStatus('Sikeres mentés!'); | \Drupal::messenger()->addStatus('Sikeres mentés!'); | ||||
| $result['products'][0] = $product; | |||||
| // /{id}/{page}/{correctStatus}/{keyWords}/{listed}/{cikkszam}/{source}/{mid}/{fid} | // /{id}/{page}/{correctStatus}/{keyWords}/{listed}/{cikkszam}/{source}/{mid}/{fid} | ||||
| $params = [ | $params = [ |
| $values = $form_state->getValues(); | $values = $form_state->getValues(); | ||||
| $product = $this->getProductFactory()->find($values['id']); | $product = $this->getProductFactory()->find($values['id']); | ||||
| $previousProductState = $product; | |||||
| $previousPrice = $product->getPrice(); | |||||
| $product->setName($values['name']); | $product->setName($values['name']); | ||||
| $product->setfabricName($values['fabric_name'] ? $values['fabric_name'] : $values['name']); | $product->setfabricName($values['fabric_name'] ? $values['fabric_name'] : $values['name']); | ||||
| $product->setAxicoName($values['axico_name'] ? $values['axico_name'] : $values['name']); | $product->setAxicoName($values['axico_name'] ? $values['axico_name'] : $values['name']); | ||||
| $product->setListed($values['listable']); | $product->setListed($values['listable']); | ||||
| $product->setPriceDevDTwo($values['price_dev_d_two'] ? $values['price_dev_d_two'] : 0.000); | $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); | $product = $this->getProductFactory()->save($product); | ||||
| $this->getCacheService()->resetCache([$this->getFormId(), $this->source, $product->getId()]); | $this->getCacheService()->resetCache([$this->getFormId(), $this->source, $product->getId()]); | ||||