This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,24 @@
<?php
namespace Stemcell\Catalog\Block\Adminhtml\Price\Import;
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class BackButton extends GenericButton implements ButtonProviderInterface
{
public function getButtonData()
{
return [
'label' => __('返回'),
'class' => 'save primary',
'on_click' => sprintf("location.href = '%s';", $this->getSampleUrl()),
'sort_order' => 90,
];
}
protected function getSampleUrl()
{
return $this->getUrl('stemcell_catalog/price/index');
}
}
@@ -0,0 +1,24 @@
<?php
namespace Stemcell\Catalog\Block\Adminhtml\Price\Import;
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class SampleButton extends GenericButton implements ButtonProviderInterface
{
public function getButtonData()
{
return [
'label' => __('下载模版文件'),
'class' => 'save primary',
'on_click' => sprintf("location.href = '%s';", $this->getSampleUrl()),
'sort_order' => 90,
];
}
protected function getSampleUrl()
{
return $this->getUrl('stemcell_catalog/price/sample');
}
}
@@ -0,0 +1,24 @@
<?php
namespace Stemcell\Catalog\Block\Adminhtml\Stock;
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class BackButton extends GenericButton implements ButtonProviderInterface
{
public function getButtonData()
{
return [
'label' => __('返回'),
'class' => 'save primary',
'on_click' => sprintf("location.href = '%s';", $this->getSampleUrl()),
'sort_order' => 90,
];
}
protected function getSampleUrl()
{
return $this->getUrl('stemcell_catalog/stock/index');
}
}
@@ -0,0 +1,8 @@
<?php
namespace Stemcell\Catalog\Block\Adminhtml\Stock;
class Import extends \Magento\Backend\Block\Template
{
}
@@ -0,0 +1,24 @@
<?php
namespace Stemcell\Catalog\Block\Adminhtml\Stock;
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class SampleButton extends GenericButton implements ButtonProviderInterface
{
public function getButtonData()
{
return [
'label' => __('下载模版文件'),
'class' => 'save primary',
'on_click' => sprintf("location.href = '%s';", $this->getSampleUrl()),
'sort_order' => 90,
];
}
protected function getSampleUrl()
{
return $this->getUrl('stemcell_catalog/stock/sample');
}
}
@@ -0,0 +1,27 @@
<?php
namespace Stemcell\Catalog\Block\Adminhtml\Stock;
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
class SaveButton extends GenericButton implements ButtonProviderInterface
{
public function getButtonData()
{
return [
'label' => __('导入'),
'class' => 'save primary',
'data_attribute' => [
'mage-init' => ['button' => ['event' => 'save']],
'form-role' => 'save',
],
'sort_order' => 90,
];
}
public function getUrl($route = '', $params = [])
{
return $this->urlBuilder->getUrl('stemcell_catalog/stock/importPost');
}
}
@@ -0,0 +1,45 @@
<?php
namespace Stemcell\Catalog\Block\Pricing\Render;
use Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface;
use Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface;
use Magento\Framework\Pricing\Price\PriceInterface;
use Magento\Framework\Pricing\Render\RendererPool;
use Magento\Framework\Pricing\SaleableInterface;
use Magento\Framework\View\Element\Template\Context;
use Stemcell\Catalog\Helper\Product\View;
class FinalPriceBox extends \Magento\Catalog\Pricing\Render\FinalPriceBox
{
public function __construct(
Context $context,
SaleableInterface $saleableItem,
PriceInterface $price,
RendererPool $rendererPool,
protected View $productViewHelper,
array $data = [],
SalableResolverInterface $salableResolver = null,
MinimalPriceCalculatorInterface $minimalPriceCalculator = null
) {
parent::__construct(
$context,
$saleableItem,
$price,
$rendererPool,
$data,
$salableResolver,
$minimalPriceCalculator
);
}
protected function _toHtml()
{
if ($this->productViewHelper->notStockCheckGroup()) {
return parent::_toHtml();
}
return '';
}
}
@@ -0,0 +1,89 @@
<?php
namespace Stemcell\Catalog\Block\Product;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product\Type;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Stemcell\SubItemProduct\Model\ResourceModel\SubItem\CollectionFactory;
use Stemcell\SubItemProduct\Model\SubItem as SubItemModel;
use Stemcell\Catalog\Helper\Product\View as ProductViewHelper;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableProductType;
class View extends \Magento\Catalog\Block\Product\View
{
const NOT_FOR_SELL_SKU_PATH = 'catalog/product_settings/not_for_sell';
const NO_PRICE_SKU_PATH = 'catalog/product_settings/no_price_sku';
const WENJUANXING_ENQUIRY_URL = 'stemcell_web/wenjuanxing/enquiry_url';
const STOCK_CHECK_GROUP_PATH = 'stemcell_web/catalog/stock_check_group';
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Framework\Url\EncoderInterface $urlEncoder,
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
\Magento\Framework\Stdlib\StringUtils $string,
\Magento\Catalog\Helper\Product $productHelper,
\Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig,
\Magento\Framework\Locale\FormatInterface $localeFormat,
\Magento\Customer\Model\Session $customerSession,
ProductRepositoryInterface $productRepository,
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
private ScopeConfigInterface $scopeConfig,
protected ProductViewHelper $productViewHelper,
array $data = []
) {
parent::__construct(
$context, $urlEncoder, $jsonEncoder, $string, $productHelper, $productTypeConfig,
$localeFormat, $customerSession, $productRepository, $priceCurrency, $data
);
}
public function showEnquiry(ProductInterface $product)
{
$notSellSkus = [];
if ($product->getTypeId() == Type::TYPE_SIMPLE && $product->getPrice()==0) {
$notSellSkus[] = $product->getSku();
}
if ($product->getTypeId() == ConfigurableProductType::TYPE_CODE) {
$childProducts = $product->getTypeInstance()->getUsedProducts($product);
foreach ($childProducts as $child) {
if ($child->getPrice() == 0) {
$notSellSkus[] = $child->getSku();
}
}
}
return !empty($notSellSkus);
}
public function isConfigurable(ProductInterface $product)
{
return $product->getTypeId() == ConfigurableProductType::TYPE_CODE;
}
/**
* 根据大货号(简单产品或可配置产品的子产品)的的库存计算出产品的库存量
* @return int
*/
public function getStockFromSubItems(ProductInterface $product){
return $this->productViewHelper->getStockFromSubItems($product);
}
public function getWenjuanxingEnquiryUrl(){
$url = (string)$this->scopeConfig->getValue(self::WENJUANXING_ENQUIRY_URL);
return trim($url);
}
public function notStockCheckGroup()
{
return $this->productViewHelper->notStockCheckGroup();
}
public function isLoggedIn()
{
return $this->customerSession->isLoggedIn();
}
}
@@ -0,0 +1,133 @@
<?php
namespace Stemcell\Catalog\Block\Product\View;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Helper\Image as ImageHelper;
use Magento\Catalog\Model\ProductFactory;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
class Publication extends \Magento\Catalog\Block\Product\View
{
private const VISIBLE_PUBLICATION_LIMIT = 3;
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Framework\Url\EncoderInterface $urlEncoder,
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
\Magento\Framework\Stdlib\StringUtils $string,
\Magento\Catalog\Helper\Product $productHelper,
\Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig,
\Magento\Framework\Locale\FormatInterface $localeFormat,
\Magento\Customer\Model\Session $customerSession,
ProductRepositoryInterface $productRepository,
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
protected ProductCollectionFactory $productCollectionFactory,
protected \Magento\Framework\Registry $registry,
protected ProductFactory $productFactory,
protected ImageHelper $imageHelper,
array $data = []
)
{
parent::__construct(
$context,
$urlEncoder,
$jsonEncoder,
$string,
$productHelper,
$productTypeConfig,
$localeFormat,
$customerSession,
$productRepository,
$priceCurrency,
$data
);
}
public function getProducts(): Collection
{
return $this->getPublicationCollection()
->setPageSize(self::VISIBLE_PUBLICATION_LIMIT)
->setCurPage(1);
}
public function getProductsCount(): int
{
return $this->getPublicationCollection()->getSize();
}
private function getPublicationCollection(): Collection
{
$product = $this->getProduct();
$publicationSkus = trim((string)$product->getData('publication_skus'));
$collection = $this->productCollectionFactory->create()
->addAttributeToSelect([
'name',
'sku',
'reference_url',
'reference_abstract',
'author_info',
'reference_journal',
'resource_type',
'reference_year',
'reference_month',
])
->addStoreFilter();
if (!$publicationSkus) {
return $this->getEmptyCollection($collection);
}
$skus = array_values(array_filter(array_map('trim', explode(',', $publicationSkus))));
if (!$skus) {
return $this->getEmptyCollection($collection);
}
return $collection->addAttributeToFilter('sku', ['in' => $skus]);
}
protected function getEmptyCollection(Collection $collection): Collection
{
$collection->addAttributeToFilter('entity_id', ['null' => true]);
return $collection;
}
public function getOptionIdByLabel(
\Magento\Catalog\Model\Product $product,
string $attributeCode,
string $label
): ?int {
$attribute = $product->getResource()->getAttribute($attributeCode);
if (!$attribute || !$attribute->usesSource()) {
return null;
}
$optionId = $attribute->getSource()->getOptionId($label);
return $optionId ? (int)$optionId : null;
}
/**
* @return string
*/
public function getPublicationListUrl()
{
$categoryOptionId = $this->getOptionIdByLabel($this->getProduct(), 'category_option', '文档');
$resourceTypeId = $this->getOptionIdByLabel($this->getProduct(), 'resource_type', '文献');
return $this->getUrl(
'catalogsearch/result/index',
[
'_query' => [
'category_option' => $categoryOptionId,
'resource_type' => $resourceTypeId,
'q' => str_ireplace('_C', '', $this->getProduct()->getSku())
]
]
);
}
}
@@ -0,0 +1,115 @@
<?php
namespace Stemcell\Catalog\Block\Product\View;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Helper\Image as ImageHelper;
use Magento\Catalog\Model\Product;
use Magento\Framework\View\Element\Template;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
use Magento\Catalog\Model\ProductFactory;
class TechnicalResource extends \Magento\Catalog\Block\Product\View
{
public function __construct(
\Magento\Catalog\Block\Product\Context $context,
\Magento\Framework\Url\EncoderInterface $urlEncoder,
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
\Magento\Framework\Stdlib\StringUtils $string,
\Magento\Catalog\Helper\Product $productHelper,
\Magento\Catalog\Model\ProductTypes\ConfigInterface $productTypeConfig,
\Magento\Framework\Locale\FormatInterface $localeFormat,
\Magento\Customer\Model\Session $customerSession,
ProductRepositoryInterface $productRepository,
\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency,
protected ProductCollectionFactory $productCollectionFactory,
protected \Magento\Framework\Registry $registry,
protected ProductFactory $productFactory,
protected ImageHelper $imageHelper,
array $data = []
)
{
parent::__construct(
$context,
$urlEncoder,
$jsonEncoder,
$string,
$productHelper,
$productTypeConfig,
$localeFormat,
$customerSession,
$productRepository,
$priceCurrency,
$data
);
}
public function getCurrentProduct()
{
$product = $this->registry->registry('product');
if (!$product) {
$product = $this->productFactory->create();
}
return $product;
}
protected function getEmptyCollection(Collection $collection): Collection
{
$collection->addAttributeToFilter('entity_id', ['null' => true]);
return $collection;
}
public function getProducts(): Collection
{
$product = $this->getProduct();
$technicalResourceSkus = $product->getData('technical_resource_skus');
$collection = $this->productCollectionFactory->create()
->addAttributeToSelect([
'name',
'sku',
'url_key',
'image',
'small_image',
'thumbnail',
'resource_type',
'form_link',
'document_path',
])
->addStoreFilter();
if (!$technicalResourceSkus) {
return $this->getEmptyCollection($collection);
}
$skus = array_values(array_filter(array_map('trim', explode(',', $technicalResourceSkus))));
if (!$skus) {
return $collection->addIdFilter([]);
}
return $collection->addAttributeToFilter('sku', ['in' => $skus]);
}
public function getTechnicalResourceProductUrl(Product $product)
{
$resourceType = (string)$product->getAttributeText('resource_type');
$resourceType = trim($resourceType);
if (in_array($resourceType, ['挂图','点播课程'])) {
return $product->getData('form_link');
} elseif ($product->getData('document_path')) {
return $product->getData('document_path');
}
return $this->getProductUrl($product);
}
public function getProductImageUrl(Product $product, int $width = 303, int $height = 170): string
{
return $this->imageHelper
->init($product, 'product_base_image')
->resize($width, $height)
->getUrl();
}
}
@@ -0,0 +1,139 @@
<?php
namespace Stemcell\Catalog\Block\Theme\Html;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Data\Tree\Node;
use Magento\Framework\Data\Tree\Node\Collection;
use Magento\Framework\Data\Tree\NodeFactory;
use Magento\Framework\Data\TreeFactory;
use Psr\Log\LoggerInterface;
class Topmenu extends \Magento\Theme\Block\Html\Topmenu
{
/**
* @var NodeFactory
*/
protected $nodeFactory;
/**
* @var TreeFactory
*/
protected $treeFactory;
protected function getChildLevel($parentLevel): int
{
return $parentLevel === null ? 0 : $parentLevel + 1;
}
protected function removeChildrenWithoutActiveParent(Collection $children, int $childLevel): void
{
/** @var Node $child */
foreach ($children as $child) {
if ($childLevel === 0 && $child->getData('is_parent_active') === false) {
$children->delete($child);
}
}
}
protected function setCurrentClass(Node $child, string $outermostClass): void
{
$currentClass = $child->getClass();
if (empty($currentClass)) {
$child->setClass($outermostClass);
} else {
$child->setClass($currentClass . ' ' . $outermostClass);
}
}
/**
* @override
*
* @param array $colBrakes
* @param int $counter
* @return bool
*/
protected function shouldAddNewColumn(array $colBrakes, int $counter): bool
{
return count($colBrakes) && $colBrakes[$counter]['colbrake'];
}
protected function getCategoryUrl(Node $node)
{
// $logger = ObjectManager::getInstance()->get(LoggerInterface::class);
// $logger->info('stemcell $node', ['$node->getData()'=>$node->getData()]);
if ($node->getUrl()) {
$path = parse_url($node->getUrl(), PHP_URL_PATH);
if (ltrim($path, '/') === 'products.html') {
return '/products/product-types.html';
}
}
return $node->getUrl();
}
/**
* @override
*
* @param Node $menuTree
* @param string $childrenWrapClass
* @param int $limit
* @param array $colBrakes
* @return string
*/
protected function _getHtml(
Node $menuTree,
$childrenWrapClass,
$limit,
array $colBrakes = []
) {
$html = '';
$children = $menuTree->getChildren();
$childLevel = $this->getChildLevel($menuTree->getLevel());
$this->removeChildrenWithoutActiveParent($children, $childLevel);
$counter = 1;
$childrenCount = $children->count();
$parentPositionClass = $menuTree->getPositionClass();
$itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';
/** @var Node $child */
foreach ($children as $child) {
$child->setLevel($childLevel);
$child->setIsFirst($counter === 1);
$child->setIsLast($counter === $childrenCount);
$child->setPositionClass($itemPositionClassPrefix . $counter);
$outermostClassCode = '';
$outermostClass = $menuTree->getOutermostClass();
if ($childLevel === 0 && $outermostClass) {
$outermostClassCode = ' class="' . $outermostClass . '" ';
$this->setCurrentClass($child, $outermostClass);
}
if ($this->shouldAddNewColumn($colBrakes, $counter)) {
$html .= '</ul></li><li class="column"><ul>';
}
$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
$html .= '<a href="' . $this->getCategoryUrl($child) . '" ' . $outermostClassCode . '><span>' . $this->escapeHtml(
$child->getName()
) . '</span></a>' . $this->_addSubMenu(
$child,
$childLevel,
$childrenWrapClass,
$limit
) . '</li>';
$counter++;
}
if (is_array($colBrakes) && !empty($colBrakes) && $limit) {
$html = '<li class="column"><ul>' . $html . '</ul></li>';
}
return $html;
}
}