Skip to content
This repository has been archived by the owner on Oct 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #127 from EmicoEcommerce/issue/126705-navigator-ba…
Browse files Browse the repository at this point in the history
…se-url

Update tweakwise server url in installer
  • Loading branch information
edwinljacobs authored Sep 30, 2020
2 parents bd3fe54 + 006bef4 commit d33426d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
46 changes: 35 additions & 11 deletions src/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
Expand All @@ -23,16 +24,25 @@ class UpgradeData implements UpgradeDataInterface
/**
* @var EavSetupFactory
*/
private $eavSetupFactory;
protected $eavSetupFactory;

/**
* @var WriterInterface
*/
protected $writer;

/**
* UpgradeData constructor.
*
* @param EavSetupFactory $eavSetupFactory
* @param WriterInterface $writer
*/
public function __construct(EavSetupFactory $eavSetupFactory)
{
public function __construct(
EavSetupFactory $eavSetupFactory,
WriterInterface $writer
) {
$this->eavSetupFactory = $eavSetupFactory;
$this->writer = $writer;
}

/**
Expand All @@ -42,15 +52,21 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
{
$setup->startSetup();

$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$this->ensureCrosssellTemplateAttribute($eavSetup);
$this->ensureUpsellTemplateAttribute($eavSetup);
$this->ensureFeaturedTemplateAttribute($eavSetup);
if (version_compare($context->getVersion(), '2.0.0', '=<')) {
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$this->ensureCrosssellTemplateAttribute($eavSetup);
$this->ensureUpsellTemplateAttribute($eavSetup);
$this->ensureFeaturedTemplateAttribute($eavSetup);
}

if (version_compare($context->getVersion(), '2.0.1', '<=')) {
$this->updateNavigatorBaseUrl();
}

$setup->endSetup();
}

private function ensureCrosssellTemplateAttribute(EavSetup $eavSetup)
protected function ensureCrosssellTemplateAttribute(EavSetup $eavSetup)
{
foreach ([Category::ENTITY, Product::ENTITY] as $entityType) {
$eavSetup->addAttribute($entityType, Config::ATTRIBUTE_CROSSSELL_TEMPLATE, [
Expand All @@ -76,7 +92,7 @@ private function ensureCrosssellTemplateAttribute(EavSetup $eavSetup)
}
}

private function ensureUpsellTemplateAttribute(EavSetup $eavSetup)
protected function ensureUpsellTemplateAttribute(EavSetup $eavSetup)
{
foreach ([Category::ENTITY, Product::ENTITY] as $entityType) {
$eavSetup->addAttribute($entityType, Config::ATTRIBUTE_UPSELL_TEMPLATE, [
Expand All @@ -102,7 +118,7 @@ private function ensureUpsellTemplateAttribute(EavSetup $eavSetup)
}
}

private function ensureFeaturedTemplateAttribute(EavSetup $eavSetup)
protected function ensureFeaturedTemplateAttribute(EavSetup $eavSetup)
{
$eavSetup->addAttribute(Category::ENTITY, Config::ATTRIBUTE_FEATURED_TEMPLATE, [
'type' => 'int',
Expand All @@ -115,4 +131,12 @@ private function ensureFeaturedTemplateAttribute(EavSetup $eavSetup)
'source' => 'Emico\Tweakwise\Model\Config\Source\RecommendationOption\Featured',
]);
}
}

/**
* Update tw server url as the old url will be retired
*/
protected function updateNavigatorBaseUrl()
{
$this->writer->save('tweakwise/general/server_url', 'https://gateway.tweakwisenavigator.com/');
}
}
2 changes: 1 addition & 1 deletion src/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Emico_Tweakwise" setup_version="2.0.0">
<module name="Emico_Tweakwise" setup_version="2.0.1">
<sequence>
<module name="Magento_CatalogSearch"/>
<module name="Magento_Search"/>
Expand Down

0 comments on commit d33426d

Please sign in to comment.