Questions tagged «programmatically»

1
如何以编程方式向表添加外键?
我试图添加一组新表,并且试图添加外键来链接这些表。我在网上寻找addForeignKey()可以找到有关的信息,但找不到任何东西。 看着Varien_Db_Adapter_Interface::addForeignKey()和Mage_Core_Model_Resource_Setup::getFkName()我想下面的设置我已经得到了正确 ->addForeignKey( $installer->getFkName('namespace_module/shop', 'area_id', 'namespace_module/area','area_id'), $installer->getTable('namespace_module/shop'), 'area_id', $installer->getTable('namespace_module/area'), 'area_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE ) 但是例外说不一样 Zend_Db_Exception Object ( [_previous:Zend_Exception:private] => [message:protected] => Undefined column "shop_locator_shop" [string:Exception:private] => [code:protected] => 0 [file:protected] => /Users/myname/Sites/site/www/lib/Varien/Db/Ddl/Table.php [line:protected] => 450 [trace:Exception:private] => Array ( [0] => Array ( [file] => /Users/myname/Sites/site/www/app/code/local/Namespace/Module/sql/namespace_module_setup/install-0.1.0.php [line] => 110 [function] …


4
以编程方式将具有不同属性的多个项目添加到购物车
我正在批量添加购物车系统。请注意:我希望它适用于具有自定义选项的简单产品->自定义选项如颜色(红色,绿色,蓝色)或尺寸(XL,M,S) 假设某人要订购以下物品: productA,red颜色qty12 ProductA,green颜色qty18 ProductB XL,数量3 Product C,数量10 因此,我想一次通过代码/以编程方式添加这4个项目。我怎样才能做到这一点?是否可以通过查询字符串或任何控制器或内置函数来实现?不必每次都看到一个查询或一个函数调用...

3
如何在Magento 2中以编程方式添加CMS块?
我需要通过安装/升级脚本添加CMS块。我已经弄清楚了如何添加“普通” CMS页面,如下面的脚本所示。但是,由于我找不到在Magento 2的代码中添加CMS块的任何方法,因此无论是在Google还是在这里,我都很困惑。 namespace [Vendor]\[Module]\Setup; use Magento\Cms\Model\Page; use Magento\Cms\Model\PageFactory; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface; use Magento\Framework\Setup\UpgradeDataInterface; class UpgradeData implements UpgradeDataInterface { /** * Page factory. * * @var PageFactory */ private $pageFactory; /** * Init. * * @param PageFactory $pageFactory */ public function __construct(PageFactory $pageFactory) { $this->pageFactory = $pageFactory; } /** …

10
Magento 2:以编程方式更新库存
在以下代码中,我能够存储所有信息,但不包括库存数据。Magento 2有什么变化吗? public function __construct( ScopeConfigInterface $scopeConfig, CollectionFactory $product, Magento\Catalog\Api\ProductRepositoryInterface $productRepository ) { $this->scopeConfig = $scopeConfig; $this->product = $product; $this->productRepository = $productRepository; } public function update(\XXXXXX\XXXXXX\Api\Data\InventoryCollectionInterface $data) { foreach ($data['list'] as $d) { $product = $this->productRepository->getById($d['entity_id']); $product->setStatus(($d['quantity'] > 0 ? 1 : 0)); $product->setUpc($d['upc']); $product->setStockData(array( 'qty' => $d['quantity'], 'is_in_stock' => …

2
Magento使用Paypal付款方式以编程方式创建订单
目前,我们有两个magento独立网站。一种表现为店面,另一种表现为后端。用户可以在前端下订单。 因此,我尝试在后端以编程方式创建相同的顺序。当用户通过checkmo付款方式付款时,它可以工作。但是,当用户通过PayPal付款时,它将无法正常工作。因此,有人知道我们如何使用PayPal付款方式以编程方式创建订单吗?有没有可能? $quote->getPayment()->importData(array(3) { [method] => paypal_express [last_trans_id] => 65Y31421KL2753028 [additional_information] => Array ( [paypal_express_checkout_shipping_method] => [paypal_payer_id] => 5LX84SUFY39L4 [paypal_payer_email] => abbas-buyer-2@bluewisesoft.com [paypal_payer_status] => verified [paypal_address_status] => Confirmed [paypal_correlation_id] => b78b4e5e6e527 [paypal_express_checkout_payer_id] => 5LX84SUFY39L4 [paypal_express_checkout_token] => EC-7P402752023166448 [paypal_express_checkout_redirect_required] => [paypal_protection_eligibility] => Eligible [paypal_payment_status] => pending [paypal_pending_reason] => authorization ) }); …

4
在Magento 2.0中以编程方式创建管理员用户
在Magento 1.9中添加新的管理员用户很简单 <?php require_once('app/Mage.php'); umask(0); Mage::app(); $user = Mage::getModel('admin/user') ->setData(array( 'username' => 'admin', 'firstname' => 'admin', 'lastname' => 'admin', 'email' => 'me@hackme.com', 'password' => 'hacker@123', 'is_active' => 1 )) ->save(); $user->setRoleIds(array(1)) ->setRoleUserId($user->getUserId()) ->saveRelations(); echo "User has been created successfully!"; ?> 但是如何在Magento 2.0中添加管理员用户?

2
Magento2-如何在触发checkout_cart_product_add_after后以编程方式将产品添加到购物车
考虑有两种产品,即:产品A和产品B。产品B是一种虚拟产品,当将产品A添加到购物车时,我需要将其添加到购物车中。 为此,我正在尝试通过观察事件将产品B添加到购物车checkout_cart_product_add_after。添加产品A后,我将检索为产品A添加的产品数量,并基于此我尝试以编程方式添加产品B。要添加产品B,我编写了以下代码: <?php namespace MyModule\Applicationcharges\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\App\RequestInterface; class AddCharges implements ObserverInterface { protected $_productRepository; protected $_cart; public function __construct(\Magento\Catalog\Model\ProductRepository $productRepository, \Magento\Checkout\Model\Cart $cart){ $this->_productRepository = $productRepository; $this->_cart = $cart; } public function execute(\Magento\Framework\Event\Observer $observer) { $item=$observer->getEvent()->getData('quote_item'); $product=$observer->getEvent()->getData('product'); $item = ( $item->getParentItem() ? $item->getParentItem() : $item ); $product->getQty(); $params = …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.