예제 #1
0
 /**
  * Test get sql active snippet if parent will be loaded on special its variants setup.
  *
  * @return null
  */
 public function testGetSqlActiveSnippetIfParentWillBeLoadedOnSpecialItsVariantsSetup()
 {
     $sArticleId = '_testArticleId';
     $sShopId = $this->getConfig()->getShopId();
     $oArticle = oxNew('oxArticle');
     $sTable = $oArticle->getViewName();
     $oDb = oxDb::getdb();
     $this->getConfig()->setConfigParam("blUseTimeCheck", 0);
     $this->getConfig()->setConfigParam("blUseStock", 0);
     $this->getConfig()->setConfigParam("blVariantParentBuyable", 0);
     // just some inactive article
     $oArticle = oxNew('oxArticle');
     $oArticle->setId($sArticleId);
     $oArticle->oxarticles__oxshopid = new oxField($sShopId);
     $oArticle->oxarticles__oxactive = new oxField(0);
     $oArticle->save();
     $sQ = "select 1 from ({$sTable}) where oxid='{$sArticleId}' and " . $oArticle->getSqlActiveSnippet();
     $this->assertFalse($oDb->getOne($sQ));
     // regular active product
     $oArticle->oxarticles__oxactive = new oxField(1);
     $oArticle->save();
     $sQ = "select 1 from ({$sTable}) where oxid='{$sArticleId}' and " . $oArticle->getSqlActiveSnippet();
     $this->assertEquals("1", $oDb->getOne($sQ));
     $this->getConfig()->setConfigParam("blUseTimeCheck", 1);
     $this->getConfig()->setConfigParam("blUseStock", 0);
     $this->getConfig()->setConfigParam("blVariantParentBuyable", 0);
     $iCurrTime = oxRegistry::get("oxUtilsDate")->getTime();
     // regular active product by time range
     $oArticle->oxarticles__oxactive = new oxField(0);
     $oArticle->oxarticles__oxactivefrom = new oxField(date('Y-m-d H:i:s', $iCurrTime - 3600));
     $oArticle->oxarticles__oxactiveto = new oxField(date('Y-m-d H:i:s', $iCurrTime + 3600));
     $oArticle->save();
     $sQ = "select 1 from ({$sTable}) where oxid='{$sArticleId}' and " . $oArticle->getSqlActiveSnippet();
     $this->assertEquals("1", $oDb->getOne($sQ));
     // stock check is on
     $this->getConfig()->setConfigParam("blUseTimeCheck", 1);
     $this->getConfig()->setConfigParam("blUseStock", 1);
     $this->getConfig()->setConfigParam("blVariantParentBuyable", 0);
     // stock = 0, stock flag = 2
     $oArticle->oxarticles__oxstock = new oxField(0);
     $oArticle->oxarticles__oxstockflag = new oxField(2);
     $oArticle->save();
     $sQ = "select 1 from ({$sTable}) where oxid='{$sArticleId}' and " . $oArticle->getSqlActiveSnippet();
     $this->assertFalse($oDb->getOne($sQ));
     // stock > 0, stock flag = 2
     $oArticle->oxarticles__oxstock = new oxField(1);
     $oArticle->oxarticles__oxstockflag = new oxField(2);
     $oArticle->save();
     $sQ = "select 1 from ({$sTable}) where oxid='{$sArticleId}' and " . $oArticle->getSqlActiveSnippet();
     $this->assertEquals("1", $oDb->getOne($sQ));
     // has 2 active variants, but parent itself is not buyable
     $oVar1 = oxNew('oxArticle');
     $oVar1->setId('_testVariant1');
     $oVar1->oxarticles__oxshopid = new oxField($sShopId);
     $oVar1->oxarticles__oxactive = new oxField(1);
     $oVar1->oxarticles__oxstock = new oxField(1);
     $oVar1->oxarticles__oxparentid = new oxField($oArticle->getId());
     $oVar1->save();
     $oVar2 = oxNew('oxArticle');
     $oVar2->setId('_testVariant2');
     $oVar2->oxarticles__oxshopid = new oxField($sShopId);
     $oVar2->oxarticles__oxactive = new oxField(1);
     $oVar2->oxarticles__oxstock = new oxField(1);
     $oVar2->oxarticles__oxparentid = new oxField($oArticle->getId());
     $oVar2->save();
     $sQ = "select 1 from ({$sTable}) where oxid='{$sArticleId}' and " . $oArticle->getSqlActiveSnippet();
     $this->assertEquals("1", $oDb->getOne($sQ));
     // has no active variants (2 inactive)
     $oVar1->oxarticles__oxactive = new oxField(0);
     $oVar1->save();
     $oVar2->oxarticles__oxactive = new oxField(0);
     $oVar2->save();
     $sQ = "select 1 from ({$sTable}) where oxid='{$sArticleId}' and " . $oArticle->getSqlActiveSnippet();
     $this->assertFalse($oDb->getOne($sQ));
     // has 2 active variants and parent itself is buyable
     $this->getConfig()->setConfigParam("blUseTimeCheck", 1);
     $this->getConfig()->setConfigParam("blUseStock", 1);
     $this->getConfig()->setConfigParam("blVariantParentBuyable", 1);
     $oVar1->oxarticles__oxactive = new oxField(1);
     $oVar1->save();
     $oVar2->oxarticles__oxactive = new oxField(1);
     $oVar2->save();
     $sQ = "select 1 from ({$sTable}) where oxid='{$sArticleId}' and " . $oArticle->getSqlActiveSnippet();
     $this->assertEquals("1", $oDb->getOne($sQ));
     // has no active variants and parent itself is buyable
     $oVar1->oxarticles__oxactive = new oxField(0);
     $oVar1->save();
     $oVar2->oxarticles__oxactive = new oxField(0);
     $oVar2->save();
     $sQ = "select 1 from ({$sTable}) where oxid='{$sArticleId}' and " . $oArticle->getSqlActiveSnippet();
     $this->assertEquals("1", $oDb->getOne($sQ));
 }