本文整理汇总了PHP中Provider::getProductData方法的典型用法代码示例。如果您正苦于以下问题:PHP Provider::getProductData方法的具体用法?PHP Provider::getProductData怎么用?PHP Provider::getProductData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Provider
的用法示例。
在下文中一共展示了Provider::getProductData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getProductsData
/**
* Get products data
*
* @return array
*/
public function getProductsData()
{
$productsData = [];
$provider = new Provider();
foreach ($this->_brands as $brandId => $brand) {
$categoryUrl = $provider->getCategoryUrl(self::STORE_URL, $brandId, self::ALL_CATEGORY_PRODUCTS);
if ($categoryUrl) {
$productUrls[$categoryUrl] = $provider->getProductUrls($this->_addStoreUrl($categoryUrl));
foreach ($productUrls[$categoryUrl] as $index => $productUrl) {
$productData = $provider->getProductData($this->_addStoreUrl($productUrl));
$productsData[$productUrl] = $this->_addBrandToProductData($productData, $brand);
}
}
}
return $productsData;
}
示例2: loadBundleChildElements
/**
* @return bool
*/
protected function loadBundleChildElements()
{
$bundleChildList = Provider::getSetItems($this);
if (empty($bundleChildList)) {
return null;
}
/** @var Basket $baseBasketCollection */
$baseBasketCollection = $this->getCollection();
/** @var Order $order */
$order = $baseBasketCollection->getOrder();
/** @var Basket $bundleCollection */
$bundleCollection = BasketBundleCollection::create($baseBasketCollection->getSiteId());
if ($order !== null) {
$bundleCollection->setOrder($order);
}
foreach ($bundleChildList as $bundleBasketListDat) {
foreach ($bundleBasketListDat["ITEMS"] as $bundleDat) {
$bundleFields = static::clearBundleItemFields($bundleDat);
$bundleFields['CURRENCY'] = $this->getCurrency();
if ($this->getId() > 0) {
$bundleFields['SET_PARENT_ID'] = $this->getId();
}
/** @var BasketItem $basketItem */
$bundleBasketItem = BasketItem::create($bundleCollection, $bundleFields['MODULE'], $bundleFields['PRODUCT_ID']);
if (!empty($bundleDat["PROPS"]) && is_array($bundleDat["PROPS"])) {
/** @var BasketPropertiesCollection $property */
$property = $bundleBasketItem->getPropertyCollection();
$property->setProperty($bundleDat["PROPS"]);
}
$bundleFields['QUANTITY'] = $bundleFields['QUANTITY'] * $this->getQuantity();
$bundleBasketItem->setFieldsNoDemand($bundleFields);
$bundleBasketItem->parentBasketItem = $this;
$bundleBasketItem->parentId = $this->getBasketCode();
$bundleCollection->addItem($bundleBasketItem);
}
}
if ($productList = Provider::getProductData($bundleCollection, array('QUANTITY', 'PRICE'))) {
foreach ($productList as $productBasketCode => $productDat) {
if ($bundleBasketItem = $bundleCollection->getItemByBasketCode($productBasketCode)) {
unset($productDat['DISCOUNT_LIST']);
$bundleBasketItem->setFieldsNoDemand($productDat);
}
}
}
$this->bundleCollection = $bundleCollection;
return $bundleCollection;
}
示例3: refreshData
/**
* @param array $select
* @param BasketItem $refreshItem
* @return Result
* @throws Main\ArgumentNullException
* @throws Main\NotSupportedException
* @throws Main\ObjectNotFoundException
*/
public function refreshData($select = array(), BasketItem $refreshItem = null)
{
$result = new Result();
$isStartField = $this->isStartField();
$discount = null;
/** @var Order $order */
if ($order = $this->getOrder()) {
$discount = $order->getDiscount();
}
$settableFields = array_fill_keys(BasketItem::getSettableFields(), true);
$data = Provider::getProductData($this, $select, $refreshItem);
foreach ($data as $key => $value) {
//$item = $this->getItemByBasketCode($key);
if (!($item = $this->getItemByBasketCode($key))) {
continue;
}
if (isset($value['DELETE']) && $value['DELETE']) {
$item->delete();
if ($discount !== null) {
$discount->clearBasketItemData($key);
}
continue;
}
$basePrice = false;
$currency = false;
$discountList = false;
$value1 = array();
$roundFields = static::getRoundFields();
foreach ($value as $k => $v) {
//TODO: create method for save data in discount
if ($k == 'BASE_PRICE') {
$basePrice = true;
}
if ($k == 'CURRENCY') {
$currency = true;
}
if ($k == 'DISCOUNT_LIST' && !empty($v)) {
$discountList = true;
}
//TODO END
if (isset($settableFields[$k])) {
if ($item) {
if ($k == "PRICE" && $item->isCustomPrice()) {
$v = $item->getPrice();
}
if (in_array($k, $roundFields)) {
$v = roundEx($v, SALE_VALUE_PRECISION);
}
}
$value1[$k] = $v;
}
}
if (!$item->isCustomPrice()) {
$value1['PRICE'] = $value1['BASE_PRICE'] - $value1['DISCOUNT_PRICE'];
}
if (!$item) {
$item = $this->createItem($value['MODULE_ID'], $value['PRODUCT_ID']);
}
if (!$item) {
continue;
}
if ($discount !== null) {
if ($basePrice && $currency) {
$discount->setBasketItemBasePrice($key, $value['BASE_PRICE'], $value['CURRENCY']);
}
if ($discountList) {
$discount->setBasketItemDiscounts($key, $value['DISCOUNT_LIST']);
}
}
/** @var Result $r */
$r = $item->setFields($value1);
if (!$r->isSuccess()) {
$result->addErrors($r->getErrors());
}
}
/** @var Order $order */
if ($order = $this->getOrder()) {
$r = $order->refreshData(array('PRICE', 'PRICE_DELIVERY'));
if (!$r->isSuccess()) {
$result->addErrors($r->getErrors());
}
}
if ($isStartField) {
$hasMeaningfulFields = $this->hasMeaningfulField();
/** @var Result $r */
$r = $this->doFinalAction($hasMeaningfulFields);
if (!$r->isSuccess()) {
$result->addErrors($r->getErrors());
}
}
return $result;
}
示例4: refreshData
/**
* @param array $select
* @param BasketItem $refreshItem
* @return Result
* @throws Main\ArgumentNullException
* @throws Main\NotSupportedException
* @throws Main\ObjectNotFoundException
*/
public function refreshData($select = array(), BasketItem $refreshItem = null)
{
$result = new Result();
$isStartField = $this->isStartField();
$discount = null;
/** @var Order $order */
if ($order = $this->getOrder()) {
$discount = $order->getDiscount();
}
$settableFields = array_fill_keys(BasketItem::getSettableFields(), true);
$data = Provider::getProductData($this, $select, $refreshItem);
foreach ($data as $key => $value) {
/** @var null|BasketItem $item */
$item = null;
//$item = $this->getItemByBasketCode($key);
// if(!($item = $this->getItemByBasketCode($key)))
// {
// continue;
// }
$item = $this->getItemByBasketCode($key);
if (isset($value['DELETE']) && $value['DELETE']) {
if ($item) {
$item->delete();
if ($discount !== null) {
$discount->clearBasketItemData($key);
}
}
continue;
}
$value1 = array();
$roundFields = static::getRoundFields();
foreach ($value as $k => $v) {
if (isset($settableFields[$k])) {
if ($item) {
if ($k == "PRICE" && $item->isCustomPrice()) {
$v = $item->getPrice();
}
if (in_array($k, $roundFields)) {
$v = PriceMaths::roundPrecision($v);
}
}
$value1[$k] = $v;
}
}
if (!$item) {
$item = $this->createItem($value['MODULE_ID'], $value['PRODUCT_ID']);
}
if (!$item) {
continue;
}
if (!$item->isCustomPrice() && array_key_exists('DISCOUNT_PRICE', $value1) && array_key_exists('BASE_PRICE', $value1)) {
$value1['PRICE'] = $value1['BASE_PRICE'] - $value1['DISCOUNT_PRICE'];
}
if ($discount instanceof Discount) {
$discount->setBasketItemData($key, $value);
}
$isBundleParent = (bool) ($item && $item->isBundleParent());
/** @var Result $r */
$r = $item->setFields($value1);
if (!$r->isSuccess()) {
$result->addErrors($r->getErrors());
}
if (($isBundleParent || $item->isBundleParent()) && array_key_exists('BUNDLE_ITEMS', $value)) {
/** @var BasketBundleCollection $bundleCollection */
if ($bundleCollection = $item->getBundleCollection()) {
$bundleIndexList = array();
/** @var BasketItem $bundleBasketItem */
foreach ($bundleCollection as $bundleBasketItem) {
$bundleIndexList[$bundleBasketItem->getBasketCode()] = true;
}
/** @var array $bundleBasketItemData */
foreach ($value['BUNDLE_ITEMS'] as $bundleBasketItemData) {
if (empty($bundleBasketItemData['MODULE']) || empty($bundleBasketItemData['PRODUCT_ID'])) {
continue;
}
/** @var BasketItem $bundleBasketItem */
if ($bundleBasketItem = $bundleCollection->getExistsItem($bundleBasketItemData['MODULE'], $bundleBasketItemData['PRODUCT_ID'], !empty($bundleBasketItemData['PROPS']) && is_array($bundleBasketItemData['PROPS']) ? $bundleBasketItemData['PROPS'] : array())) {
if (isset($bundleIndexList[$bundleBasketItem->getBasketCode()])) {
unset($bundleIndexList[$bundleBasketItem->getBasketCode()]);
}
} else {
/** @var BasketItem $bundleBasketItem */
$bundleBasketItem = BasketItem::create($bundleCollection, $bundleBasketItemData['MODULE'], $bundleBasketItemData['PRODUCT_ID']);
}
if (!$bundleBasketItem) {
continue;
}
$fields = array_intersect_key($bundleBasketItemData, $settableFields);
$r = $bundleBasketItem->setFields($fields);
if (!$r->isSuccess()) {
$result->addErrors($r->getErrors());
}
//.........这里部分代码省略.........