Hallo,
ich programmiere gerade eine Erweiterung mit der man sich Dokumente in einen Warenkorb packen kann und dann zusenden lassen kann.
Ich habe ein Warenkorbobjekt und ein Dokument im Kickstarter angelegt. Mit einer 1:n Verknüpfung Warenkorb zum Wissensdokument unter dokumente.
Der Kickstarter hat folgendes erstellt
TCA:
'dokumente' => array(
'exclude' => 1,
'label' => 'LLL:EXT:warenkorb/Resources/Private/Language/locallang_db.xlf:tx_warenkorb_domain_model_warenkorb.dokumente',
'config' => array(
'type' => 'inline',
'foreign_table' => 'tx_warenkorb_domain_model_wissensdokument',
'foreign_field' => 'warenkorb',
'maxitems' => 9999,
'appearance' => array(
'collapseAll' => 0,
'levelLinksPosition' => 'top',
'showSynchronizationLink' => 1,
'showPossibleLocalizationRecords' => 1,
'showAllLocalizationLink' => 1
),
),
),
und in der Warenkorb Klasse
/**
* dokumente
*
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Sutor\Warenkorb\Domain\Mode \WissensDokument>
* @cascade remove
* @lazy
*/
protected $dokumente = NULL;
In der Warenkorb Klasse habe ich jetzt zum entfernen eines Dokumentes erst diese Methode angelegt.
/**
* WissensDokument aus dem Warenkorb entfernen
*
* @param \Sutor\Warenkorb\Domain\Model\WissensDokument $dokumenteToRemove
* @return void
*/
public function removeDokument(\Sutor\Warenkorb\Domain\Model\WissensDokument $dokumentToRemove) {
$this->dokumente->detach($dokument);
}
Funktioniert aber nicht, da das Objekt $dokumentToRemove neu erstellt wird und nicht das Gleiche ist wie im Objectstorage $this->$dokumente.
Annschließend habe ich es so versucht
public function removeDokument(\Sutor\Warenkorb\Domain\Model\WissensDokument $dokumentToRemove) {
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->getDokumente());
foreach ($this->getDokumente() as $dokument){
if ($dokument->getUid() === $dokumentToRemove->getUid()) {
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(spl_object_hash($dokument));
$this->dokumente->detach($dokument);
}
}
die();
}
Die Debugging ausgabe wenn ich das Dukoment1 löschen will ist für
$this->getDokumente()
TYPO3\CMS\Extbase\Persistence\ObjectStorageprototypemodified object (2 items)
0000000004b8b7d100000000231c17a6 => Sutor\..prototypepersistent entity (uid=1, pid=296)
000000004f770b92000000003c96eeb4 => Sutor\..tprototypepersistent entity (uid=2, pid=296)
und für den Obeject Hash für $dokument
'0000000020853b890000000050bb6d6d' (32 chars)
Also auch hier wieder verschiedene Objekte. Das verstehe ich nicht so ganz. Es könnte daran liegen das der Warenkorb in einer Session gespeichert wird.
Als drittes habe ich dann folgender versucht
public function removeDokument(\Sutor\Warenkorb\Domain\Model\WissensDokument $dokumentToRemove) {
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->getDokumente());
foreach ($this->getDokumente() as $objectHash => $dokument){
if ($dokument->getUid() === $dokumentToRemove->getUid()) {
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($objectHash);
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->dokumente[$objectHash]);
unset($this->dokumente[$objectHash]);
}
}
}
Die Debuggingausgabe wenn ich das Dukoment1 löschen will ist für
$this->getDokumente()
TYPO3\CMS\Extbase\Persistence\ObjectStorageprototypemodified object (2 items)
0000000004b8b7d100000000231c17a6 => Sutor\..prototypepersistent entity (uid=1, pid=296)
000000004f770b92000000003c96eeb4 => Sutor\..tprototypepersistent entity (uid=2, pid=296)
und für den Obeject Hash für $dokument
'0000000004b8b7d100000000231c17a6' (32 chars)
Aber für $this->dokumente[$objectHash] kommt null
An dieser Stelle verstehe ich jetzt gar nix mehr. Kann ich noch nicht gut genug PHP ?
Frage ist
Was mache ich falsch ?
oder
Bin ich überhaupt auf dem richtigen Weg?
Gibt es evt. einen Link für Beispiel? Es ja nichts außergewöhnliches. ( Ich habe gegooglt aber nichts gefunden )
Vielen Dank
Martin

