/** * Get registered label for product * * @param \XLite\Model\Product $product Product object * * @return array */ public static function getLabel(\XLite\Model\Product $product) { if (!isset(static::$labels[$product->getProductId()])) { static::$labels[$product->getProductId()] = $product->getFreeShip() ? static::getLabelContent() : ''; } return !empty(static::$labels[$product->getProductId()]) ? static::$labels[$product->getProductId()] : array(); }
protected function checkProductOnList(\XLite\Model\Product $product, $modes, $sale, $type) { $listPrice = $this->formatPrice($product->getListPrice()); foreach ($modes as $mode) { $this->click('css=a.' . $mode); //$this->waitForAjaxProgress(); sleep(1); $this->assertElementPresent("css=.content .items-list .product.productid-" . $product->getProductId(), "Sale product missing, {$mode} mode, {$sale} {$type}"); $this->assertElementPresent("css=.content .items-list .productid-" . $product->getProductId() . " .label-orange.sale-price", "Sale label missing, {$mode} mode, {$sale} {$type}"); $this->assertNotEquals($product->getPrice(), $product->getListPrice(), "Price and list price equals, {$mode} mode, {$sale} {$type}"); $this->assertElementContainsText("css=.content .items-list .product.productid-" . $product->getProductId() . " .product-price", $listPrice, "Price shown without sale, {$mode} mode, {$sale} {$type}"); } }
/** * Import 'relatedProducts' value * * @param \XLite\Model\Product $model Product * @param array $value Value (array of related products SKUs) * @param array $column Column info * * @return void */ protected function importRelatedProductsColumn(\XLite\Model\Product $model, array $value, array $column) { $currentRelations = \XLite\Core\Database::getRepo('XLite\\Module\\XC\\Upselling\\Model\\UpsellingProduct')->getUpsellingProducts($model->getProductId()); $relSku = array(); if ($currentRelations) { // Get SKU cache of currently assigned related products // and remove related products which are not in new values list $toDelete = array(); foreach ($currentRelations as $rel) { $relSku[] = $rel->getProduct()->getSku(); if ($rel->getProduct() && !in_array($rel->getProduct()->getSku(), $value)) { $toDelete[] = $rel; } } if ($toDelete) { \XLite\Core\Database::getRepo('XLite\\Module\\XC\\Upselling\\Model\\UpsellingProduct')->deleteInBatch($toDelete); } } if ($value) { // Add current product SKU to avoid creations of the related product with the same SKU $relSku[] = $model->getSku(); foreach ($value as $relProductSku) { if (!in_array($relProductSku, $relSku)) { // Create new relation $relProduct = \XLite\Core\Database::getRepo('XLite\\Model\\Product')->findOneBySku($relProductSku); if ($relProduct) { $up = new \XLite\Module\XC\Upselling\Model\UpsellingProduct(); $up->setProduct($relProduct); $up->setParentProduct($model); \XLite\Core\Database::getEM()->persist($up); } } } } }
/** * Generate SKU * * @param \XLite\Model\Product $product Product * * @return string */ public function generateSKU(\XLite\Model\Product $product) { $id = $product->getProductId(); if (11 > strlen((string) $id)) { $id = str_repeat('0', 11 - strlen((string) $id)) . $id; } $sku = (string) $id; $i = 0; $qb = $this->defineGenerateSKUQuery(); while ($i < static::SKU_GENERATION_LIMIT && 0 < intval($qb->setParameter('sku', $sku)->getSingleScalarResult())) { $i++; $sku = $id . '-' . $i; } if ($i >= static::SKU_GENERATION_LIMIT) { $sku = md5($sku . microtime(true)); } return $sku; }
/** * Get product URL * * @param \XLite\Model\Product $product Product object * @param integer $categoryId Category ID * * @return string */ protected function getProductURL(\XLite\Model\Product $product, $categoryId = null) { $params = array(); $params['product_id'] = $product->getProductId(); if ($categoryId) { $found = false; $firstId = null; $productCategories = $product->getCategories(); if ($productCategories && (1 < count($productCategories) || LC_USE_CLEAN_URLS && !(bool) \Includes\Utils\ConfigParser::getOptions(array('clean_urls', 'use_canonical_urls_only')))) { foreach ($productCategories as $category) { if (!isset($firstId)) { $firstId = $category->getCategoryId(); } if ($category->getCategoryId() == $categoryId) { $found = true; break; } } if (!$found) { $categoryId = $firstId; } } else { $categoryId = null; } if ($categoryId) { $params['category_id'] = $categoryId; } } return \XLite\Core\Converter::buildURL('product', '', $params); }
/** * Log import notice * * @param string $message Message * @param integer $position Row position OPTIONAL * @param string $column Column name OPTIONAL * @param string $value Cell value OPTIONAL * @param \XLite\Model\Product $product Product OPTIONAL * * @return void */ protected function logImportWarning($message, $position = null, $column = null, $value = null, \XLite\Model\Product $product = null) { $message = trim($message); $this->importCell['warning_count']++; if (isset($position)) { $message .= PHP_EOL . 'Row number: ' . ($position + 2); } if (isset($column)) { $message .= PHP_EOL . 'Column: ' . $column; } if (isset($value)) { $message .= PHP_EOL . 'Cell value: ' . var_export($value, true); } if (isset($product)) { if ($product->getProductId()) { $message .= PHP_EOL . 'Product id: ' . $product->getProductId(); } elseif ($product->getSku()) { $message .= PHP_EOL . 'Product SKU: ' . $product->getSku(); } } \XLite\Logger::getInstance()->logCustom('import', $message); }
/** * Get registered label for product * * @param \XLite\Model\Product $product Product object * * @return array */ public static function getLabel(\XLite\Model\Product $product) { return !empty(static::$labels[$product->getProductId()]) ? static::$labels[$product->getProductId()] : array(); }
/** * {@inheritDoc} */ public function getProductId() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getProductId', array()); return parent::getProductId(); }
/** * Assemble product data * * @param \XLite\Model\Product $product Product * * @return array */ protected function assembleProductData(\XLite\Model\Product $product) { return array('loc' => array('target' => 'product', 'product_id' => $product->getProductId()), 'lastmod' => \XLite\Core\Converter::time(), 'changefreq' => \XLite\Core\Config::getInstance()->CDev->XMLSitemap->product_changefreq, 'priority' => $this->processPriority(\XLite\Core\Config::getInstance()->CDev->XMLSitemap->product_priority)); }
/** * Define query builder for getMinQuantities() * * @param \XLite\Model\Product $product Product entity * @param \XLite\Model\Membership $membership Membership entity (or null) OPTIONAL * * @return \Doctrine\ORM\QueryBuilder */ protected function defineMinQuantitiesQuery($product, $membership = null) { $qb = $this->createQueryBuilder('m'); $qb->innerJoin('m.product', 'product')->andWhere('product.product_id = :productId')->setParameter('productId', $product->getProductId()); if (!is_null($membership)) { $qb->innerJoin('m.membership', 'membership')->andWhere('membership.membership_id = :membershipId')->addOrderBy('membership.membership_id')->setParameter('membershipId', $membership->getMembershipId()); } else { $qb->andWhere('m.membership is null'); } return $qb; }
/** * Return list of the CategoryProduct entities * * @param \XLite\Model\Product $product Current product * * @return array */ protected function getCategoryProducts(\XLite\Model\Product $product) { $data = array(); foreach ((array) $this->getPostedData('category_ids') as $categoryId) { $data[] = new \XLite\Model\CategoryProducts(array('product_id' => $product->getProductId(), 'category_id' => $categoryId, 'category' => \XLite\Core\Database::getRepo('\\XLite\\Model\\Category')->find($categoryId), 'product' => $product)); } return array('categoryProducts' => new \Doctrine\Common\Collections\ArrayCollection($data)); }
/** * Checks whether a product was added to the cart * * @param \XLite\Model\Product $product The product to look for * * @return boolean */ protected function isProductAdded(\XLite\Model\Product $product) { return $this->getCart()->isProductAdded($product->getProductId()); }