Exemple #1
0
 /**
  * Retrieve layout updates by handle
  *
  * @param string $handle
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @param \Magento\Framework\App\ScopeInterface $store
  * @return string
  */
 public function fetchUpdatesByHandle($handle, \Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Framework\App\ScopeInterface $store)
 {
     $bind = ['layout_update_handle' => $handle, 'theme_id' => $theme->getId(), 'store_id' => $store->getId()];
     $result = '';
     $connection = $this->getConnection();
     if ($connection) {
         $select = $this->_getFetchUpdatesByHandleSelect();
         $result = join('', $connection->fetchCol($select, $bind));
     }
     return $result;
 }
 public function testBuildDimensionWithDefaultScope()
 {
     $name = 'scope';
     $value = \Magento\Framework\App\ScopeInterface::SCOPE_DEFAULT;
     $scopeId = -123456;
     $this->dimension->expects($this->once())->method('getName')->will($this->returnValue($name));
     $this->dimension->expects($this->once())->method('getValue')->will($this->returnValue($value));
     $this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId));
     $this->scopeResolver->expects($this->once())->method('getScope')->with($value)->will($this->returnValue($this->scope));
     $query = $this->builder->build($this->dimension);
     $this->assertEquals(sprintf('`%s` = `%s`', \Magento\Framework\Search\Adapter\Mysql\Dimensions::STORE_FIELD_NAME, $scopeId), $query);
 }
Exemple #3
0
 /**
  * Retrieve layout updates by handle
  *
  * @param string $handle
  * @param \Magento\Framework\View\Design\ThemeInterface $theme
  * @param \Magento\Framework\App\ScopeInterface $store
  * @return string
  */
 public function fetchUpdatesByHandle($handle, \Magento\Framework\View\Design\ThemeInterface $theme, \Magento\Framework\App\ScopeInterface $store)
 {
     $bind = ['theme_id' => $theme->getId(), 'store_id' => $store->getId()];
     $cacheKey = implode('-', $bind);
     if (!isset($this->layoutUpdateCache[$cacheKey])) {
         $this->layoutUpdateCache[$cacheKey] = [];
         foreach ($this->getConnection()->fetchAll($this->_getFetchUpdatesByHandleSelect(), $bind) as $layout) {
             if (!isset($this->layoutUpdateCache[$cacheKey][$layout['handle']])) {
                 $this->layoutUpdateCache[$cacheKey][$layout['handle']] = '';
             }
             $this->layoutUpdateCache[$cacheKey][$layout['handle']] .= $layout['xml'];
         }
     }
     return isset($this->layoutUpdateCache[$cacheKey][$handle]) ? $this->layoutUpdateCache[$cacheKey][$handle] : '';
 }
Exemple #4
0
 /**
  * Round price considering delta
  *
  * @param float $price
  * @param bool $negative Indicates if we perform addition (true) or subtraction (false) of rounded value
  * @return float
  */
 public function deltaRound($price, $negative = false)
 {
     $roundedPrice = $price;
     if ($roundedPrice) {
         if ($negative) {
             $this->_delta = -$this->_delta;
         }
         $price += $this->_delta;
         $roundedPrice = $this->_scope->roundPrice($price);
         $this->_delta = $price - $roundedPrice;
         if ($negative) {
             $this->_delta = -$this->_delta;
         }
     }
     return $roundedPrice;
 }
 /**
  * Check is possible to get all categories for all store starting from top level root category
  */
 public function testGetTreeForAllScope()
 {
     $rootCategoryId = null;
     $depth = null;
     $category = null;
     $categoriesMock = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Category\\Collection', [], [], '', false);
     $categoryMock = $this->getMock('\\Magento\\Catalog\\Model\\Category', [], [], 'categoryMock', false);
     $categoriesMock->expects($this->once())->method('getFirstItem')->willReturn($categoryMock);
     $categoriesMock->expects($this->once())->method('addFilter')->with('level', ['eq' => 0])->willReturnSelf();
     $this->categoriesFactoryMock->expects($this->once())->method('create')->willReturn($categoriesMock);
     $nodeMock = $this->getMock('\\Magento\\Framework\\Data\\Tree\\Node', [], [], '', false);
     $this->categoryTreeMock->expects($this->once())->method('getTree')->with($nodeMock, $depth);
     $this->categoryRepositoryMock->expects($this->never())->method('get');
     $this->categoryTreeMock->expects($this->once())->method('getRootNode')->with($categoryMock)->willReturn($nodeMock);
     $this->scopeResolverMock->expects($this->once())->method('getScope')->willReturn($this->scopeMock);
     $this->scopeMock->expects($this->once())->method('getCode')->willReturn(\Magento\Store\Model\Store::ADMIN_CODE);
     $this->model->getTree();
 }
 public function testBuildWithoutOutOfStock()
 {
     $scopeId = '113';
     $tableSuffix = 'scope113_someNamesomeValue';
     $index = 'test_index_name';
     $dimensions = [$this->createDimension('scope', $scopeId), $this->createDimension('someName', 'someValue')];
     $this->request->expects($this->exactly(2))->method('getDimensions')->willReturn($dimensions);
     $this->dimensionScopeResolver->expects($this->once())->method('getScope')->willReturn($this->scopeInterface);
     $this->scopeInterface->expects($this->once())->method('getId')->willReturn('someValue');
     $this->mockBuild($index, $tableSuffix, false);
     $this->stockConfiguration->expects($this->once())->method('getDefaultScopeId')->willReturn(1);
     $this->config->expects($this->once())->method('isSetFlag')->with('cataloginventory/options/show_out_of_stock')->will($this->returnValue(false));
     $this->connection->expects($this->once())->method('quoteInto')->with(' AND stock_index.website_id = ?', 1)->willReturn(' AND stock_index.website_id = 1');
     $this->select->expects($this->at(2))->method('where')->with('(someName=someValue)')->willReturnSelf();
     $this->select->expects($this->at(3))->method('joinLeft')->with(['stock_index' => 'cataloginventory_stock_status'], 'search_index.entity_id = stock_index.product_id' . ' AND stock_index.website_id = 1', [])->willReturnSelf();
     $this->select->expects($this->at(4))->method('where')->with('stock_index.stock_status = ?', 1)->will($this->returnSelf());
     $result = $this->target->build($this->request);
     $this->assertSame($this->select, $result);
 }
 public function testProcessNotStaticAttribute()
 {
     $expectedResult = 'search_index.entity_id IN (select entity_id from (TEST QUERY PART) as filter)';
     $scopeId = 0;
     $isNegation = false;
     $query = 'SELECT field FROM table';
     $attributeId = 1234567;
     $this->scope->expects($this->once())->method('getId')->will($this->returnValue($scopeId));
     $this->filter->expects($this->exactly(4))->method('getField')->will($this->returnValue('not_static_attribute'));
     $this->config->expects($this->exactly(1))->method('getAttribute')->with(\Magento\Catalog\Model\Product::ENTITY, 'not_static_attribute')->will($this->returnValue($this->attribute));
     $this->attribute->expects($this->once())->method('isStatic')->will($this->returnValue(false));
     $this->attribute->expects($this->once())->method('getBackendTable')->will($this->returnValue('backend_table'));
     $this->attribute->expects($this->once())->method('getAttributeId')->will($this->returnValue($attributeId));
     $this->connection->expects($this->once())->method('getIfNullSql')->with('current_store.value', 'main_table.value')->will($this->returnValue('IF NULL SQL'));
     $this->select->expects($this->once())->method('from')->with(['main_table' => 'backend_table'], 'entity_id')->will($this->returnSelf());
     $this->select->expects($this->once())->method('joinLeft')->with(['current_store' => 'backend_table'])->will($this->returnSelf());
     $this->select->expects($this->once())->method('columns')->with(['not_static_attribute' => 'IF NULL SQL'])->will($this->returnSelf());
     $this->select->expects($this->exactly(2))->method('where')->will($this->returnSelf());
     $this->select->expects($this->once())->method('__toString')->will($this->returnValue('TEST QUERY PART'));
     $actualResult = $this->target->process($this->filter, $isNegation, $query);
     $this->assertSame($expectedResult, $this->removeWhitespaces($actualResult));
 }
Exemple #8
0
/**
 * @uses \Magento\Framework\App\Config\Data::getValue()
 * https://github.com/magento/magento2/blob/2335247d4ae2dc1e0728ee73022b0a244ccd7f4c/lib/internal/Magento/Framework/App/Config/Data.php#L47-L62
 *
 * 2015-12-26
 * https://mage2.pro/t/357
 * «The @uses \Magento\Framework\App\Config::getValue() method
 * has a wrong PHPDoc type for the $scopeCode parameter».
 *
 * Метод возвращает null или $default, если данные отсутствуют:
 * @see \Magento\Framework\App\Config\Data::getValue()
 * https://github.com/magento/magento2/blob/6ce74b2/lib/internal/Magento/Framework/App/Config/Data.php#L47-L62
 *
 * 2015-10-09
 * https://mage2.pro/t/128
 * https://github.com/magento/magento2/issues/2064
 *
 * @param string $key
 * @param null|string|int|ScopeA|Store|IConfigData|ConfigData $scope [optional]
 * @param mixed|callable $default [optional]
 * @return array|string|null|mixed
 */
function df_cfg($key, $scope = null, $default = null)
{
    /** @var array|string|null|mixed $result */
    $result = $scope instanceof IConfigData ? $scope->getValue($key) : df_cfg_m()->getValue($key, ScopeS::SCOPE_STORE, $scope);
    return df_if(df_cfg_empty($result), $default, $result);
}