Hallo liebe Community,
ich habe mich ein wenig in die Modulerstellung von Oxid eingearbeitet. Ich habe einen Artikel den man via Generator modifizieren kann (Aufklebegenerator). Die Daten die der Kunde ausgewählt hat, werden dann als Parameter an den Server übermittelt, sobald der Kunde kaufen klickt.
Da der Preis und der Name des Produktes sich aber nach der Auswahl des Nutzers richten (Größe und Farbe des Aufklebers kann variieren), bin ich auf die Idee gekommen für jeden Artikel den der Kunde sich erstellt eine individuelle Variante zu erstellen, sobald der Kunde auf “In den Warenkorb” klickt.
Ich habe mir dazu die Klasse oxcmp_basket angeschaut und in meinem Modul diese Klasse erweitert.
Anstatt des ursprünglichen Artikels wird eine neue Variante des Aufkleberartikels erstellt (ist momentan eine hart eincodierte ID) und in den Warenkorb gelegt, sobald der Kunde auf “In den Warenkorb” klickt.
Jetzt mein Problem:
Für die 1. Variante meines Artikels läuft alles super. Die Variante wird erstellt und anstelle des ursprünglichen Artikels in den Warenkorb gepackt. Erstelle ich eine zweite Aufklebervariante, dann bekomme ich die Fehlermeldung: “Artikel ist nicht kaufbar”.
Auch in Backend sind meine Artikelvarianten alle aufgelistet. Die 1. Variante ist kaufbar, bei der zweiten steht: “Achtung: Vaterartikel kann nicht gekauft werden.”
Ich habe schon probiert die Varianten für meinen Artikel per Hand einzupflegen - dann kann ich alle erstellten Varianten kaufen.
Warum ist das so? Was mache ich falsch beim Erstellen der Varianten?
Hier meine Klasse:
<?php
/*
Modul description
*/
class add_to_basket extends add_to_basket_parent
{
public $aRedirectParams = array('cnid', // category id
'mnid', // manufacturer id
'anid', // active article id
'tpl', // spec. template
'listtype', // list type
'searchcnid', // search category
'searchvendor', // search vendor
'searchmanufacturer', // search manufacturer
// @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
'searchtag', // search tag
// END deprecated
// @deprecated since v5.3 (2016-06-17); Listmania will be moved to an own module.
'searchrecomm', // search recomendation
'recommid', // recomm. list id
'variantDesc',
'artNum' // END deprecated
);
public function tobasket($sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = false)
{
$myPersText = "";
$myPersArtNum = "";
// setting redirect parameters
foreach ($this->aRedirectParams as $sParamName) {
$sParamVal = oxRegistry::getConfig()->getRequestParameter($sParamName);
if($sParamName == "variantDesc"){
$myPersText = $sParamVal;
} else if($sParamName == "artNum"){
$myPersArtNum = $sParamVal;
}
}
//Problem: First added article variant is buyable, second isn't
//What the hell?
//Idea: There is a problem creating the variants
return parent::tobasket($this->onClickOrder("6fdb8c3a7bd3c280d2ee3706652243a8", $myPersText, $myPersArtNum), $dAmount, $aSel, $aPersParam, $blOverride);
}
//This is an super awesome functions which allows to save new article variant
//Here we have to save a new variant for each text the user generates
public function savevariant($aParams)
{
//Declare a new article and assign the given params $aParams
$oArticle = oxNew("oxarticle");
$oArticle->assign($aParams);
$oArticle->resetRemindStatus();
if ($oParent = $this->_getProductParent($oArticle->oxarticles__oxparentid->value)) {
// assign field from parent for new variant
// #4406
$oArticle->oxarticles__oxisconfigurable = new oxField($oParent->oxarticles__oxisconfigurable->value);
$oArticle->oxarticles__oxremindactive = new oxField($oParent->oxarticles__oxremindactive->value);
}
$oArticle->save();
return $oArticle->oxarticles__oxid;
}
protected function _getProductParent($sParentId)
{
if ($this->_oProductParent === null ||
($this->_oProductParent !== false && $this->_oProductParent->getId() != $sParentId)
) {
$this->_oProductParent = false;
$oProduct = oxNew("oxarticle");
if ($oProduct->load($sParentId)) {
$this->_oProductParent = $oProduct;
}
}
return $this->_oProductParent;
}
public function onClickOrder($oxid, $info, $artNum){
//TODO: Calculate the price depending on parsed values
$price = "100.0";
//Creates new variant with given params
return $this->savevariant(array( "oxarticles__oxvarselect" => $info, "oxarticles__oxartnum" => $artNum, "oxarticles__oxprice" => $price, "oxarticles__oxsort" => "90030", "oxarticles__oxstock" => "100", "oxarticles__oxstockflag" => "1", "oxarticles__oxshopid" => "oxbaseshop", "oxarticles__oxparentid" => $oxid, "oxarticles__oxactive" => "1"));
}
}
?>