Skip to content

Commit

Permalink
Merge pull request #30 from lizardmedia/enterprise-compatibility-patch
Browse files Browse the repository at this point in the history
Enterprise compatibility fix
  • Loading branch information
Bartosz Kubicki authored May 7, 2020
2 parents 4b1d001 + 65e195d commit aab577d
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 182 deletions.
59 changes: 24 additions & 35 deletions Block/Customer/Account/AttachmentList.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

namespace LizardMedia\ProductAttachment\Block\Customer\Account;

use \LizardMedia\ProductAttachment\Api\Data\AttachmentInterface;
use \LizardMedia\ProductAttachment\Api\PurchasedItemsAttachmentProviderInterface;
use \LizardMedia\ProductAttachment\Api\SettingsInterface;
use \LizardMedia\ProductAttachment\Model\ResourceModel\Attachment\Collection;
use \Magento\Customer\Helper\Session\CurrentCustomer;
use \Magento\Framework\Message\ManagerInterface;
use \Magento\Framework\View\Element\Template;
use \Magento\Framework\View\Element\Template\Context;
use LizardMedia\ProductAttachment\Api\Data\AttachmentInterface;
use LizardMedia\ProductAttachment\Api\PurchasedItemsAttachmentProviderInterface;
use LizardMedia\ProductAttachment\Api\SettingsInterface;
use LizardMedia\ProductAttachment\Model\ResourceModel\Attachment\Collection;
use Magento\Customer\Helper\Session\CurrentCustomer;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

/**
* Class Attachment
Expand All @@ -31,43 +31,37 @@ class AttachmentList extends Template
*/
private $isCollectionLoaded = false;


/**
* @var \LizardMedia\ProductAttachment\Api\PurchasedItemsAttachmentProviderInterface
* @var PurchasedItemsAttachmentProviderInterface
*/
private $purchasedItemsAttachmentProvider;


/**
* @var \LizardMedia\ProductAttachment\Api\SettingsInterface
* @var SettingsInterface
*/
private $settings;


/**
* @var \LizardMedia\ProductAttachment\Model\ResourceModel\Attachment\Collection
* @var Collection
*/
private $collection;


/**
* @var \Magento\Customer\Helper\Session\CurrentCustomer
* @var CurrentCustomer
*/
private $currentCustomer;


/**
* @var \Magento\Framework\Message\ManagerInterface
* @var ManagerInterface
*/
private $messageManager;


/**
* @param \LizardMedia\ProductAttachment\Api\PurchasedItemsAttachmentProviderInterface $purchasedItemsAttachmentProvider
* @param \LizardMedia\ProductAttachment\Api\SettingsInterface $settings
* @param \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Message\ManagerInterface $messageManager
* @param PurchasedItemsAttachmentProviderInterface $purchasedItemsAttachmentProvider
* @param SettingsInterface $settings
* @param CurrentCustomer $currentCustomer
* @param Context $context
* @param ManagerInterface $messageManager
* @param array $data
*/
public function __construct(
Expand All @@ -85,10 +79,7 @@ public function __construct(
$this->messageManager = $messageManager;
}


/**
* @throws \Exception
*
* @return $this
*/
protected function _prepareLayout()
Expand All @@ -103,9 +94,8 @@ protected function _prepareLayout()
return $this;
}


/**
* @return \LizardMedia\ProductAttachment\Model\ResourceModel\Attachment\Collection
* @return Collection
*/
public function getAttachments() : Collection
{
Expand All @@ -125,7 +115,6 @@ public function getAttachments() : Collection
return $this->collection;
}


/**
* @return string
*/
Expand All @@ -138,18 +127,18 @@ public function getBackUrl() : string
return $this->getUrl('customer/account/');
}


/**
* @param \LizardMedia\ProductAttachment\Api\Data\AttachmentInterface $attachment
*
* @param AttachmentInterface $attachment
* @return string
*/
public function getDownloadUrl(AttachmentInterface $attachment) : string
{
return $this->getUrl('downloadable/download/attachment', ['id' => $attachment->getId(), '_secure' => true]);
return $this->getUrl(
'downloadable/download/attachment',
['id' => $attachment->getId(), '_secure' => true]
);
}


/**
* @return bool
*/
Expand Down
61 changes: 26 additions & 35 deletions Block/Product/AttachmentTab.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

namespace LizardMedia\ProductAttachment\Block\Product;

use \LizardMedia\ProductAttachment\Api\Data\AttachmentInterface;
use \LizardMedia\ProductAttachment\Api\AttachmentRepositoryInterface;
use \LizardMedia\ProductAttachment\Api\SettingsInterface;
use \LizardMedia\ProductAttachment\Model\Attachment;
use \Magento\Framework\DataObject\IdentityInterface;
use \Magento\Framework\View\Element\Template;
use \Magento\Framework\View\Element\Template\Context;
use \Magento\Framework\Registry;
use LizardMedia\ProductAttachment\Api\AttachmentRepositoryInterface;
use LizardMedia\ProductAttachment\Api\Data\AttachmentInterface;
use LizardMedia\ProductAttachment\Api\SettingsInterface;
use LizardMedia\ProductAttachment\Model\Attachment;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\DataObject\IdentityInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;

/**
* Class Attachments
Expand All @@ -27,28 +28,25 @@
class AttachmentTab extends Template implements IdentityInterface
{
/**
* @var \LizardMedia\ProductAttachment\Api\AttachmentRepositoryInterface
* @var AttachmentRepositoryInterface
*/
private $attachmentRepository;


/**
* @var \LizardMedia\ProductAttachment\Api\SettingsInterface
* @var SettingsInterface
*/
private $settings;


/**
* @var \Magento\Framework\Registry
* @var Registry
*/
private $registry;


/**
* @param \LizardMedia\ProductAttachment\Api\AttachmentRepositoryInterface $attachmentRepository
* @param \LizardMedia\ProductAttachment\Api\SettingsInterface $settings
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Registry $registry
* @param AttachmentRepositoryInterface $attachmentRepository
* @param SettingsInterface $settings
* @param Context $context
* @param Registry $registry
* @param array $data
*/
public function __construct(
Expand All @@ -59,18 +57,13 @@ public function __construct(
array $data = []
) {
parent::__construct($context, $data);

$this->attachmentRepository = $attachmentRepository;
$this->settings = $settings;
$this->registry = $registry;
}


/**
* In case of poor performance (not noticed so far) it can be delegated to
* ajax controller, to load it later, when tab is clicked and selected.
*
* @return \LizardMedia\ProductAttachment\Api\Data\AttachmentInterface[]
* @return AttachmentInterface[]
*/
public function getAttachments() : array
{
Expand All @@ -81,40 +74,38 @@ public function getAttachments() : array
return [];
}


/**
* @return \Magento\Catalog\Api\Data\ProductInterface
* @return ProductInterface
*/
private function getProduct()
{
return $this->registry->registry('current_product');
}


/**
* @param \LizardMedia\ProductAttachment\Api\Data\AttachmentInterface $attachment
*
* @param AttachmentInterface $attachment
* @return string
*/
public function getDownloadUrl(AttachmentInterface $attachment) : string
public function getDownloadUrl(AttachmentInterface $attachment): string
{
return $this->getUrl('downloadable/download/attachment', ['id' => $attachment->getId(), '_secure' => true]);
return $this->getUrl(
'downloadable/download/attachment',
['id' => $attachment->getId(), '_secure' => true]
);
}


/**
* @return bool
*/
public function getIsOpenInNewWindow() : bool
public function getIsOpenInNewWindow(): bool
{
return $this->settings->areLinksOpenedInNewWindow();
}


/**
* @return array
*/
public function getIdentities() : array
public function getIdentities(): array
{
return [Attachment::CACHE_TAG];
}
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
* fix for adminthtml routes.xml

### 1.3.2 ###
* fix for incorrect admin controller paths
* fix for incorrect admin controller paths

### 1.3.3 ###
* enterprise magento version compatibility patch
* minor refactor
8 changes: 4 additions & 4 deletions Helper/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(Context $context)
* @param string $scope
* @return string
*/
public function getAttachmentDefaultTitle($scope = ScopeInterface::SCOPE_STORE) : string
public function getAttachmentDefaultTitle($scope = ScopeInterface::SCOPE_STORE): string
{
return $this->scopeConfig->getValue(self::PRODUCT_ATTACHMENT_DEFAULT_TITLE_XML_PATH);
}
Expand All @@ -57,16 +57,16 @@ public function getAttachmentDefaultTitle($scope = ScopeInterface::SCOPE_STORE)
* @param string $scope
* @return bool
*/
public function areLinksOpenedInNewWindow($scope = ScopeInterface::SCOPE_STORE) : bool
public function areLinksOpenedInNewWindow($scope = ScopeInterface::SCOPE_STORE): bool
{
return (bool) $this->scopeConfig->getValue(self::PRODUCT_ATTACHMENT_OPEN_IN_NEW_WINDOW_XML_PATH);
return (bool) $this->scopeConfig->isSetFlag(self::PRODUCT_ATTACHMENT_OPEN_IN_NEW_WINDOW_XML_PATH);
}

/**
* @param string $scope
* @return string
*/
public function getContentDisposition($scope = ScopeInterface::SCOPE_STORE) : string
public function getContentDisposition($scope = ScopeInterface::SCOPE_STORE): string
{
return $this->scopeConfig->getValue(self::PRODUCT_ATTACHMENT_USE_CONTENT_DISPOSITION_XML_PATH);
}
Expand Down
61 changes: 61 additions & 0 deletions Helper/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types = 1);

/**
* File: Version.php
*
* @author Bartosz Kubicki [email protected]>
* @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
*/

namespace LizardMedia\ProductAttachment\Helper;

use Exception;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\App\ProductMetadata;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\EntityManager\MetadataPool;

/**
* Various Helper
* @package LizardMedia\ProductAttachment\Helper
*/
class Version
{
/**
* @var ProductMetadataInterface
*/
private $productMetadata;

/**
* @var MetadataPool
*/
private $metadataPool;

/**
* @param ProductMetadataInterface $productMetadata
* @param MetadataPool $metadataPool
*/
public function __construct(
ProductMetadataInterface $productMetadata,
MetadataPool $metadataPool
) {
$this->productMetadata = $productMetadata;
$this->metadataPool = $metadataPool;
}

/**
* @return string
* @throws Exception
*/
public function getLinkFieldValue(): string
{
return (
$this->productMetadata->getEdition() !== ProductMetadata::EDITION_NAME
&& version_compare($this->productMetadata->getVersion(), '2.1.0', '>=')
)
? 'entity_id'
: $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
}
}
Loading

0 comments on commit aab577d

Please sign in to comment.